SMS106 短信验证码接口测试
SMS106 短信验证码接口测试
一.什么是SMS106:
106短信通道是指仅中国移动、中国联通提供的网关短信平台,实现与客户指定号码进行短信批量发送和自定义发送的目的,即你收到的短信在手机上以106开头的短信称为106短信。 短信通道的分类国内短信通道主要分为:106通道、电信虚拟短信通道:电话区号(类似021)的、1069三网合一企业实名制通,106通道一般显示为:106通道(10657移动,联通10655,电信10659)。全网移动企业短信通通道10657,联通10655,电信10659全部能够实现上下行,全国支持,适合通知祝福类的短信,限制房地产、发票、私募基金和SP等客户信息。
二.Demo:
1.接口网:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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 }
2.网易云通信:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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 }
3.上海创明:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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 }
4.云通讯:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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 }
三.注意事项:
参数一些公司为了安全会吧一些关键的参数放入header中;
首先必须登录其官网注册,来获得自己需要的参数;
仅供参考,请勿拷贝粘贴,多动手,你的技术就会提升一大截。(拷贝你也用不了,某些隐秘参数我会乱输的,安全第一)
为了明天能幸福,今天付出再多也不后悔。