阿里云短信发送模块api及demo

地址:https://www.npmjs.com/package/@alicloud/sms-sdk

安装方法:$ npm install @alicloud/sms-sdk --save

代码:

 

/**

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

 * 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-'

 

//初始化sms_client

let smsClient = new SMSClient({accessKeyId, secretAccessKey})

 

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)

})

 

 

//短信回执报告

smsClient.receiveMsg(0, queueName).then(function (res) {

    //消息体需要base64解码

    let {code, body}=res

    if (code === 200) {

        //处理消息体,messagebody

        console.log(body)

    }

}, function (err) {

    console.log(err)

})

 

//短信上行报告

smsClient.receiveMsg(1, queueName).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)

})

 

//发送短信

smsClient.sendSMS({

    PhoneNumbers: '1500000000',

    SignName: '云通信产品',

    TemplateCode: 'SMS_000000',

    TemplateParam: '{"code":"12345","product":"云通信"}'

}).then(function (res) {

    let {Code}=res

    if (Code === 'OK') {

        //处理返回参数

        console.log(res)

    }

}, function (err) {

    console.log(err)

})

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值