Commit e087d5ce by 宋毅

tn

parent 17334402
...@@ -8,6 +8,7 @@ class AccessAuthAPI extends APIBase { ...@@ -8,6 +8,7 @@ class AccessAuthAPI extends APIBase {
this.apitradeSvr = system.getObject("service.common.apitradeSve"); this.apitradeSvr = system.getObject("service.common.apitradeSve");
this.authUtils = system.getObject("util.businessManager.authUtils"); this.authUtils = system.getObject("util.businessManager.authUtils");
this.userSve = system.getObject("service.auth.userSve"); this.userSve = system.getObject("service.auth.userSve");
this.vCodeExTime = 120;//验证码缓存秒数
} }
/*查询注册用户的信息sys*/ /*查询注册用户的信息sys*/
async queryRegUser(pobj, query, req) { async queryRegUser(pobj, query, req) {
...@@ -47,7 +48,7 @@ class AccessAuthAPI extends APIBase { ...@@ -47,7 +48,7 @@ class AccessAuthAPI extends APIBase {
return system.getResultFail(system.redoFail, "操作过于频繁,请勿重复获取", system.redoFail); return system.getResultFail(system.redoFail, "操作过于频繁,请勿重复获取", system.redoFail);
} }
pobj.reqType = "otherVcode"; pobj.reqType = "otherVcode";
var vcodeResult = await this.cacheManager["VCodeCache"].cache(cacheKeyStr, pobj, 120, null); var vcodeResult = await this.cacheManager["VCodeCache"].cache(cacheKeyStr, pobj, this.vCodeExTime, null);
return system.getResult(vcodeResult); return system.getResult(vcodeResult);
} }
/** /**
...@@ -78,11 +79,13 @@ class AccessAuthAPI extends APIBase { ...@@ -78,11 +79,13 @@ class AccessAuthAPI extends APIBase {
if (tmplCode && tmplCode.indexOf("SMS_") < 0) { if (tmplCode && tmplCode.indexOf("SMS_") < 0) {
return system.getResult(null, "模版编码有误"); return system.getResult(null, "模版编码有误");
} }
var tmpReslut = await this.cacheManager["VCodeCache"].getCache(appkey + "_" + mobile); var cacheKeyStr = appkey + "_" + pobj.mobile;
var tmpReslut = await this.cacheManager["VCodeCache"].getCache(cacheKeyStr);
if (tmpReslut) { if (tmpReslut) {
return system.getResultFail(system.redoFail, "操作过于频繁,请勿重复获取", system.redoFail); return system.getResultFail(system.redoFail, "操作过于频繁,请勿重复获取", system.redoFail);
} }
var vcodeResult = await this.cacheManager["VCodeCache"].cache(appkey + "_" + mobile, tmplCode, 120, signName); pobj.reqType = "defaultOtherVcode";
var vcodeResult = await this.cacheManager["VCodeCache"].cache(cacheKeyStr, pobj, this.vCodeExTime, null);
return system.getResult(vcodeResult); return system.getResult(vcodeResult);
} }
/** /**
...@@ -97,11 +100,13 @@ class AccessAuthAPI extends APIBase { ...@@ -97,11 +100,13 @@ class AccessAuthAPI extends APIBase {
if (!mobile) { if (!mobile) {
return system.getResult(null, "电话号码不能为空."); return system.getResult(null, "电话号码不能为空.");
} }
var tmpReslut = await this.cacheManager["VCodeCache"].getCache(appkey + "_" + mobile); var cacheKeyStr = appkey + "_" + pobj.mobile;
var tmpReslut = await this.cacheManager["VCodeCache"].getCache(cacheKeyStr);
if (tmpReslut) { if (tmpReslut) {
return system.getResultFail(system.redoFail, "操作过于频繁,请勿重复获取", system.redoFail); return system.getResultFail(system.redoFail, "操作过于频繁,请勿重复获取", system.redoFail);
} }
var vcodeResult = this.cacheManager["VCodeCache"].cache(appkey + "_" + mobile, null, 120); pobj.reqType = "defaultVcode";
var vcodeResult = this.cacheManager["VCodeCache"].cache(cacheKeyStr, pobj, this.vCodeExTime, null);
return system.getResult(vcodeResult); return system.getResult(vcodeResult);
} }
async authAccessKey(pobj, query, req) { async authAccessKey(pobj, query, req) {
...@@ -276,7 +281,8 @@ class AccessAuthAPI extends APIBase { ...@@ -276,7 +281,8 @@ class AccessAuthAPI extends APIBase {
if (!pobj.openid) { if (!pobj.openid) {
return system.getResult(null, "openid不能未空."); return system.getResult(null, "openid不能未空.");
} }
var cacheCode = await this.cacheManager["VCodeCache"].cache(appkey + "_" + pobj.mobile, null); var cacheKeyStr = appkey + "_" + pobj.mobile;
var cacheCode = await this.cacheManager["VCodeCache"].getCache(cacheKeyStr);
if (!cacheCode || pobj.vcode != cacheCode.vcode) { if (!cacheCode || pobj.vcode != cacheCode.vcode) {
return system.getResultFail(system.verifyVCodeFail, "验证码校验不成功,请重新获取验证码验证.", system.verifyVCodeFail); return system.getResultFail(system.verifyVCodeFail, "验证码校验不成功,请重新获取验证码验证.", system.verifyVCodeFail);
} }
...@@ -394,7 +400,7 @@ class AccessAuthAPI extends APIBase { ...@@ -394,7 +400,7 @@ class AccessAuthAPI extends APIBase {
return system.getResult(null, "新密码不能未空."); return system.getResult(null, "新密码不能未空.");
} }
var cacheKeyStr = appkey + "_" + pobj.mobile; var cacheKeyStr = appkey + "_" + pobj.mobile;
var cacheCode = await this.cacheManager["VCodeCache"].cache(cacheKeyStr, null); var cacheCode = await this.cacheManager["VCodeCache"].getCache(cacheKeyStr);
if (!cacheCode || pobj.vcode != cacheCode.vcode) { if (!cacheCode || pobj.vcode != cacheCode.vcode) {
return system.getResultFail(-1, "验证码校验不成功,请重新获取验证码验证." + pobj.vcode + "--" + cacheCode.vcode, system.verifyVCodeFail); return system.getResultFail(-1, "验证码校验不成功,请重新获取验证码验证." + pobj.vcode + "--" + cacheCode.vcode, system.verifyVCodeFail);
} }
......
...@@ -17,29 +17,24 @@ class VCodeCache extends CacheBase { ...@@ -17,29 +17,24 @@ class VCodeCache extends CacheBase {
return "g_vcode:appkey_" return "g_vcode:appkey_"
} }
async buildCacheVal(cachekey, inputkey, val, ex, ...items) { async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
//【XXX】您的验证码是:602639(5分钟内有效),工作人员不会索取,请勿泄露。-------描述在模板中配置
var pobj = val; var pobj = val;
var vcode = await this.smsUtil.getUidStr(6, 10); var vcode = await this.smsUtil.getUidStr(6, 10);
if (!pobj) { if (pobj && pobj.reqType) {
//inputkey采用appkey_mobile的形式 switch (pobj.reqType) {
var mobile = inputkey.split("_")[1]; case "defaultVcode":
var tmplCode = val; this.smsUtil.sendMsg(pobj.mobile, vcode);
var signName = items ? items[0] : ""; break;
// var content=tmpl.replace(/\|vcode\|/g,vcode); case "defaultOtherVcode":
//this.smsUtil.sendMsg(mobile,content); this.smsUtil.aliSendMsg(pobj.mobile, pobj.tmplCode, pobj.signName, JSON.stringify({ code: vcode }));
if (!tmplCode && !signName) { break;
this.smsUtil.sendMsg(mobile, vcode); case "otherVcode":
} //tmplCode为发送短信编码,需在阿里开通,signName为短信头描述信息,二者没有传递则用默认的发送验证码 this.smsUtil.aliOtherSendMsg(pobj.mobile, pobj.accessKeyId, pobj.accessKeySecret, pobj.tmplCode,
else { pobj.signName, JSON.stringify({ code: vcode }));
this.smsUtil.aliSendMsg(mobile, tmplCode, signName, JSON.stringify({ code: vcode })); break;
default:
break;
} }
return JSON.stringify({ vcode: vcode });
}
if (pobj.reqType == "otherVcode") {
//【XXX】您的验证码是:602639(5分钟内有效),工作人员不会索取,请勿泄露。-------描述在模板中配置
pobj.msgContent = vcode;
this.smsUtil.aliOtherSendMsg(pobj.mobile, pobj.accessKeyId, pobj.accessKeySecret, pobj.tmplCode,
pobj.signName, JSON.stringify({ code: vcode }));
} }
return JSON.stringify({ vcode: vcode }); return JSON.stringify({ vcode: vcode });
} }
......
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