小编给大家分享一下C#如何开发手机短信验证码接口,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
我们提供的服务有:做网站、成都网站制作、微信公众号开发、网站优化、网站认证、鸡西ssl等。为上千多家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的鸡西网站制作公司
#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#如何开发手机短信验证码接口”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!