欢迎来到入门教程网!

C#教程

当前位置:主页 > 软件编程 > C#教程 >

C# 开发(创蓝253)手机短信验证码接口的实例

来源:本站原创|时间:2020-01-10|栏目:C#教程|点击:

创蓝253: https://www.253.com/

#region 获取手机验证码(创蓝253)
  /// <summary>
  /// 获取手机验证码(创蓝253)
  /// </summary>
  /// <param name="phoneno">手机号</param>
  /// <returns></returns>
  [AllowAnonymous]
  public async Task<IHttpActionResult> GetPhoneCode(string phoneno)
  {
   string account = "******", password = "******", mobile = phoneno;
   Random rd = new Random(); int r = rd.Next(100000, 999999);
   string content = "【您的签名】"+"尊敬的客户:您的验证码为" + r + "!";
   string postStrTpl = "un={0}&pw={1}&phone={2}&msg={3}&rd=1";
   UTF8Encoding encoding = new UTF8Encoding();
   byte[] postData = encoding.GetBytes(string.Format(postStrTpl, account, password, mobile, content));
   HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://sms.253.com/msg/send");
   myRequest.Method = "POST";
   myRequest.ContentType = "application/x-www-form-urlencoded";
   myRequest.ContentLength = postData.Length;
   Stream newStream = myRequest.GetRequestStream();
   newStream.Write(postData, 0, postData.Length);
   newStream.Flush();
   newStream.Close();
   HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
   if (myResponse.StatusCode == HttpStatusCode.OK)
   {
    return Ok(new { code = "200", res = new { msg = "短信发送成功!", data = new { code = r } } });
   }
   else {
    return Ok(new { code = "400", res = new { msg = "短信发送失败!" } });
   }
  }
  #endregion

以上这篇C# 开发(创蓝253)手机短信验证码接口的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

上一篇:C#抓取网络图片保存到本地的实现方法

栏    目:C#教程

下一篇:C#创建Excel多级分组的方法

本文标题:C# 开发(创蓝253)手机短信验证码接口的实例

本文地址:https://www.xiuzhanwang.com/a1/C_jiaocheng/5301.html

网页制作CMS教程网络编程软件编程脚本语言数据库服务器

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:835971066 | 邮箱:835971066#qq.com(#换成@)

Copyright © 2002-2020 脚本教程网 版权所有