Commit 5e06c625 authored by Hsinli's avatar Hsinli

addd

parent f9c547a0
Pipeline #13517 passed with stage
in 4 seconds
......@@ -21,20 +21,19 @@ class SmsService extends Service {
const appKey = '276BC440-B67E-44DA-ADC0-944A79F0DAB0';
let params = {
app_id: appId,
timestamp: new Date().getTime(),
timestamp: new Date().getTime().toString(),
sign: '',
params: {
phone: inputParams.phone,
content: inputParams.content,
schedule: inputParams.hasOwnProperty('schedule') ? inputParams.schedule : ''
}
}
params.sign = await ctx.helper.md5(params.timestamp + '&' + appKey);
if (!(/【51公积金】/.test(params.params.content))) {
params.params.content = '【51公积金】' + params.params.content;
}
if (inputParams.hasOwnProperty('schedule')) {
params.params.schedule = inputParams.schedule;
}
ctx.logger.info(params);
let result = await ctx.helper.send_request(url, params, { method: 'POST' });
return result;
}
......
......@@ -41,16 +41,16 @@ class ApplyService extends Service {
*/
//60秒只能获取一次
let lockKey = 'mine:credit:black:lock' + inputParams.phone;
let lock = app.redis.get(lockKey);
let lock = await app.redis.get(lockKey);
ctx.logger.info(lock);
if (lock && lock !== null) {
ctx.failed('获取验证码过于频繁,请稍后再试');
}
await app.redis.set('lock', lockKey, 'EX', 5);//60秒锁
await app.redis.set(lockKey, 'lock', 'EX', 60);//60秒锁
//每日次数限制
let timesKey = 'mine:credit:black:times' + inputParams.phone;
let times = app.redis.get(timesKey);
let times = await app.redis.get(timesKey);
if (!times) {
times = 0;
}
......@@ -59,7 +59,7 @@ class ApplyService extends Service {
ctx.failed('今日获取验证码次数过多,请明日再试');
}
let pexpire = new Date(moment().add(1, 'days').format('YYYY-MM-DD')).getTime();
await app.redis.set(times, timesKey, 'PX', pexpire);//今日有效
await app.redis.set(timesKey, times, 'PX', pexpire);//今日有效
//生成
let code = '';
......@@ -71,15 +71,19 @@ class ApplyService extends Service {
}
}
let codeKey = 'mine:credit:black:code' + inputParams.phone;
await app.redis.set(code, codeKey, 'EX', 60 * 5);//5分钟有效时间
await app.redis.set(codeKey, code, 'EX', 60 * 5);//5分钟有效时间
let smsParams = {
phone: inputParams.phone,
content: '【51公积金】您本次操作的短信验证码为' + code + ',谨慎保管,切勿告诉他人。'
}
let smsResult = await ctx.service.common.sms.sendSms(smsParams);
ctx.logger.info(smsResult);
return { code: 1, msg: 'ok' };
// let smsResult = await ctx.service.common.sms.sendSms(smsParams);
// let ret = {
// code: smsResult.status === 201 ? 1 : 0,
// msg: smsResult.status === 201 ? '短信发送成功' : '短信发送失败'
// }
// return ret;
return 1;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment