把 templateCode 参数改为 msgTemplate

This commit is contained in:
Luk Lu
2022-03-09 15:58:50 +08:00
parent 2875879874
commit 4ad3051fa1
2 changed files with 5 additions and 5 deletions

View File

@@ -35,7 +35,7 @@ module.exports = {
const [ sms, save ] = await Promise.all([ const [ sms, save ] = await Promise.all([
sendSMS(phone, { sendSMS(phone, {
msgParam: { code }, msgParam: { code },
templateCode: 'SMS_142465215', msgTemplate: 'SMS_142465215',
signName: 'VIC' signName: 'VIC'
}), }),
this.saveCode({ this.saveCode({

View File

@@ -1,12 +1,12 @@
'use strict'; 'use strict';
async function sendSmsAliyun (smsClient, phone, msgParam, templateCode, signName) { // msgParam 是消息模板参数对象,例如 { code: "890353" } async function sendSmsAliyun (smsClient, phone, msgParam, msgTemplate, signName) { // msgParam 是消息模板参数对象,例如 { code: "890353" }
let matches = phone.match(/\d+/g); let matches = phone.match(/\d+/g);
let smsNumber = matches[0] === '86' ? matches[1] : '00' + matches[0] + matches[1]; let smsNumber = matches[0] === '86' ? matches[1] : '00' + matches[0] + matches[1];
const res = await smsClient.sendSMS({ const res = await smsClient.sendSMS({
PhoneNumbers: smsNumber,//必填:待发送手机号。支持以逗号分隔的形式进行批量调用批量上限为1000个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式;发送国际/港澳台消息时接收号码格式为00+国际区号+号码如“0085200000000” PhoneNumbers: smsNumber,//必填:待发送手机号。支持以逗号分隔的形式进行批量调用批量上限为1000个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式;发送国际/港澳台消息时接收号码格式为00+国际区号+号码如“0085200000000”
SignName: signName,//必填:短信签名-可在短信控制台中找到 SignName: signName,//必填:短信签名-可在短信控制台中找到
TemplateCode: templateCode,//必填:短信模板-可在短信控制台中找到,发送国际/港澳台消息时,请使用国际/港澳台短信模版 TemplateCode: msgTemplate,//必填:短信模板-可在短信控制台中找到,发送国际/港澳台消息时,请使用国际/港澳台短信模版
TemplateParam: JSON.stringify(msgParam) //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时。 TemplateParam: JSON.stringify(msgParam) //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时。
}); });
if (res && res.Code && res.Code === 'ok') { if (res && res.Code && res.Code === 'ok') {
@@ -40,8 +40,8 @@ module.exports = {
}); });
return async function (phone, option = {}) { // 通过option对象对外提供统一的调用参数格式 return async function (phone, option = {}) { // 通过option对象对外提供统一的调用参数格式
if (/^\+\d+-\d+$/.test(phone)) { if (/^\+\d+-\d+$/.test(phone)) {
if (option.msgParam && option.templateCode && option.signName) { if (option.msgParam && option.msgTemplate && option.signName) {
return await sendSmsAliyun(smsClient, phone, option.msgParam, option.templateCode, option.signName).catch(err => { return await sendSmsAliyun(smsClient, phone, option.msgParam, option.msgTemplate, option.signName).catch(err => {
const errmsg = '短信发送失败 ' + JSON.stringify(err); const errmsg = '短信发送失败 ' + JSON.stringify(err);
mylog && mylog.error ? mylog.error(errmsg) : console.error(errmsg); mylog && mylog.error ? mylog.error(errmsg) : console.error(errmsg);
}); });