|
|
@@ -244,6 +244,9 @@ module.exports = class extends think.Controller { |
|
|
const smsConfig = require('../config/sms.js'); |
|
|
const smsConfig = require('../config/sms.js'); |
|
|
const ip = this.ctx?.ip || ''; |
|
|
const ip = this.ctx?.ip || ''; |
|
|
|
|
|
|
|
|
|
|
|
think.logger.info(`[SMS] sendNotifySms 开始 - 手机号: ${mobile}, 模板: ${templateId}, 参数: ${JSON.stringify(templateParams)}, 业务: ${bizType}`); |
|
|
|
|
|
think.logger.info(`[SMS] 配置状态 - enabled: ${smsConfig.enabled}, smsSdkAppId: ${smsConfig.smsSdkAppId || '(空)'}, signName: ${smsConfig.signName || '(空)'}`); |
|
|
|
|
|
|
|
|
// 记录到数据库 |
|
|
// 记录到数据库 |
|
|
const smsLogModel = this.model('sms_log'); |
|
|
const smsLogModel = this.model('sms_log'); |
|
|
const logId = await smsLogModel.add({ |
|
|
const logId = await smsLogModel.add({ |
|
|
@@ -257,14 +260,19 @@ module.exports = class extends think.Controller { |
|
|
ip, |
|
|
ip, |
|
|
create_time: think.datetime(new Date()) |
|
|
create_time: think.datetime(new Date()) |
|
|
}); |
|
|
}); |
|
|
|
|
|
think.logger.info(`[SMS] 日志已写入数据库 logId: ${logId}`); |
|
|
|
|
|
|
|
|
let sendResult = { success: true, msgId: null }; |
|
|
let sendResult = { success: true, msgId: null }; |
|
|
if (smsConfig.enabled && smsConfig.smsSdkAppId) { |
|
|
if (smsConfig.enabled && smsConfig.smsSdkAppId) { |
|
|
|
|
|
think.logger.info(`[SMS] 调用腾讯云短信接口...`); |
|
|
sendResult = await this._sendTencentSms(mobile, templateId, templateParams); |
|
|
sendResult = await this._sendTencentSms(mobile, templateId, templateParams); |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
think.logger.info(`[SMS-DEV] 未启用真实发送 - enabled: ${smsConfig.enabled}, smsSdkAppId: ${smsConfig.smsSdkAppId || '(空)'}`); |
|
|
think.logger.info(`[SMS-DEV] 通知短信 手机号: ${mobile}, 模板: ${templateId}, 参数: ${JSON.stringify(templateParams)}, 业务: ${bizType}`); |
|
|
think.logger.info(`[SMS-DEV] 通知短信 手机号: ${mobile}, 模板: ${templateId}, 参数: ${JSON.stringify(templateParams)}, 业务: ${bizType}`); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
think.logger.info(`[SMS] sendNotifySms 结果 - success: ${sendResult.success}, msgId: ${sendResult.msgId || '(无)'}, message: ${sendResult.message || '(无)'}`); |
|
|
|
|
|
|
|
|
await smsLogModel.where({ id: logId }).update({ |
|
|
await smsLogModel.where({ id: logId }).update({ |
|
|
status: sendResult.success ? 1 : 2, |
|
|
status: sendResult.success ? 1 : 2, |
|
|
fail_reason: sendResult.success ? null : sendResult.message, |
|
|
fail_reason: sendResult.success ? null : sendResult.message, |
|
|
@@ -295,21 +303,28 @@ module.exports = class extends think.Controller { |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const result = await client.SendSms({ |
|
|
|
|
|
|
|
|
const reqParams = { |
|
|
PhoneNumberSet: [`+86${mobile}`], |
|
|
PhoneNumberSet: [`+86${mobile}`], |
|
|
SmsSdkAppId: smsConfig.smsSdkAppId, |
|
|
SmsSdkAppId: smsConfig.smsSdkAppId, |
|
|
SignName: smsConfig.signName, |
|
|
SignName: smsConfig.signName, |
|
|
TemplateId: templateId, |
|
|
TemplateId: templateId, |
|
|
TemplateParamSet: templateParams |
|
|
TemplateParamSet: templateParams |
|
|
}); |
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
think.logger.info(`[SMS] _sendTencentSms 请求参数: ${JSON.stringify(reqParams)}`); |
|
|
|
|
|
|
|
|
|
|
|
const result = await client.SendSms(reqParams); |
|
|
|
|
|
think.logger.info(`[SMS] _sendTencentSms 响应: ${JSON.stringify(result)}`); |
|
|
|
|
|
|
|
|
const sendStatus = result.SendStatusSet?.[0]; |
|
|
const sendStatus = result.SendStatusSet?.[0]; |
|
|
if (sendStatus?.Code === 'Ok') { |
|
|
if (sendStatus?.Code === 'Ok') { |
|
|
|
|
|
think.logger.info(`[SMS] 发送成功 SerialNo: ${sendStatus.SerialNo}`); |
|
|
return { success: true, msgId: sendStatus.SerialNo }; |
|
|
return { success: true, msgId: sendStatus.SerialNo }; |
|
|
} |
|
|
} |
|
|
|
|
|
think.logger.error(`[SMS] 发送失败 Code: ${sendStatus?.Code}, Message: ${sendStatus?.Message}`); |
|
|
return { success: false, message: sendStatus?.Message || '发送失败' }; |
|
|
return { success: false, message: sendStatus?.Message || '发送失败' }; |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
think.logger.error('[SMS] 腾讯云短信发送失败:', error); |
|
|
|
|
|
|
|
|
think.logger.error('[SMS] 腾讯云短信发送异常:', error.message); |
|
|
|
|
|
think.logger.error('[SMS] 异常堆栈:', error.stack); |
|
|
return { success: false, message: error.message }; |
|
|
return { success: false, message: error.message }; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|