No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
.gitignore
README.md
index.js
package.json

README.md

wilddog-sms

Wilddog SMS SDK for Node.js

Getting started

安装node.js module:

npm install wilddog-sms --save

初始化

var SMS = require('wilddog-sms');

var sms = new SMS({appId: '<YOUR_APP_ID>', smsKey: '<YOUR_SMS_KEY>'});

发送验证码短信

sms.sendCode(string mobile, string templateId, [array params , callback])

Use promise

var q = sms.sendCode('<PHONE_NUMBER>', '<YOUR_TEMPLATE_ID>', ['8888']);

q.then(function (data) {
    console.log(data);
}).error(function (err) {
    console.log(err);
});

Use callback

sms.sendCode('<PHONE_NUMBER>', '<YOUR_TEMPLATE_ID>', ['9999'], function (err, data) {
    if(err) throw err;
    console.log(data);
});

校验验证码

sms.checkCode(string mobile, string code [, callback])

Use promise

var q = sms.checkCode('<PHONE_NUMBER>', '<CODE>');

q.then(function (data) {
    console.log(data);
}).error(function (err) {
    console.log(err);
});

Use callback

sms.checkCode('<PHONE_NUMBER>', '8888', function (err, data) {
    if(err) throw err;
    console.log(data);
});

发送通知短信

sms.sendNotify(array mobiles, string templateId, array params [, callback])

Use promise:

var q = sms.sendCode(['<PHONE_NUMBER>'], '<YOUR_TEMPLATE_ID>', ['Var1', 'Var2']);

q.then(function (data) {
    console.log(data);
}).error(function (err) {
    console.log(err);
});

Use callback

sms.sendCode(['<PHONE_NUMBER>'], '<YOUR_TEMPLATE_ID>', ['Var1', 'Var2'], function(err, data) {
    if(err) throw err;
    console.log(data);
});

查询发送状态

sms.sendStatus(string rrid [, callback])

Use promise

sms.sendStatus('<RRID>').then(function (data) {
    console.log(data);
}).error(function (err) {
    console.log(err);
});

Use callback

sms.sendStatus('<RRID>', function (err, data) {
    if(err) throw err;
    console.log(data);
});

查询账户余额

sms.queryBalance([callback])

Use promise

sms.queryBalance()
    .then(function (data) {
        console.log(data);
    })
    .err(function(err) {
        console.log(err);
    });

Use callback

sms.queryBalance(function (err, data) {
    console.log(arguments);
});

所有API均支持Promise与传统callback两种方式调用。如果不传callback则会返回Promise,否则callback会被触发。