欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-12-20 09:39:52
创蓝253: https://www.253.com/ #region 获取手机验证码(创蓝253) /// ///...

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

上一篇:

下一篇: