1. 程式人生 > >SMS106 短信驗證碼接口測試

SMS106 短信驗證碼接口測試

req demo hid url 檢查 create XML napi bre

SMS106 短信驗證碼接口測試

一.什麽是SMS106:

106短信通道是指僅中國移動、中國聯通提供的網關短信平臺,實現與客戶指定號碼進行短信批量發送和自定義發送的目的,即你收到的短信在手機上以106開頭的短信稱為106短信。 短信通道的分類國內短信通道主要分為:106通道、電信虛擬短信通道:電話區號(類似021)的、1069三網合一企業實名制通,106通道一般顯示為:106通道(10657移動,聯通10655,電信10659)。全網移動企業短信通通道10657,聯通10655,電信10659全部能夠實現上下行,全國支持,適合通知祝福類的短信,限制房地產、發票、私募基金和SP等客戶信息。

二.Demo:

1.接口網:

技術分享
 1 private static string SendForJieKouWang(string phone)
 2         {
 3 
 4              //支持htpp get,post請求,如返回104錯誤,檢查驗證碼內容是否系統提供的模板。
 5             //sms.106jiekou.com/utf8/sms.aspx?account=9999&password=接口密碼&mobile=13900008888&content=您的驗證碼是:7409。請不要把驗證碼泄露給其他人。如非本人操作,可不用理會!。
 6             string
url = "http://sms.106jiekou.com/utf8/sms.aspx"; 7 8 string account = "9999"; 9 string password = "111"; 10 int num = BuildCode(); 11 string content = "您的驗證碼是:" + num + "。請不要把驗證碼泄露給其他人。如非本人操作,可不用理會!"; 12 13 StringBuilder sb = new StringBuilder();
14 sb.Append(url); 15 sb.Append("?account=" + account); 16 sb.Append("&password=" + password); 17 sb.Append("&mobile=" + phone); 18 sb.Append("&content=" + content); 19 20 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sb.ToString()); 21 request.Method = "GET"; 22 request.Timeout = 5000; 23 24 HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 25 StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8); 26 string result = sr.ReadToEnd(); 27 sr.Close(); 28 code = num; 29 return result; 30 //直接返回狀態碼:成功是100 31 }
View Code

2.網易雲通信:

技術分享
 1  private static string SendForWangYiYun(string phone)
 2         {
 3 
 4             string url = "https://api.netease.im/sms/sendcode.action";
 5             string mobile = "mobile=" + phone;
 6             byte[] byteArr = Encoding.UTF8.GetBytes(mobile.ToString());
 7 
 8             HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
 9             request.Method = "POST";
10             request.ContentType = "application/x-www-form-urlencoded";
11             request.ContentLength = byteArr.Length;
12             request.Timeout = 5000;
13 
14             string appKey = "43c75a269800f3fa008812481db1b031";
15             string appSecret = "9c74d37ab7f1";
16             string nonce = "4tgggergigwow323t231";
17             string curTime = GetCurTime();
18             string checkSum = HashCodeForSHA1(appSecret + nonce + curTime);
19 
20             request.Headers.Add("AppKey", appKey);
21             request.Headers.Add("Nonce", "4tgggergigwow323t23t");
22             request.Headers.Add("CurTime", curTime);
23             request.Headers.Add("CheckSum", checkSum);
24 
25             Stream requestStream = request.GetRequestStream();
26             requestStream.Write(byteArr, 0, byteArr.Length);
27             requestStream.Close();
28 
29             HttpWebResponse response = (HttpWebResponse)request.GetResponse();
30             StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
31             string result = sr.ReadToEnd();
32             sr.Close();
33             response.Close();
34             SMSResult smsResult = JsonConvert.DeserializeObject<SMSResult>(result);
35             code = Convert.ToInt32(smsResult.Obj);
36             return result;
37 
38             //{ "code":200,"msg":"1","obj":"5996"}
39         }
View Code

3.上海創明:

技術分享
 1  private static string SendForDuanxinWang(string phone)
 2         {
 3         
 4             string sendurl = "http://101.37.79.158/OpenPlatform/OpenApi";
 5             string action = "sendOnce";
 6             string ac = "[email protected]";            //用戶名
 7             string authkey = "1E37CA014926157DDC29A59ECA9FBD81";    //密鑰
 8             string cgid = "1";  //通道組編號
 9             string csid = "1";  //簽名編號 ,可以為空時,使用系統默認的編號
10             int num = BuildCode();
11             string c = "【創明短信】驗證碼:" + num + ", [驗證碼告知他人將導致帳號被盜,請勿泄露]";  // 短信的內容,不能為空
12 
13             StringBuilder sb = new StringBuilder();
14             sb.Append("action=" + action);
15             sb.Append("&ac=" + ac);
16             sb.Append("&authkey=" + authkey);
17             sb.Append("&cgid=" + cgid);
18             sb.Append("&csid=" + csid);
19             sb.Append("&m=" + phone);
20             sb.Append("&c=" + c);
21 
22             byte[] byteArr = Encoding.GetEncoding("utf-8").GetBytes(sb.ToString());
23 
24             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sendurl);
25             request.Method = "POST";
26             request.Timeout = 5000;
27             request.ContentType = "application/x-www-form-urlencoded";
28             request.ContentLength = byteArr.Length;
29 
30             Stream requestStream = request.GetRequestStream();
31             requestStream.Write(byteArr, 0, byteArr.Length);
32             requestStream.Close();
33 
34             HttpWebResponse response = (HttpWebResponse)request.GetResponse();
35             StreamReader responseStream = new StreamReader(response.GetResponseStream(), Encoding.ASCII);
36             string result = responseStream.ReadToEnd();
37             responseStream.Close();
38             response.Close();
39             code = num;
40             return result;
41 
42             //返回xml
43             //<? xml version = "1.0" ?>
44             //    < xml result = "1" name = "sendOnce" >
45             //        < Item remain = "0.100" price = "0.1" total = "1" msgid = "8450826309420610" sid = "1001" cid = "901012750001" />
46             //    </ xml >
47         }
View Code

三.註意事項:

參數一些公司為了安全會吧一些關鍵的參數放入header中;

首先必須登錄其官網註冊,來獲得自己需要的參數;

僅供參考,請勿拷貝粘貼,多動手,你的技術就會提升一大截。(拷貝你也用不了,某些隱秘參數我會亂輸的,安全第一)

SMS106 短信驗證碼接口測試