栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C# > C#教程

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

C#教程 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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

#region 获取手机验证码(创蓝253)
  /// 
  /// 获取手机验证码(创蓝253)
  /// 
  /// 手机号
  /// 
  [AllowAnonymous]
  public async Task 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)手机短信验证码接口的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/123066.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号