码迷,mamicode.com
首页 > 其他好文 > 详细

SMS106 短信验证码接口测试

时间:2017-06-08 10:59:22      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:上下   cgi   sha1   发送   pps   企业   append   code   eth   

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

 

三.注意事项:

参数一些公司为了安全会吧一些关键的参数放入header中;

首先必须登录其官网注册,来获得自己需要的参数;

仅供参考,请勿拷贝粘贴,多动手,你的技术就会提升一大截。(拷贝你也用不了,某些隐秘参数我会乱输的,安全第一)

SMS106 短信验证码接口测试

标签:上下   cgi   sha1   发送   pps   企业   append   code   eth   

原文地址:http://www.cnblogs.com/zlp520/p/6960902.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!