node-qcloud-sms
v1.0.3
Published
## 腾讯云v5短信模块 需要先配置腾讯云短信参数才能正常使用
Downloads
2
Readme
node-qcloud-sms
腾讯云v5短信模块 需要先配置腾讯云短信参数才能正常使用
支持 发送单条短信
发送模板短信
群发短信
群发模板短信
Usage
npm install node-qcloud-sms --save
- 腾讯云配置
const qcloudSMS = require('node-qcloud-sms')
/**
* @param qcloudConfig 腾讯云配置信息
* @param sdkappid 腾讯云SMS服务对应的sdkappid
* @param appkey 腾讯云SMS服务对应的appkey
*/
qcloudSMS.qcloudConfig = {
sdkappid: 'xxx',
appkey: 'xxxx'
}
- 发送单条短信
/**
* @param tel 手机
* @param nationcode 国家码
* @param mobile 电话号码
* @param type 短信类型 0:普通短信;1:营销短信(强调:要按需填值,不然会影响到业务的正常使用)
* @param msg 短息内容,字段需要匹配审核通过的模板内容
*/
qcloudSMS.sendSingleMsg({
tel: {
nationcode: '86',
mobile: 'xxxxxxxxxx'
},
type: 0,
msg: 'xxxx为您的登录验证码,请于xxxx分钟内填写。如非本人操作,请忽略本短信。'
}).then(result => {
// 成功逻辑
}).catch(err => {
// 失败
})
- 发送模板短信
/**
* @param tel 手机
* @param nationcode 国家码
* @param mobile 电话号码
* @param tplId 业务在控制台审核通过的模板ID
* @param params //假定这个模板为:{1}为您的登录验证码,请于{2}分钟内填写。如非本人操作,请忽略本短信。参数,分别对应上面假定模板的{1},{2}
*/
qcloudSMS.sendTemplateMsg({
tel: {
nationcode: '86',
mobile: 'xxxxxxxxxx'
},
tplId: 'xxxx',
params: [
'1234',
'4'
]
}).then(result => {
// 成功逻辑
}).catch(err => {
// 失败逻辑
})
- 群发短信
/**
* @param tel 手机 群发数组 单次提交不超过200个手机号,内容长度不超过450字
* @param nationcode 国家码
* @param mobile 电话号码
* @param type 短信类型 0:普通短信;1:营销短信(强调:要按需填值,不然会影响到业务的正常使用)
* @param msg 短息内容,字段需要匹配审核通过的模板内容
*/
qcloudSMS.sendMultiMsg({
tel: [{
nationcode: '86',
mobile: 'xxxxxxxxxx'
}, {
nationcode: '86',
mobile: 'xxxxxxxxxx'
}],
type: 0,
msg: 'xxxx为您的登录验证码,请于xx分钟内填写。如非本人操作,请忽略本短信。'
}).then(result => {
console.debug('成功')
console.debug(result.text)
}).catch(err => {
console.debug('出错了')
console.debug(err)
})
- 群发模板短信
/**
* @param tel 手机 群发数组 单次提交不超过200个手机号,内容长度不超过450字
* @param nationcode 国家码
* @param mobile 电话号码
* @param tplId 业务在控制台审核通过的模板ID
* @param params //假定这个模板为:{1}为您的登录验证码,请于{2}分钟内填写。如非本人操作,请忽略本短信。参数,分别对应上面假定模板的{1},{2}
*/
qcloudSMS.sendMultiTemplateMsg({
tel: [{
nationcode: '86',
mobile: 'xxxxxxxxxx'
}, {
nationcode: '86',
mobile: 'xxxxxxxxxx'
}],
tplId: 'xxxx',
params: [
'1234',
'4'
]
}).then(result => {
console.debug('成功')
console.debug(result.text)
}).catch(err => {
console.debug('出错了')
console.debug(err)
})