Commit a412177e by 王昆

gsb

parent 3ccca8c1
...@@ -132,6 +132,52 @@ class LaoActionApi extends APIBase { ...@@ -132,6 +132,52 @@ class LaoActionApi extends APIBase {
} }
} }
// async SendSms(obj) { //用户登录,返回用户信息
// if (!obj.phone_no) {
// return system.getResult(null, "电话号码不能为空");
// }
// var phone_no = this.trim(obj.phone_no);
//
// try {
// if (!/^1[23456789]\d{9}$/.test(phone_no)) {
// return system.getResult(null, "手机号码格式不正确");
// }
// let data=null,_result={data:"发送成功"};
// //如果是短信模板则直接发送短信
// if(obj.templateName=="smsTemplate"){
// data= {
// "templateName": "smsTemplate", // 模板类型 loginTemplate(登陆) authenticationTemplate(验证) smsTemplate(短信通知)
// "phoneNumbers": phone_no, // 手机号
// "name":this.trim(obj.name), // 模板参数 默认字段 如果是短信通知模板,则请勿传值
// }
// _result = await this.msSve.SendSms(data);
// }else{
// var isTest = this.testPhones.indexOf(phone_no) != -1;
// // 生成验证码
// var key = this.vcodePrev + phone_no;
// var vcode = await this.redisClient.get(key + "t");
// if (!vcode) {
// vcode = isTest ? "123123" : await this.getVCode();
// await this.redisClient.setWithEx(key, vcode, 5 * 60);
// await this.redisClient.setWithEx(key + "t", vcode, 60);
// var msg = "您的验证码为" + vcode + ", (切勿将验证码告知别人, 请在5分钟内输入完成验证, 如有问题请联系客服。)";
// if (!isTest) {
// // var rs = await this.smsClient.sendMsg(phone_no, msg);
// data = {
// "templateName": obj.templateName, // 模板类型 loginTemplate(登陆) authenticationTemplate(验证) smsTemplate(短信通知)
// "phoneNumbers": phone_no, // 手机号
// "code":vcode, // 模板参数 默认字段 如果是短信通知模板,则请勿传值
// }
// _result = await this.msSve.SendSms(data);
// }
// }
// }
// return _result;
// } catch (error) {
// return system.getResultFail(500, "接口异常:" + error.message);
// }
// }
async SendSms(obj) { //用户登录,返回用户信息 async SendSms(obj) { //用户登录,返回用户信息
if (!obj.phone_no) { if (!obj.phone_no) {
return system.getResult(null, "电话号码不能为空"); return system.getResult(null, "电话号码不能为空");
...@@ -142,37 +188,22 @@ class LaoActionApi extends APIBase { ...@@ -142,37 +188,22 @@ class LaoActionApi extends APIBase {
if (!/^1[23456789]\d{9}$/.test(phone_no)) { if (!/^1[23456789]\d{9}$/.test(phone_no)) {
return system.getResult(null, "手机号码格式不正确"); return system.getResult(null, "手机号码格式不正确");
} }
let data=null,_result={data:"发送成功"};
//如果是短信模板则直接发送短信 var isTest = this.testPhones.indexOf(phone_no) != -1;
if(obj.templateName=="smsTemplate"){ // 生成验证码
data= { var key = this.vcodePrev + phone_no;
"templateName": "smsTemplate", // 模板类型 loginTemplate(登陆) authenticationTemplate(验证) smsTemplate(短信通知) var vcode = await this.redisClient.get(key + "t");
"phoneNumbers": phone_no, // 手机号 if (!vcode) {
"name":this.trim(obj.name), // 模板参数 默认字段 如果是短信通知模板,则请勿传值 vcode = isTest ? "123123" : await this.getVCode();
} await this.redisClient.setWithEx(key, vcode, 5 * 60);
_result = await this.msSve.SendSms(data); await this.redisClient.setWithEx(key + "t", vcode, 60);
}else{ var msg = "您的验证码为" + vcode + ", (切勿将验证码告知别人, 请在5分钟内输入完成验证, 如有问题请联系客服。)";
var isTest = this.testPhones.indexOf(phone_no) != -1; if (!isTest) {
// 生成验证码 var rs = await this.smsClient.sendMsg(phone_no, msg);
var key = this.vcodePrev + phone_no; console.log(rs);
var vcode = await this.redisClient.get(key + "t");
if (!vcode) {
vcode = isTest ? "123123" : await this.getVCode();
await this.redisClient.setWithEx(key, vcode, 5 * 60);
await this.redisClient.setWithEx(key + "t", vcode, 60);
var msg = "您的验证码为" + vcode + ", (切勿将验证码告知别人, 请在5分钟内输入完成验证, 如有问题请联系客服。)";
if (!isTest) {
// var rs = await this.smsClient.sendMsg(phone_no, msg);
data = {
"templateName": obj.templateName, // 模板类型 loginTemplate(登陆) authenticationTemplate(验证) smsTemplate(短信通知)
"phoneNumbers": phone_no, // 手机号
"code":vcode, // 模板参数 默认字段 如果是短信通知模板,则请勿传值
}
_result = await this.msSve.SendSms(data);
}
} }
} }
return _result; return system.getResultSuccess("发送成功");
} catch (error) { } catch (error) {
return system.getResultFail(500, "接口异常:" + error.message); return system.getResultFail(500, "接口异常:" + error.message);
} }
......
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