Web Form 发送短信

1.首先要找到合适的短信的接口。

2.确定给谁发短信和短信内容。

 1 /// <summary>
 2         /// 发短信
 3         /// </summary>
 4         /// <param name="tel">电话</param>
 5         
 6         private void SendMessageToRequestor(string tel)
 7         {
 8             string url = string.Empty;//短信接口路径
 9             string content = string.Empty;//短信内容,可增加变量来替换短信内容 比如:content = content.Replace("${ItCode}", itcode);//itcode
10            try
11             {
12                 url = url.Replace("${message}", HttpUtility.UrlEncode(content, Encoding.GetEncoding("GBK")));
13                 url = url.Replace("${mobile}", tel);//收短信人的电话号码
14                 this.HttpGet(url);
15             }
16             catch (Exception ex)
17             {
18 
19             }
20 }
21 
22 /// <summary>
23         ///  Get
24         /// </summary>
25         /// <param name="url"></param>
26         /// <param name="queryStr"></param>
27         /// <returns></returns>
28         public string HttpGet(string url)
29         {
30             HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
31             //myReq.ContentType = "application/x-www-form-urlencoded";
32             myReq.Method = "GET";
33             myReq.Headers.Add("Accept-Encoding", "utf-8");
34             HttpWebResponse HttpWResp;
35             try
36             {
37                 HttpWResp = (HttpWebResponse)myReq.GetResponse();
38             }
39             catch (WebException ex)
40             {
41                 HttpWResp = (HttpWebResponse)ex.Response;
42             }
43             Stream myStream = HttpWResp.GetResponseStream();
44             StreamReader reader = new StreamReader(myStream, Encoding.UTF8);
45             string content = reader.ReadToEnd();
46             reader.Close();
47             HttpWResp.Close();
48             return content;
49 
50         }

猜你喜欢

转载自www.cnblogs.com/cfss/p/Shortmessage.html
今日推荐