String Uid = "网建短信通用户名";
String key = "接口短信密钥";
String smsMob = "13800000000";
String smsText = "验证码:8888";
string url = "http://gbk.api.smschinese.cn/";
string post = string.Format("Uid={0}&key={1}&smsMob={2}&smsText={3}", Uid, key, smsMob, smsText);
Response.Write(PostData(url, post));
public static string PostData(string posturl, string postData)
{
//ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
Stream outstream = null;
Stream instream = null;
StreamReader sr = null;
HttpWebResponse response = null;
HttpWebRequest request = null;
Encoding encoding = Encoding.UTF8;
byte[] data = encoding.GetBytes(postData);
// 准备请求...
try
{
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
//ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
// 设置参数
//ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
request = WebRequest.Create(posturl) as HttpWebRequest;
CookieContainer cookieContainer = new CookieContainer();
request.CookieContainer = cookieContainer;
request.AllowAutoRedirect = true;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
outstream = request.GetRequestStream();
outstream.Write(data, 0, data.Length);
outstream.Close();
//发送请求并获取相应回应数据
response = request.GetResponse() as HttpWebResponse;
//直到request.GetResponse()程序才开始向目标网页发送Post请求
instream = response.GetResponseStream();
sr = new StreamReader(instream, encoding);
//返回结果网页(html)代码
string content = sr.ReadToEnd();
string err = string.Empty;
return content;
}
catch (Exception ex)
{
return ex.Message;
}
}
重要提示:用接口发送验证码的程序员注意,近期短信验证码轰炸软件泛滥,请在发送验证码的时候,加上一个图形校验码验证,防止机器人读取狂发验证码!!!不明事宜请联系客服咨询。发送手机验证码请做好以下几点防范:
参数变量 | 是否必填 | 说明 |
---|---|---|
Gbk编码Url | 是 | http://gbk.api.smschinese.cn/ |
Utf-8编码Url | 是 | http://utf8.api.smschinese.cn/ |
Https接口Url | 是 | https://utf8api.smschinese.cn/ |
Uid | 是 | 本站用户名(无本站用户名请先注册,不是手机号)[免费注册] |
Key | 是 | 接口短信密钥(可到平台修改接口秘钥)[立刻修改] 如需要加密参数,请把Key变量名改成KeyMD5, KeyMD5=接口秘钥32位MD5加密,大写。 |
smsMob | 是 | 目的手机号码(多个手机号请用半角逗号隔开) 如:13888888886,13888888887,1388888888 最多100个手机 |
smsText | 是 | 短信内容,最多支持500个字,普通短信70个字/条,长短信64个字/条计费 提示:HTTP调用URL接口时, 变量请先转URL编码后再提交 |
短信发送后返回值 | 说 明 |
---|---|
大于0 | 提交成功 短信发送数量 |
-1 | 没有该用户账户 |
-2 | 接口密钥不正确 [查看密钥] 不是账户登陆密码 |
-21 | MD5接口密钥加密不正确 |
-3 | 短信数量不足 |
-11 | 该用户被禁用 |
-14 | 短信内容出现非法字符 |
-4 | 手机号格式不正确 |
-41 | 手机号码为空 |
-42 | 短信内容为空 |
-51 | 短信签名格式不正确 接口签名格式为:【签名内容】 |
-52 | 短信签名太长 建议签名10个字符以内 |
-6 | IP限制 |
沪ICP备2021011364号-1 Copyright © 2006-2022 webchinese.cn Inc. All Rights Reserved 网建 版权所有 |