修改 sendSms: 返回状态变量 _state=‘SMS_SENT_SUCCESS' 而不是 sendState='DONE'

This commit is contained in:
陆柯 2021-10-15 09:24:57 +08:00
parent 196c2e6219
commit 1146a72d25

View File

@ -7,12 +7,14 @@ let smtpTransporter = null
let smsClient = null // 在调用时,才创建 smsClient防止 wo.envi 还没有建立好。 let smsClient = null // 在调用时,才创建 smsClient防止 wo.envi 还没有建立好。
module.exports = { module.exports = {
sendMail: async function (option) {
async sendMail (option) {
// 或者如果smtp参数已经确定就可以直接定义 sendMail: Bluebird.promisify(Smtp.sendMail).bind(Smtp) // 或者如果smtp参数已经确定就可以直接定义 sendMail: Bluebird.promisify(Smtp.sendMail).bind(Smtp)
smtpTransporter = smtpTransporter || NodeMailer.createTransport(wo.envi.SMTP) smtpTransporter = smtpTransporter || NodeMailer.createTransport(wo.envi.SMTP)
return await util.promisify(smtpTransporter.sendMail).call(smtpTransporter, option) return await util.promisify(smtpTransporter.sendMail).call(smtpTransporter, option)
}, },
sendSms: async function (phone, option) {
async sendSms (phone, option) {
// 通过option对象对外提供统一的调用参数格式 // 通过option对象对外提供统一的调用参数格式
if (/^\+\d+-\d+$/.test(phone)) { if (/^\+\d+-\d+$/.test(phone)) {
option = option || {} option = option || {}
@ -24,7 +26,8 @@ module.exports = {
} }
return null // 手机号格式错误,或者 option.vendor 错误。 return null // 手机号格式错误,或者 option.vendor 错误。
}, },
sendSmsDxton: async function (phone, msg) {
async sendSmsDxton (phone, msg) {
// 使用 dxton.com 的短信接口。 // 使用 dxton.com 的短信接口。
var matches = phone.match(/\d+/g) var matches = phone.match(/\d+/g)
var smsNumber, smsUrl var smsNumber, smsUrl
@ -37,11 +40,11 @@ module.exports = {
} }
// return Bluebird.promisify(Http.get)(smsUrl+'&mobile='+smsNumber+"&content="+encodeURIComponent(msg)); // return Bluebird.promisify(Http.get)(smsUrl+'&mobile='+smsNumber+"&content="+encodeURIComponent(msg));
let returnValue = await RequestPromise.get(smsUrl + '&mobile=' + smsNumber + '&content=' + encodeURIComponent(msg)) let returnValue = await RequestPromise.get(smsUrl + '&mobile=' + smsNumber + '&content=' + encodeURIComponent(msg))
let result = { state: 'FAIL', code: returnValue } let result = { _state: 'SMS_SEND_FAIL', code: returnValue }
switch (parseInt(returnValue)) { switch (parseInt(returnValue)) {
// 短信接口代码http://www.dxton.com/help_detail/2.html // 短信接口代码http://www.dxton.com/help_detail/2.html
case 100: case 100:
return { state: 'DONE', code: '100', msg: 'sendSms: 发送成功 (表示已和我们接口连通)' } return { _state: 'SMS_SENT_SUCCESS', code: '100', msg: 'sendSms: 发送成功 (表示已和我们接口连通)' }
case 101: case 101:
result.msg = 'sendSms: 验证失败(账号、密码可能错误)' result.msg = 'sendSms: 验证失败(账号、密码可能错误)'
case 102: case 102:
@ -69,7 +72,8 @@ module.exports = {
return result return result
} }
}, },
sendSmsAliyun: async function (phone, msgParam, templateCode, signName) {
async sendSmsAliyun (phone, msgParam, templateCode, signName) {
// msgParam 是消息模板参数对象,例如 { code: "890353" } // msgParam 是消息模板参数对象,例如 { code: "890353" }
smsClient = smsClient =
smsClient || smsClient ||
@ -97,13 +101,13 @@ module.exports = {
function (res) { function (res) {
let { Code } = res let { Code } = res
if (Code === 'OK') { if (Code === 'OK') {
return { state: 'DONE' } return { _state: 'SMS_SENT_SUCCESS' }
} else { } else {
return { state: 'FAIL', result: res } return { _state: 'SMS_SEND_FAIL', result: res }
} }
}, },
function (err) { function (err) {
return { state: 'ERROR', error: err } return { _state: 'SMS_SEND_ERROR', error: err }
} }
) )
}, },