互億無線 · 文檔中心

短信驗證碼/通知 - 代碼示例


NODE.JS對接驗證碼短信接口DEMO示例
本文為您提供了NODE.JS語言版本的驗證碼短信接口對接DEMO示例

驗證碼/通知短信接口文檔 點擊下載

驗證碼/通知短信接口接入指南 點擊訪問

注冊/登錄頁圖形驗證工具 點擊訪問


/* *
 * 接口類型:互億無線觸發(fā)短信接口,支持發(fā)送驗證碼短信、訂單通知短信等。
 * 賬戶注冊:請通過該地址開通賬戶https://user.ihuyi.com/new/register.html
 * 注意事項:
*(1)調(diào)試期間,請使用用系統(tǒng)默認的短信內(nèi)容:您的驗證碼是:【變量】。請不要把驗證碼泄露給其他人。
 *(2)請使用 用戶名 及 APIkey來調(diào)用接口,APIkey在會員中心可以獲?。?
*(3)該代碼僅供接入互億無線短信接口參考使用,客戶可根據(jù)實際需要自行編寫;
*/
 
/**
 * Created by XadillaX on 14-2-12.
 * https://github.com/XadillaX/ihuyi106js
 */
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://106.ihuyi.com/webservice/sms.php?method=Submit";
var _userAgent = "node-ihuyi106-module by 死月 (admin@xcoder.in)";
 
/**
 * iHuyi constructure.
 * @param account
 * @param password 查看密碼請登錄用戶中心->驗證碼、通知短信->帳戶及簽名設置->APIKEY
 */
var iHuyi = function(account, password) {
    this.spidex = require("spidex");
    this.spidex.setDefaultUserAgent(_userAgent);
 
    this.account = account;
    this.password = password;
};
 
/**
 * send an SMS.
 * @param mobile
 * @param content
 * @param callback
 */
iHuyi.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ā)送服務器響應失敗。"));
            return;
        }
 
        html = html.replaceAll("\r", "");
        html = html.replaceAll("\n", "");
        html = html.replaceAll(" xmlns=\"http://106.ihuyi.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 = iHuyi;

現(xiàn)在注冊,即享新用戶禮包!

在線咨詢
電話咨詢

服務熱線:

4008 808 898

服務熱線(工作時間):

4008 808 898

業(yè)務咨詢(非工作時間):

售后咨詢(非工作時間):

驗證碼已發(fā)送到您的手機,請查收!

輸入驗證碼后,點擊“開通體驗賬戶”按鈕可立即開通體驗賬戶。

收不到短信驗證碼?
互億無線不提供接碼服務,接碼用戶請勿點擊開通按鈕。
×