SMS106 短信驗證碼接口測試


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 = "1001@101012750001";            //用戶名
 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

 4.雲通訊:

 1  private static string SendForYunTongXun(string phone)
 2         {
 3 
 4    
 5 
 6             //注冊不能免費試用,可以通過聯系客服可以提供測試賬號及密碼,要求參數json格式
 7             string url = "http://vsms.253.com/msg/send/json";
 8             string account = "N3723588";
 9             string password = "qdzCbTt5lEf411";
10             int num = BuildCode();
11             string msg = "【253雲通訊】您的驗證碼是:" + num + "";
12 
13             //可選項
14             string sendtime = "";
15             string extend = "";
16             string uid = "";
17             //string json = "{ \"account\":\"N3723588\",\"password\":\"qdzCbTt5lEf411\",\"msg\":\"254786\",,\"phone\":\"13520073575\"}";
18             Param p = new Param();
19             p.account = account;
20             p.password = password;
21             p.msg = msg;
22             p.phone = phone;
23             string json=JsonConvert.SerializeObject(p);
24 
25             byte[] dataArr = Encoding.UTF8.GetBytes(json);
26 
27             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
28             request.Method = "POST";
29             request.ContentType = "application/json";
30             request.ContentLength = dataArr.Length;
31             request.Timeout = 5000;
32 
33             Stream requestStream = request.GetRequestStream();
34             requestStream.Write(dataArr, 0, dataArr.Length);
35             requestStream.Close();
36 
37             HttpWebResponse response = (HttpWebResponse)request.GetResponse();
38             StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
39             string result = sr.ReadToEnd();
40             sr.Close();
41             response.Close();
42             code = num;
43             return result;
44             //"{\"time\":\"20170608113306\",\"msgId\":\"\",\"errorMsg\":\"無此用戶\",\"code\":\"101\"}"  error
45             //"{\"time\":\"20170608113520\",\"msgId\":\"17060811352028802\",\"errorMsg\":\"\",\"code\":\"0\"}"  ok
46         }
View Code

三.注意事項:

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

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

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM