.net 實現之簡訊驗證碼

來源:互聯網
上載者:User

標籤:ice   config   bre   false   cond   settings   代碼   code   word   

介面類型:互億無線觸發簡訊介面,支援發送驗證碼簡訊、訂單通知簡訊等。

賬戶註冊:請通過該地址開通賬戶http://sms.ihuyi.com/register.html

只能測試用:

  實現註冊頁面

     

<script type="text/javascript">    function get_mobile_code() {        $.get(‘Post.aspx‘, { mobile: jQuery.trim($(‘#mobile‘).val()) }, function (msg) {            alert(jQuery.trim(unescape(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 = ‘擷取手機驗證碼‘;                iTime = 59;                document.getElementById(‘zphone‘).disabled = false;            } else {                Account = setTimeout("RemainTime()", 1000);                iTime = iTime - 1;            }        } else {            sTime = ‘沒有倒計時‘;        }        document.getElementById(‘zphone‘).value = sTime;    }</script>

  

<form action="" method="post" name="formUser" onSubmit="return register();">    <table width="100%" border="0" align="left" cellpadding="5" cellspacing="3">        <tr>        <td align="right">手機<td>        <input id="mobile" name="extend_field5" type="text" size="25" class="inputBg" /><span style="color:#FF0000"> *</span>         <input id="zphone" type="button" value=" 發送手機驗證碼 " onClick="get_mobile_code();"></td>        </tr>        <tr>            <td align="right">驗證碼</td>            <td><input type="text" size="8" name="captcha" class="inputBg" /></td>        </tr>    </table></form>

後台代碼

 

 public static string PostUrl = ConfigurationManager.AppSettings["WebReference.Service.PostUrl"];        protected void Page_Load(object sender, EventArgs e)        {            string account = "C23795760";//使用者名稱是登入使用者中心->驗證碼、通知簡訊->帳戶及簽章設定->APIID            string password = "b79bc3ff3985ea849964fb7a5fdf78ea"; //密碼是請登入使用者中心->驗證碼、通知簡訊->帳戶及簽章設定->APIKEY            string mobile = Request.QueryString["mobile"];            Random rad = new Random();            int mobile_code = rad.Next(1000, 10000);            string content = "我就是來測試的別害怕zmd:" + mobile_code + " 。請不要把驗證碼泄露給其他人。";            //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();            }            else            {                //訪問失敗            }        }

web.confg

 <appSettings>    <add key="WebReference.Service.PostUrl" value="http://106.ihuyi.cn/webservice/sms.php?method=Submit"/>    <add key="WebReference.sms" value="http://106.ihuyi.cn/webservice/sms.php?smsService"/>  </appSettings>

 

     

.net 實現之簡訊驗證碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.