下面小编就为大家分享一篇C# 开发(创蓝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)手机短信验证码接口的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程学习网。
沃梦达教程
本文标题为:C# 开发(创蓝253)手机短信验证码接口的实例
猜你喜欢
- .NET CORE DI 依赖注入 2023-09-27
- C# 使用Aspose.Cells 导出Excel的步骤及问题记录 2023-05-16
- 在C# 8中如何使用默认接口方法详解 2023-03-29
- user32.dll 函数说明小结 2022-12-26
- c# 模拟线性回归的示例 2023-03-14
- Unity3D实现渐变颜色效果 2023-01-16
- 如何使用C# 捕获进程输出 2023-03-10
- Oracle中for循环的使用方法 2023-07-04
- WPF使用DrawingContext实现绘制刻度条 2023-07-04
- Unity Shader实现模糊效果 2023-04-27