| 名稱 | 是否必須 | 示例值 | 說(shuō)明 |
|---|---|---|---|
| 請(qǐng)求地址 | UTF-8 | http://dc.28inter.com/sms.aspx | 如果服務(wù)器不支持解析, 請(qǐng)聯(lián)系技術(shù)人員進(jìn)行協(xié)助處理! |
| 名稱 | 是否必須 | 示例值 | 描述 |
|---|---|---|---|
| 發(fā)送任務(wù)命令 | 必須 | 固定設(shè)置為:send | 設(shè)置為固定的:send |
| 帳戶 | 必須 | 28inter | 注冊(cè)獲或系統(tǒng)管理員分配取,登陸賬號(hào) |
| 密碼 | 必須 | 123456 | 注冊(cè)或系統(tǒng)管理員分配獲取,登陸密碼 |
| 用戶ID | 必須 | 1001 | 注冊(cè)或系統(tǒng)管理員分配獲取,賬戶ID |
| 發(fā)送號(hào)碼 | 必須 | 13000000000,13000000001 | 短信接收號(hào)碼。支持單個(gè)或多個(gè)手機(jī)號(hào)碼,傳入號(hào)碼為11位手機(jī)號(hào)碼,不能加0或86。群發(fā)短信需傳入多個(gè)號(hào)碼,以英文逗號(hào)分隔,一次調(diào)用最多傳入200個(gè)號(hào)碼示例:13000000000,13000000001 |
| 發(fā)送內(nèi)容 | 必須 | 【創(chuàng)信信息】您的驗(yàn)證碼是:123456 | 發(fā)送短信的內(nèi)容,整體做用urlencode。短信的格式為:【簽名】放在內(nèi)容的最前方。 |
| sendtime | 可選 | 2000-12-31 00:00:10 | 短信定時(shí)發(fā)送時(shí)間。不設(shè)置默認(rèn)為立即發(fā)送。格式為:YYYY-MM-DD HH:MM:SS |
| rt | 可選 | json | 固定值 json,不填則為XML格式返回 |
| NODE.JS實(shí)例 |
|---|
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("短信發(fā)送服務(wù)器響應(yīng)失敗。")); 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; |