String Uid = "網(wǎng)建短信通用戶名";
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);
// 準(zhǔn)備請求...
try
{
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
//ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
// 設(shè)置參數(shù)
//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();
//發(fā)送請求并獲取相應(yīng)回應(yīng)數(shù)據(jù)
response = request.GetResponse() as HttpWebResponse;
//直到request.GetResponse()程序才開始向目標(biāo)網(wǎng)頁發(fā)送Post請求
instream = response.GetResponseStream();
sr = new StreamReader(instream, encoding);
//返回結(jié)果網(wǎng)頁(html)代碼
string content = sr.ReadToEnd();
string err = string.Empty;
return content;
}
catch (Exception ex)
{
return ex.Message;
}
}
重要提示:用接口發(fā)送驗證碼的程序員注意,近期短信驗證碼轟炸軟件泛濫,請在發(fā)送驗證碼的時候,加上一個圖形校驗碼驗證,防止機器人讀取狂發(fā)驗證碼!!!不明事宜請聯(lián)系客服咨詢。發(fā)送手機驗證碼請做好以下幾點防范:
| 參數(shù)變量 | 是否必填 | 說明 |
|---|---|---|
| Gbk編碼Url | 是 | http://gbk.api.smschinese.cn/ |
| Utf-8編碼Url | 是 | http://utf8.api.smschinese.cn/ |
| Https接口Url | 是 | https://utf8api.smschinese.cn/ |
| Uid | 是 | 本站用戶名(無本站用戶名請先注冊,不是手機號)[免費注冊] |
| Key | 是 | 接口短信密鑰(可到平臺修改接口秘鑰)[立刻修改] 如需要加密參數(shù),請把Key變量名改成KeyMD5, KeyMD5=接口秘鑰32位MD5加密,大寫。 |
| smsMob | 是 | 目的手機號碼(多個手機號請用半角逗號隔開) 如:13888888886,13888888887,1388888888 最多100個手機 |
| smsText | 是 | 短信內(nèi)容,最多支持500個字,普通短信70個字/條,長短信64個字/條計費 提示:HTTP調(diào)用URL接口時, 變量請先轉(zhuǎn)URL編碼后再提交 |
| 短信發(fā)送后返回值 | 說 明 |
|---|---|
| 大于0 | 提交成功 短信發(fā)送數(shù)量 |
| -1 | 沒有該用戶賬戶 |
| -2 | 接口密鑰不正確 [查看密鑰] 不是賬戶登陸密碼 |
| -21 | MD5接口密鑰加密不正確 |
| -3 | 短信數(shù)量不足 |
| -11 | 該用戶被禁用 |
| -14 | 短信內(nèi)容出現(xiàn)非法字符 |
| -4 | 手機號格式不正確 |
| -41 | 手機號碼為空 |
| -42 | 短信內(nèi)容為空 |
| -51 | 短信簽名格式不正確 接口簽名格式為:【簽名內(nèi)容】 |
| -52 | 短信簽名太長 建議簽名10個字符以內(nèi) |
| -6 | IP限制 |
| 滬ICP備2021011364號-1 Copyright ? 2006-2024 webchinese.cn Inc. All Rights Reserved 網(wǎng)建 版權(quán)所有 |