C# 開發(fā)(創(chuàng)藍(lán)253)手機(jī)短信驗證碼接口的實例
更新時間:2018年01月05日 09:17:20 投稿:jingxian
下面小編就為大家分享一篇C# 開發(fā)(創(chuàng)藍(lán)253)手機(jī)短信驗證碼接口的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
創(chuàng)藍(lán)253: https://www.253.com/
#region 獲取手機(jī)驗證碼(創(chuàng)藍(lán)253)
/// <summary>
/// 獲取手機(jī)驗證碼(創(chuàng)藍(lán)253)
/// </summary>
/// <param name="phoneno">手機(jī)號</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)藍(lán)253)手機(jī)短信驗證碼接口的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
C#實現(xiàn)按照指定長度在數(shù)字前補0方法小結(jié)
這篇文章主要介紹了C#實現(xiàn)按照指定長度在數(shù)字前補0方法,實例總結(jié)了兩個常用的數(shù)字補0的技巧,非常具有實用價值,需要的朋友可以參考下2015-04-04
如何利用C#正則表達(dá)式判斷是否是有效的文件及文件夾路徑
項目中少不了讀取或設(shè)置文件路徑的功能,如何才能對輸入的路徑是否合法進(jìn)行判斷呢?下面這篇文章主要給大家介紹了關(guān)于C#利用正則表達(dá)式判斷是否是有效的文件及文件夾路徑的相關(guān)資料,需要的朋友可以參考下2022-04-04
DevExpress實現(xiàn)GridView當(dāng)無數(shù)據(jù)行時提示消息
這篇文章主要介紹了DevExpress實現(xiàn)GridView當(dāng)無數(shù)據(jù)行時提示消息,需要的朋友可以參考下2014-08-08

