短信接口的使用

以前老感觉短信接口特别难,但实际做过一个后,感觉也没啥,以前主要是没接触过,没有思路罢了,开发前要有一个短信接口,或者说是短信接口开发文档

 1   public string HttpGet(string postDataStr = "")
 2         {
 3             string MobilePhone = Request["MobilePhone"];
 4             string yan = Request["yan"];
 5             if (MobilePhone != "手机号" && MobilePhone != "")
 6             {
 7                 //随机数
 8                 System.Random Random = new System.Random();
 9                 int Result = Random.Next(0, 9999);
10                 Session["yan"] = Result;
11                 string Url = "在这里输入你的接口";
12                 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr);
13                 request.Method = "GET";
14                 request.ContentType = "text/html;charset=UTF-8";
15 
16                 HttpWebResponse response = (HttpWebResponse)request.GetResponse();
17                 Stream myResponseStream = response.GetResponseStream();
18                 StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
19                 string retString = myStreamReader.ReadToEnd();
20                 myStreamReader.Close();
21                 myResponseStream.Close();
22 
23                 return retString;
24             }
25             else
26             {
27                 return "1";
28             }
29         }

页面中用ajax做的

 <div id="layout">
      
        <img src="~/Content/UI/images/logo_03.png" style="margin-left:27%;margin-top:23%;width:170px;height:60px" />
            <ul>
                <p id="err_msg"></p>
                <li><input class="username" maxlength="11" required id="inp" type="tel" name="MobilePhone" value="手机号" ></li>
                <li><input class="yzm" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" id="txtpwd" maxlength="4" value="验证码" onblur="yanval()" required type="text"><input  type="button" id="send" value="获取验证码" /></li>
                <li>
                    <button class="submit" type="submit" onclick="resign()">登陆</button>                 
                    <a href="/Home/Login"><div class="reg-login"><p>用户名登陆</p></div></a>
                </li>
            </ul>
    </div>

<script>
 $.ajax({
            type: "Get",
            url: '/Home/HttpGet',
            data: {
                MobilePhone: $("#inp").val(),
                yan: $("#txtpwd").val()
            },
            async: false,

            success: function (data) {
                if (data == "fail") {
                    alert("发送失败");
                }
                else if (data == "1") {
                    alert("请输入手机号");
                    return false;

                }
                else {

                }
            }
        })
</script>

 

posted @ 2017-02-06 16:05  大黄人  阅读(261)  评论(0编辑  收藏  举报