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

@alicloud/sms-sdk

v1.1.6

Published

阿里云-云通信-短信产品SDK

Downloads

3,141

Readme

安装

 $ npm install @alicloud/sms-sdk --save

使用方法

  1. 安装@alicloud/sms-sdk,请需要根据官方文档做一些配置
  2. 产品文档: https://dysms.console.aliyun.com/dysms.htm
  3. Node.js版本 >= v7.6.0

DEMO

/**
 * 云通信基础能力业务短信发送、查询详情以及消费消息示例,供参考。
 * Created on 2017-07-31
 */

const SMSClient = require('@alicloud/sms-sdk')

// ACCESS_KEY_ID/ACCESS_KEY_SECRET 根据实际申请的账号信息进行替换
const accessKeyId = 'yourAccessKeyId'
const secretAccessKey = 'yourAccessKeySecret'

//在云通信页面开通相应业务消息后,就能在页面上获得对应的queueName,不用填最后面一段
const queueName = 'Alicom-Queue-1092397003988387-'

// vpc需要配置,华东1示例:请查看 https://help.aliyun.com/document_detail/68360.html
const smsApiEndpoint = 'http://dysmsapi-vpc.cn-hangzhou.aliyuncs.com'
const baseApiEndpoint = 'http://dybaseapi-vpc.cn-hangzhou.aliyuncs.com'
const regionId = 'cn-hangzhou' 
const mnsVpc = {
    secure: false, // use https or http
    internal: true, // use internal endpoint
    vpc: true
}



//初始化sms_client, 后面4个参数vpc需要配置
let smsClient = new SMSClient({accessKeyId, secretAccessKey, smsApiEndpoint, baseApiEndpoint, regionId, mnsVpc})

smsClient.sendBatchSMS({
    PhoneNumberJson: JSON.stringify(['18040580000', '15088650000']),
    SignNameJson: JSON.stringify(['短信迁移测试签名','短信迁移测试签名']),
    TemplateCode: 'SMS_71175823',
    TemplateParamJson: JSON.stringify([{code: "1234", product: "ytx1"}, {code: "5678", product: "ytx2"}]),
}).then(function (res) {
    let {Code}=res
    if (Code === 'OK') {
       //处理返回参数
       console.log(res)
    }
}, function (err) {
    console.log('err', err)
})


//短信回执报告,5表示5s=>未被删除的消息再次推送等待时间,true表示消费完进行删除(默认为false)
smsClient.receiveMsg(0, queueName, 5, true).then(function (res) {
    //消息体需要base64解码
    let {code, body}=res
    if (code === 200) {
        //处理消息体,messagebody
        console.log(body)
    }
}, function (err) {
    console.log(err)
})

//短信上行报告,5表示5s=>未被删除的消息再次推送等待时间,true表示消费完进行删除(默认为false)
smsClient.receiveMsg(1, queueName, 5, true).then(function (res) {
    //消息体需要base64解码
    let {code, body}=res
    if (code === 200) {
        //处理消息体,messagebody
        console.log(body)
    }
}, function (err) {
    console.log(err)
})


//查询短信发送详情
smsClient.queryDetail({
    PhoneNumber: '1500000000',
    SendDate: '20170731',
    PageSize: '10',
    CurrentPage: "1"
}).then(function (res) {
    let {Code, SmsSendDetailDTOs}=res
    if (Code === 'OK') {
        //处理发送详情内容
        console.log(SmsSendDetailDTOs)
    }
}, function (err) {
    //处理错误
    console.log(err)
})

//发送短信, vpc配置options={method:'POST'},改为POST请求
smsClient.sendSMS({
    PhoneNumbers: '1500000000',
    SignName: '云通信产品',
    TemplateCode: 'SMS_000000',
    TemplateParam: '{"code":"12345","product":"云通信"}'
},options).then(function (res) {
    let {Code}=res
    if (Code === 'OK') {
        //处理返回参数
        console.log(res)
    }
}, function (err) {
    console.log(err)
})