npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yunpian-sms-client

v2.0.3

Published

yunpian sms nodejs client

Downloads

6

Readme

yunpian-sms-client

npm npm npm

yunpian-sms-client 用于对接云片网提供的短信发送接口的nodejs简单实现,相关的接口和示例已测试通过,若有问题请在issue中提出或pull request。

更新版本至v2,详见云片网API文档:v2.0文档 注:使用此yunpian-sms-client 的旧版本(v1.x)若升级至当前最新版本,原调用的代码需要进行局部修改,请参见示例:v1.x使用示例

本次更新主要是为了适配云片网API v2.0新接口(按自己需要实现了部份),在调用层面支持Promise的风格调用,缩减了一些无用的代码。

2016-11-23更新根据反馈,增加获取回复短信及检查是否屏蔽词接口,并开放自定义调用云片v2.0 API方法,详见下文说明;


[TOC]


说明

yunpian-sms-client 旧版本的调用方式请移步示例中查看, 以下信息都是以当前版本做说明,所列出的接口实现中已支持官方文档中注明的所有参数(有些参数如发送信息后希望回调uid需要申请开通,这里就不作演示了).

安装

npm install yunpian-sms-client --save

初始化一个SMS Provider

var smsProvider = require('yunpian-sms-client').v2;
var apiKey = 'your apiKey';
var provider = smsProvider.initWithKey(apiKey);
var text = '【xxxx】您的短信验证码为:23845';
var mobile = 'your mobile';

单条信息发送


provider.sendSingleSms({
    mobile: mobile,
    text: text,
    uid: '234'//可选,请参见官方文档说明
}).then(function (result) {
    if (result) {
        console.log(result);
    }
}).catch(function (err) {
    console.log(err);
});

//或者分步写效果是一样,后续的示例不再重复说明
var promise = provider.sendSingleSms({
    mobile: mobile,
    text: text,
    uid: '234'//可选,请参见官方文档说明
});

promise.then(function(result){
//
});
promise.catch(function(err){
 //
})

批量发送信息


provider.sendBatchSms({mobile:'your mobile,your girl mobile...',text:text}).then(function(result){
    if(result){
        console.log(result);
    }
}).catch(function(err){
    console.log(err);
});

指定模板单发(官方不推荐使用),看起来用处也不是很大


provider.sendSingleTplSms({
    mobile: mobile,
    tpl_id: 1411507,
    tpl_value: "#code#=1411507"
}).then(function (result) {
    if (result) {
        console.log(result);
    }
}).catch(function (err) {
    console.log(err);
});

查短信发送报告

provider.getSmsStatusReport({page_size: 10}).then(function (report) {
    if (report) {
        console.log(report);
    }
}).catch(function (err) {
    console.log(err);
});

查短信发送记录

provider.getSmsSendRecord({start_time: '2016-01-02 00:00:00', end_time: '2016-06-23 12:00:00'}).then(function (record) {
    if (record) {
        console.log(record);
    }
}).catch(function (err) {
    console.log(err);
});

获取短信回复记录

provider.getSmsReplyRecord({
    start_time: '2016-08-11 00:00:00',
    end_time: '2017-08-11 00:00:00',
    page_num:1, //页码,默认1,必填
    page_size:20 //页大小,最大允许100,必填,
    /*mobile:13xxxxxx*///填写时只查该手机号的回复,不填时查所有的回复 ,可选
}).then(function (res) {
    if(res) {
        console.log(res);
    }
}).catch(function (e) {
    console.log(e);
});

检查内容是否包含屏蔽词

provider.isBlackWord('发票,微贷,贷款').then(function (res) {
    if (res) { //返回屏蔽词数组
        console.log(res);
    }
}).catch(function (e) {
    console.log(e);
});

备注

其他未在此文档中的接口调用,大家若有需要,可以通过以下方式自定义实现(即可自行根据云片的v2.0文档路径定义调用),如自定义实现获取回复内容的接口也可以这么实现(其他接口同理):

//注:若是es6使用者可以直接使用let
var data = {
    start_time: '2016-08-11 00:00:00',
    end_time: '2017-08-11 00:00:00',
    page_num: 1, //页码,默认1,必填
    page_size: 20 //页大小,最大允许100,必填,
    /*mobile:13xxxxxx*///填写时只查该手机号的回复,不填时查所有的回复 ,可选
};
var path = '/v2/sms/get_reply.json';
provider.getCustomReqSmsAPI(data, path).then(function (res) {
    if (res) {
        console.log(res);
    }
}).catch(function (e) {
    console.log(e);
});

其他说明

习惯上使用co或es6+的童鞋,也可以包装为以下方式:

  return co(function *() {
        const path = '/v2/sms/get_reply.json';
        let data = {
            start_time: '2016-08-11 00:00:00',
            end_time: '2017-08-11 00:00:00',
            page_num: 1, //页码,默认1,必填
            page_size: 20 //页大小,最大允许100,必填,
            /*mobile:13xxxxxx*///填写时只查该手机号的回复,不填时查所有的回复 ,可选
        };

        return yield provider.getCustomReqSmsAPI(data, path);
    });