C# 開發(fā)(創(chuàng)藍253)手機短信驗證碼接口的實例
更新時間:2018年01月05日 09:17:20 投稿:jingxian
下面小編就為大家分享一篇C# 開發(fā)(創(chuàng)藍253)手機短信驗證碼接口的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
創(chuàng)藍253: https://www.253.com/
#region 獲取手機驗證碼(創(chuàng)藍253)
/// <summary>
/// 獲取手機驗證碼(創(chuàng)藍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 = "短信發(fā)送成功!", data = new { code = r } } });
}
else {
return Ok(new { code = "400", res = new { msg = "短信發(fā)送失敗!" } });
}
}
#endregion
以上這篇C# 開發(fā)(創(chuàng)藍253)手機短信驗證碼接口的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
WPF程序?qū)⒖丶尸F(xiàn)的內(nèi)容保存成圖像
這篇文章介紹了WPF程序?qū)⒖丶尸F(xiàn)的內(nèi)容保存成圖像的方法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-06-06
C# 中的GroupBy的動態(tài)拼接問題及GroupBy<>用法介紹
這篇文章主要介紹了C# 中的GroupBy的動態(tài)拼接問題,在文章給大家提到了C# List泛型集合中的GroupBy<>用法詳解,需要的朋友可以參考下2017-12-12
c#創(chuàng)建windows服務(wù)(Windows Services)詳細步驟
這篇文章主要介紹了c#創(chuàng)建windows服務(wù)(Windows Services)詳細步驟,大家參考使用吧2013-12-12

