日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

.NET短信接口验证

發(fā)布時(shí)間:2023/12/10 asp.net 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 .NET短信接口验证 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

.NET短信接口驗(yàn)證

之前遇到的一個(gè)問題,因?yàn)闆]有接觸過,所以自己上網(wǎng)查閱過資料也向他人請教以及老師,.NET短信接口調(diào)用,其實(shí),網(wǎng)上有許多免費(fèi)的短信接口平臺(tái),但也是有限度的,如果發(fā)送的數(shù)量過多,我們也可以購買,我這里數(shù)量不多,只需要用免費(fèi)的就可以了,首先,我們必須要注冊一個(gè)賬戶,獲得使用的權(quán)限,在這里,我用的是互億無線短信平臺(tái),也可以根據(jù)個(gè)人需要選擇。
我們需要把樣式寫好:

<div class="col-lg-2 col-md-2 col-sm-2 text-right"><span class="control-label">手機(jī)號碼</span> </div> <div class="col-lg-4 col-md-4 col-sm-4 reset"><div class="col-sm-6" style="margin-left:-15px;"><input type="text"style="width:180px; height:34px;" class="form-control" id="Cellphone" name="Cellphone" onblur="fff()"/></div><div class="col-sm-6" style="margin-left:62px;width:95px!important"><input type="text" class="form-control" style="width:80px; height:34px"/></div> </div><div class="col-lg-1" style="margin-left:-31px;"><button class="btn btn-success" type="button" id="zphone" onClick="mobile();">獲取驗(yàn)證碼</button> </div>

我們要檢查我們在Web.config中有沒有給到鏈接:

如果沒有,我們需要在控制器中給到鏈接:

這里我們可以自主選擇方法。
接下來我們需要在控制器里面寫方法:

public ActionResult dx(string mobile){string account = "用戶名/";//用戶名是登錄用戶中心->驗(yàn)證碼、通知短信->帳戶及簽名設(shè)置->APIIDstring password = "密碼"; //密碼是請登錄用戶中心->驗(yàn)證碼、通知短信->帳戶及簽名設(shè)置->APIKEYmobile = "手機(jī)號碼";Random rad = new Random();int mobile_code = rad.Next(1000, 10000);string content = "您的驗(yàn)證碼是:" + mobile_code + " 。請不要把驗(yàn)證碼泄露給其他人。";Session["mobile"] = mobile;//Session["mobile_code"] = mobile_code;//string postStrTpl = "account={0}&password={1}&mobile={2}&content={3}";UTF8Encoding encoding = new UTF8Encoding();byte[] postData = encoding.GetBytes(string.Format(postStrTpl, account, password, mobile, content));HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(PostUrl);myRequest.Method = "POST";myRequest.ContentType = "application/x-www-form-urlencoded";myRequest.ContentLength = postData.Length;Stream newStream = myRequest.GetRequestStream();// Send the data.newStream.Write(postData, 0, postData.Length);newStream.Flush();newStream.Close();HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();if (myResponse.StatusCode == HttpStatusCode.OK){StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);//Response.Write(reader.ReadToEnd());string res = reader.ReadToEnd();int len1 = res.IndexOf("</code>");int len2 = res.IndexOf("<code>");string code = res.Substring((len2 + 6), (len1 - len2 - 6));//Response.Write(code);int len3 = res.IndexOf("</msg>");int len4 = res.IndexOf("<msg>");string msg = res.Substring((len4 + 5), (len3 - len4 - 5));Response.Write(msg);Response.End();return Json(msg, JsonRequestBehavior.AllowGet);}else{//訪問失敗return Json("", JsonRequestBehavior.AllowGet);}}

在寫完控制器之后,我們要寫一個(gè)方法來調(diào)用,提交發(fā)送短信驗(yàn)證:

<script language="javascript">function mobile() {var Cellphone = $('#Cellphone').val();$.post("/Aiyumye/BasicInformation/dx", { Cellphone: Cellphone }, function (msg) {if (msg == '提交成功') {RemainTime();}});};var iTime = 59;var Account;function RemainTime(){document.getElementById('zphone').disabled = true;var iSecond,sSecond="",sTime="";if (iTime >= 0){iSecond = parseInt(iTime%60);iMinute = parseInt(iTime/60)if (iSecond >= 0){if(iMinute>0){sSecond = iMinute + "分" + iSecond + "秒";}else{sSecond = iSecond + "秒";}}sTime=sSecond;if(iTime==0){clearTimeout(Account);sTime='獲取手機(jī)驗(yàn)證碼';iTime = 59;document.getElementById('zphone').disabled = false;}else{Account = setTimeout("RemainTime()",1000);iTime=iTime-1;}}else{sTime='沒有倒計(jì)時(shí)';}document.getElementById('zphone').value = sTime;}</script>

在這個(gè)過程中,必須引用這個(gè)插件,不然是沒有效果的:

操作代碼就以上的這些,我們實(shí)現(xiàn)的效果如下:

輸入手機(jī)號碼,獲取驗(yàn)證碼,實(shí)現(xiàn)短信驗(yàn)證。

總結(jié)

以上是生活随笔為你收集整理的.NET短信接口验证的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。