Commit c10dfeb8 by 宋毅

tj

parent 1df5a8a4
...@@ -16,6 +16,41 @@ class AccessAuthAPI extends APIBase { ...@@ -16,6 +16,41 @@ class AccessAuthAPI extends APIBase {
return system.getResult(userList); return system.getResult(userList);
} }
/** /**
* 发送短信---用于有自己的key 和 密钥
* @param {*} pobj {mobile为要发送的手机号,tmplCode为发送短信编码,需在阿里开通,signName为短信头描述信息}
* @param {*} query
* @param {*} req
*/
async fetchOtherVCode(pobj, query, req) {
var appkey = req.app.appkey;
if (!pobj.mobile) {
return system.getResult(null, "电话号码不能为空.");
}
if (!pobj.tmplCode) {
return system.getResult(null, "模版编码不能为空.");
}
if (!pobj.signName) {
return system.getResult(null, "短信签名不能为空.");
}
if (pobj.tmplCode && pobj.tmplCode.indexOf("SMS_") < 0) {
return system.getResult(null, "模版编码有误");
}
if (!pobj.accessKeyId) {
return system.getResult(null, "模版accessKeyId不能为空.");
}
if (!pobj.accessKeySecret) {
return system.getResult(null, "模版accessKeySecret不能为空.");
}
var cacheKeyStr = appkey + "_" + pobj.mobile;
var tmpReslut = await this.cacheManager["VCodeCache"].getCache(cacheKeyStr);
if (tmpReslut) {
return system.getResultFail(system.redoFail, "操作过于频繁,请勿重复获取", system.redoFail);
}
pobj.reqType = "otherVcode";
var vcodeResult = await this.cacheManager["VCodeCache"].cache(cacheKeyStr, pobj, 120, null);
return system.getResult(vcodeResult);
}
/**
* 发送短信 * 发送短信
* @param {*} pobj {mobile为要发送的手机号,tmplCode为发送短信编码,需在阿里开通,signName为短信头描述信息} * @param {*} pobj {mobile为要发送的手机号,tmplCode为发送短信编码,需在阿里开通,signName为短信头描述信息}
* @param {*} query * @param {*} query
...@@ -45,7 +80,7 @@ class AccessAuthAPI extends APIBase { ...@@ -45,7 +80,7 @@ class AccessAuthAPI extends APIBase {
} }
var tmpReslut = await this.cacheManager["VCodeCache"].getCache(appkey + "_" + mobile); var tmpReslut = await this.cacheManager["VCodeCache"].getCache(appkey + "_" + mobile);
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); var vcodeResult = await this.cacheManager["VCodeCache"].cache(appkey + "_" + mobile, tmplCode, 120, signName);
return system.getResult(vcodeResult); return system.getResult(vcodeResult);
...@@ -64,7 +99,7 @@ class AccessAuthAPI extends APIBase { ...@@ -64,7 +99,7 @@ class AccessAuthAPI extends APIBase {
} }
var tmpReslut = await this.cacheManager["VCodeCache"].getCache(appkey + "_" + mobile); var tmpReslut = await this.cacheManager["VCodeCache"].getCache(appkey + "_" + mobile);
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); var vcodeResult = this.cacheManager["VCodeCache"].cache(appkey + "_" + mobile, null, 120);
return system.getResult(vcodeResult); return system.getResult(vcodeResult);
...@@ -358,12 +393,14 @@ class AccessAuthAPI extends APIBase { ...@@ -358,12 +393,14 @@ class AccessAuthAPI extends APIBase {
if (!pobj.newPwd) { if (!pobj.newPwd) {
return system.getResult(null, "新密码不能未空."); return system.getResult(null, "新密码不能未空.");
} }
var cacheCode = await this.cacheManager["VCodeCache"].cache(appkey + "_" + pobj.mobile, null); var cacheKeyStr = appkey + "_" + pobj.mobile;
var cacheCode = await this.cacheManager["VCodeCache"].cache(cacheKeyStr, null);
if (!cacheCode || pobj.vcode != cacheCode.vcode) { if (!cacheCode || pobj.vcode != cacheCode.vcode) {
return system.getResultFail(-1, "验证码校验不成功,请重新获取验证码验证.", system.verifyVCodeFail); return system.getResultFail(-1, "验证码校验不成功,请重新获取验证码验证.", system.verifyVCodeFail);
} }
//按照appid和电话查询出要修改的用户 //按照appid和电话查询出要修改的用户
var ruser = await this.userSve.modiPasswordByMobile(appid, pobj.mobile, pobj.newPwd); var ruser = await this.userSve.modiPasswordByMobile(appid, pobj.mobile, pobj.newPwd);
this.cacheManager["VCodeCache"].invalidate(cacheKeyStr);//清除验证码缓存
return system.getResult(ruser); return system.getResult(ruser);
} }
/** /**
...@@ -397,7 +434,8 @@ class AccessAuthAPI extends APIBase { ...@@ -397,7 +434,8 @@ class AccessAuthAPI extends APIBase {
if (!pobj.vcode) { if (!pobj.vcode) {
return system.getResult(null, "验证码不能未空."); return system.getResult(null, "验证码不能未空.");
} }
var cacheCode = await this.cacheManager["VCodeCache"].cache(appkey + "_" + pobj.mobile, null); var cacheKeyStr = appkey + "_" + pobj.mobile;
var cacheCode = await this.cacheManager["VCodeCache"].cache(cacheKeyStr, null);
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);
} }
...@@ -419,6 +457,7 @@ class AccessAuthAPI extends APIBase { ...@@ -419,6 +457,7 @@ class AccessAuthAPI extends APIBase {
var opencode = super.getUUID(); var opencode = super.getUUID();
var authUrl = req.app.authUrl + "?opencode=" + opencode; var authUrl = req.app.authUrl + "?opencode=" + opencode;
await this.cacheManager["OpenCodeCache"].cache(opencode, ruser, 120); await this.cacheManager["OpenCodeCache"].cache(opencode, ruser, 120);
this.cacheManager["VCodeCache"].invalidate(cacheKeyStr);//清除验证码缓存
return system.getResultSuccess({ auth_url: authUrl, opencode: opencode }); return system.getResultSuccess({ auth_url: authUrl, opencode: opencode });
} }
......
...@@ -17,11 +17,19 @@ class VCodeCache extends CacheBase { ...@@ -17,11 +17,19 @@ 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) {
var pobj = val;
var vcode = await this.smsUtil.getUidStr(6, 10);
if (pobj.reqType && 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 }));
}
else {
//inputkey采用appkey_mobile的形式 //inputkey采用appkey_mobile的形式
var mobile = inputkey.split("_")[1]; var mobile = inputkey.split("_")[1];
var tmplCode = val; var tmplCode = val;
var signName = items ? items[0] : ""; var signName = items ? items[0] : "";
var vcode = await this.smsUtil.getUidStr(6, 10);
// var content=tmpl.replace(/\|vcode\|/g,vcode); // var content=tmpl.replace(/\|vcode\|/g,vcode);
//this.smsUtil.sendMsg(mobile,content); //this.smsUtil.sendMsg(mobile,content);
if (!tmplCode && !signName) { if (!tmplCode && !signName) {
...@@ -30,6 +38,7 @@ class VCodeCache extends CacheBase { ...@@ -30,6 +38,7 @@ class VCodeCache extends CacheBase {
else { else {
this.smsUtil.aliSendMsg(mobile, tmplCode, signName, JSON.stringify({ code: vcode })); this.smsUtil.aliSendMsg(mobile, tmplCode, signName, JSON.stringify({ code: vcode }));
} }
}
return JSON.stringify({ vcode: vcode }); return JSON.stringify({ vcode: vcode });
} }
} }
......
const system=require("../system"); const system = require("../system");
const Core = require('@alicloud/pop-core'); const Core = require('@alicloud/pop-core');
class SmsClient{ class SmsClient {
constructor(){ constructor() {
this.smsTeml="http://123.57.156.109:4103/api/Send"; this.smsTeml = "http://123.57.156.109:4103/api/Send";
this.restClient=system.getObject("util.restClient"); this.restClient = system.getObject("util.restClient");
this.aliclient=new Core({ this.aliclient = new Core({
accessKeyId: 'LTAI4FtNp3wcqFzaADvo1WtZ', accessKeyId: 'LTAI4FtNp3wcqFzaADvo1WtZ',
accessKeySecret: 'VBKn1Anx4UmMF0LKNz7PVaCFG1phcg', accessKeySecret: 'VBKn1Anx4UmMF0LKNz7PVaCFG1phcg',
endpoint: 'https://dysmsapi.aliyuncs.com', endpoint: 'https://dysmsapi.aliyuncs.com',
...@@ -13,7 +13,7 @@ class SmsClient{ ...@@ -13,7 +13,7 @@ class SmsClient{
} }
async aliSendMsg(to,tmplcode,signName,jsonContent){ async aliSendMsg(to, tmplcode, signName, jsonContent) {
var params = { var params = {
"RegionId": "default", "RegionId": "default",
"PhoneNumbers": to, "PhoneNumbers": to,
...@@ -31,13 +31,38 @@ class SmsClient{ ...@@ -31,13 +31,38 @@ class SmsClient{
}) })
} }
async sendMsg(to,content){ async aliOtherSendMsg(to, accessKeyId, accessKeySecret, tmplcode, signName, jsonContent) {
var txtObj ={ var params = {
"appId":8, "RegionId": "default",
"mobilePhone":to, "PhoneNumbers": to,
"content":content "SignName": signName,
"TemplateCode": tmplcode,
"TemplateParam": jsonContent
};
var requestOption = {
method: 'POST'
};
var otherAliclient = new Core({
accessKeyId: accessKeyId,
accessKeySecret: accessKeySecret,
endpoint: 'https://dysmsapi.aliyuncs.com',
apiVersion: '2017-05-25'
});
otherAliclient.request('SendSms', params, requestOption).then((result) => {
console.log(JSON.stringify(result));
}, (ex) => {
console.log(ex);
});
}
async sendMsg(to, content) {
var txtObj = {
"appId": 8,
"mobilePhone": to,
"content": content
} }
return this.restClient.execPost(txtObj,this.smsTeml); return this.restClient.execPost(txtObj, this.smsTeml);
} }
async getUidStr(len, radix) { async getUidStr(len, radix) {
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
...@@ -60,7 +85,7 @@ class SmsClient{ ...@@ -60,7 +85,7 @@ class SmsClient{
} }
} }
module.exports=SmsClient; module.exports = SmsClient;
// var sms=new SmsClient(); // var sms=new SmsClient();
// sms.aliSendMsg("13381139519","SMS_173946419","iboss",JSON.stringify({code:"hello"})); // sms.aliSendMsg("13381139519","SMS_173946419","iboss",JSON.stringify({code:"hello"}));
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