当前位置: 移动技术网 > IT编程>开发语言>c# > C# 开发(创蓝253)手机短信验证码接口的实例

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

2019年07月18日  | 移动技术网IT编程  | 我要评论

创蓝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)手机短信验证码接口的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网