You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.0 KiB

'use strict';
async function varfiyCode(ctx) {
try {
const { models } = ctx.fs.dc;
const { pushBySms, pushByEmail } = ctx.app.fs.utils
const { phone, type ,email,struction,point,number} = ctx.request.body
// 伪造的请求可能由相同的sig参数组成
// const checkSigUsed = await models.PhoneValidateCode.findOne({
// where: { sig: sig }
// });
// if (checkSigUsed) {
// throw '参数错误!'
// }
// // 验证sig正确性
// const checkSig = Hex.stringify(SHA1(phone + r));
// if (!r || !sig || sig != checkSig) {
// throw '参数错误!'
// }
let varifyCode = ''
for (let i = 0; i < 6; i++) {
varifyCode += Math.floor(Math.random() * 10)
}
if(type.includes(1)){
await pushBySms({
phone: phone,
templateCode: 'SMS_273640525',
templateParam: {
struction,
point,
number
},
})
}
if(type.includes(2)){
await pushByEmail({
email: email,
title: '隧道智慧运维助手',
text: `
您好${struction}中${point}点位故障问题已重复累积发生${number}存在一定风险可能原因是设备老化或其他隐患问题导致售后工程师正在排查`
})
}
// await models.PhoneValidateCode.create({
// phone: phone,
// code: varifyCode,
// sig: sig,
// expired: moment().add(10, 'minutes').format('YYYY-MM-DD HH:mm:ss')
// })
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : '获取验证码失败'
}
}
}
module.exports = {
varfiyCode,
// pushByEmail
}