名稱 | 是否必須 | 示例值 | 說明 |
---|---|---|---|
請求地址 | UTF-8 | http://dc.28inter.com/sms.aspx | 如果服務器不支持解析, 請聯系技術人員進行協助處理! |
名稱 | 是否必須 | 示例值 | 描述 |
---|---|---|---|
發送任務命令 | 必須 | 固定設置為:send | 設置為固定的:send |
帳戶 | 必須 | 28inter | 注冊獲或系統管理員分配取,登陸賬號 |
密碼 | 必須 | 123456 | 注冊或系統管理員分配獲取,登陸密碼 |
用戶ID | 必須 | 1001 | 注冊或系統管理員分配獲取,賬戶ID |
發送號碼 | 必須 | 13000000000,13000000001 | 短信接收號碼。支持單個或多個手機號碼,傳入號碼為11位手機號碼,不能加0或86。群發短信需傳入多個號碼,以英文逗號分隔,一次調用最多傳入200個號碼示例:13000000000,13000000001 |
發送內容 | 必須 | 【創信信息】您的驗證碼是:123456 | 發送短信的內容,整體做用urlencode。短信的格式為:【簽名】放在內容的最前方。 |
sendtime | 可選 | 2000-12-31 00:00:10 | 短信定時發送時間。不設置默認為立即發送。格式為:YYYY-MM-DD HH:MM:SS |
rt | 可選 | json | 固定值 json,不填則為XML格式返回 |
NODE.JS實例 |
---|
String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) { if (!RegExp.prototype.isPrototypeOf(reallyDo)) { return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith); } else { return this.replace(reallyDo, replaceWith); } }; var dom = require('xmldom').DOMParser; var _baseUri = "http://dc.28inter.com/sms.aspx?action=send" var _userAgent = "node-cxsms" /** * sms constructure. * @param userid ID * @param account 用戶名 * @param password 接口密碼 */ var sms = function(userid, account, password) { this.spidex = require("spidex"); this.spidex.setDefaultUserAgent(_userAgent); this.userid = userid; this.account = account; this.password = password; }; /** * send an SMS. * @param mobile * @param content * @param callback */ sms.prototype.send = function(mobile, content, callback) { var data = { account : this.account, password : this.password, mobile : mobile, content : content }; this.spidex.post(_baseUri, function(html, status) { if(status !== 200) { callback(new Error("短信發送服務器響應失敗。")); return; } html = html.replaceAll("\r", ""); html = html.replaceAll("\n", ""); html = html.replaceAll(" xmlns=\"http://dc.28inter.com/\"", "");
//console.log(html); var doc = new dom().parseFromString(html); var result = doc.lastChild; var json = {}; for(var node = result.firstChild; node !== null; node = node.nextSibling) { json[node.tagName] = node.firstChild.data; } //console.log(json); if(json.code == "2") { callback(null, json.smsid); } else { callback(new Error(json.msg, parseInt(json.code))); } }, data, "utf8").on("err", function(e) { callback(e); }); }; module.exports = sms; |