Commit d854753d by 宋毅

tj

parent 35878bad
...@@ -3,14 +3,14 @@ var system = require("../../../system"); ...@@ -3,14 +3,14 @@ var system = require("../../../system");
const logCtl = system.getObject("service.common.oplogSve"); const logCtl = system.getObject("service.common.oplogSve");
class opLog extends APIBase { class opLog extends APIBase {
constructor() { constructor() {
super(); super();
} }
async info(pobj, qobj, req) { async info(pobj, qobj, req) {
this.logCtl.info(pobj); this.logCtl.info(pobj);
} }
async error(pobj, qobj, req) { async error(pobj, qobj, req) {
this.logCtl.error(pobj); this.logCtl.error(pobj);
} }
} }
module.exports = opLog; module.exports = opLog;
\ No newline at end of file
...@@ -25,10 +25,7 @@ class AccessAuthAPI extends APIBase { ...@@ -25,10 +25,7 @@ class AccessAuthAPI extends APIBase {
var itemResult = await this.appmobilemsgSve.getItemByUappId(pobj); var itemResult = await this.appmobilemsgSve.getItemByUappId(pobj);
var result = system.getResult(null, "get msg error"); var result = system.getResult(null, "get msg error");
if (itemResult.status != 0) { if (itemResult.status != 0) {
result = await this.opPlatformUtils.fetchDefaultVCode(pobj.actionBody.mobile, pobj.appInfo.uapp_key, pobj.appInfo.uapp_secret); result = await this.opPlatformUtils.fetchDefaultVCode(pobj.actionBody.mobile, pobj.appInfo.uapp_key);
console.log("--------------fetchDefaultVCode result start")
console.log(result);
console.log("--------------fetchDefaultVCode result end")
return result; return result;
} }
var param = { var param = {
...@@ -38,7 +35,7 @@ class AccessAuthAPI extends APIBase { ...@@ -38,7 +35,7 @@ class AccessAuthAPI extends APIBase {
accessKeyId: itemResult.data.access_key_id, accessKeyId: itemResult.data.access_key_id,
accessKeySecret: itemResult.data.access_key_secret accessKeySecret: itemResult.data.access_key_secret
} }
result = await this.opPlatformUtils.fetchOtherVCode(param, pobj.appInfo.uapp_key, pobj.appInfo.uapp_secret); result = await this.opPlatformUtils.fetchOtherVCode(param, pobj.appInfo.uapp_key);
return result; return result;
} }
......
...@@ -7,6 +7,14 @@ class CacheBase { ...@@ -7,6 +7,14 @@ class CacheBase {
this.prefix = this.prefix(); this.prefix = this.prefix();
this.cacheCacheKeyPrefix = "s_sadd_appkeys:" + settings.appKey + "_cachekey"; this.cacheCacheKeyPrefix = "s_sadd_appkeys:" + settings.appKey + "_cachekey";
this.isdebug = this.isdebug(); this.isdebug = this.isdebug();
this.md5 = require("MD5");
}
async getEncryptStr(str) {
if (!str) {
throw new Error("字符串不能为空");
}
var md5 = this.md5(str + "_" + settings.salt);
return md5.toString().toLowerCase();
} }
isdebug() { isdebug() {
return false; return false;
......
...@@ -14,6 +14,7 @@ class AppTokenByHostsCache extends CacheBase { ...@@ -14,6 +14,7 @@ class AppTokenByHostsCache extends CacheBase {
prefix() { prefix() {
return settings.cacheprefix + "_accesskey:"; return settings.cacheprefix + "_accesskey:";
} }
//优化掉从平台中获取应用信息--sy-2020-10-21
async buildCacheVal(cachekey, inputkey, val, ex, ...items) { async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var actionBody = val; var actionBody = val;
if (!actionBody) { if (!actionBody) {
...@@ -29,20 +30,20 @@ class AppTokenByHostsCache extends CacheBase { ...@@ -29,20 +30,20 @@ class AppTokenByHostsCache extends CacheBase {
if (!item) { if (!item) {
return system.getResult(null, "app_hosts to data is empty !"); return system.getResult(null, "app_hosts to data is empty !");
} }
if (!item.uapp_key || !item.uapp_secret) {
return system.getResult(null, "uapp_key or uapp_secret can not be empty !");
}
if (item.is_enabled != 1) { if (item.is_enabled != 1) {
return system.getResult(null, "app_hosts to item is Disable !"); return system.getResult(null, "app_hosts to item is Disable !");
} }
var result = await this.opPlatformUtils.getReqApiAccessKey(item.uapp_key, item.uapp_secret); // if (!item.uapp_key || !item.uapp_secret) {
if (!result) { // return system.getResult(null, "uapp_key or uapp_secret can not be empty !");
return system.getResult(null, "platform to data is empty !"); // }
} // var result = await this.opPlatformUtils.getReqApiAccessKey(item.uapp_key, item.uapp_secret);
if (result.status != 0) { // if (!result) {
return result; // return system.getResult(null, "platform to data is empty !");
} // }
item.token = result.data.accessKey; // if (result.status != 0) {
// return result;
// }
// item.token = result.data.accessKey;
return system.getResultSuccess(item); return system.getResultSuccess(item);
} }
} }
......
...@@ -13,24 +13,24 @@ class AppUserPinByLoginPwdCache extends CacheBase { ...@@ -13,24 +13,24 @@ class AppUserPinByLoginPwdCache extends CacheBase {
prefix() { prefix() {
return settings.cacheprefix + "_userPin:"; return settings.cacheprefix + "_userPin:";
} }
//优化掉从平台中获取应用信息--sy-2020-10-21
async buildCacheVal(cachekey, inputkey, val, ex, ...items) { async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var actionBody = val.actionBody; const actionBody = val.actionBody;
var appInfo = val.appInfo; const appInfo = val.appInfo;
var uUserName = actionBody.userName;//uUserName const uUserName = actionBody.userName;//uUserName
var uPassword = actionBody.password;//uPassword const password = await this.getEncryptStr(actionBody.password);//uPassword
var uUserInfo = await this.opPlatformUtils.login(uUserName, uPassword, // var uUserInfo = await this.opPlatformUtils.login(uUserName, uPassword,
appInfo.uapp_key, appInfo.uapp_secret); // appInfo.uapp_key, appInfo.uapp_secret);
if (uUserInfo.status != 0) { // if (uUserInfo.status != 0) {
return uUserInfo; // return uUserInfo;
}//值为2010为用户名或密码错误 // }//值为2010为用户名或密码错误
var userInfo = await this.appuserDao.getItemByChannelUserId(actionBody.userName, appInfo.uapp_id); var userInfo = await this.appuserDao.getItemByPwd(uUserName, password, appInfo.uapp_id);
if (!userInfo) { if (!userInfo) {
return system.getResult(null, "user to item is empty !"); return system.getResult(null, "user to item is empty !");
} }
if (userInfo.is_enabled != 1) { if (userInfo.is_enabled != 1) {
return system.getResult(null, "user to item is Disable !"); return system.getResult(null, "user to item is Disable !");
} }
userInfo.userpin = actionBody.userpin;
return system.getResultSuccess(userInfo); return system.getResultSuccess(userInfo);
} }
} }
......
...@@ -14,31 +14,27 @@ class AppUserPinByLoginVcodeCache extends CacheBase { ...@@ -14,31 +14,27 @@ class AppUserPinByLoginVcodeCache extends CacheBase {
return settings.cacheprefix + "_userPin:"; return settings.cacheprefix + "_userPin:";
} }
async buildCacheVal(cachekey, inputkey, val, ex, ...items) { async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var actionBody = val.actionBody; let actionBody = val.actionBody;
var appInfo = val.appInfo; let appInfo = val.appInfo;
var uUserInfo = await this.opPlatformUtils.loginByVCode(actionBody.mobile, actionBody.vcode, actionBody.password, let userInfo = await this.appuserDao.getItemByChannelUserId(actionBody.mobile, appInfo.uapp_id);
appInfo.uapp_key, appInfo.uapp_secret);
if (uUserInfo.status != 0) {
return uUserInfo;
}//2030验证码校验不成功 或 注册失败
var userInfo = await this.appuserDao.getItemByChannelUserId(actionBody.mobile, appInfo.uapp_id);
if (userInfo) { if (userInfo) {
if (userInfo.is_enabled != 1) { if (userInfo.is_enabled != 1) {
return system.getResult(null, "user to item is Disable !"); return system.getResult(null, "用户未启用");
} }
if (actionBody.reqType == "reg") { if (actionBody.reqType === "reg") {
return system.getResultFail(system.existUserRegFail, "已经存在此用户,注册失败"); return system.getResult(null, "已经存在此用户,注册失败");
} }
userInfo.userpin = actionBody.userpin;
return system.getResultSuccess(userInfo); return system.getResultSuccess(userInfo);
} }
var params = {
const uPassword = await this.getEncryptStr((actionBody.password || actionBody.mobile));//uPassword
let params = {
uapp_id: appInfo.uapp_id, uapp_id: appInfo.uapp_id,
channel_userid: actionBody.mobile || "", channel_userid: actionBody.mobile || "",
channel_username: actionBody.mobile || "", channel_username: actionBody.mobile || "",
channel_nickname: actionBody.nickName || "", channel_nickname: actionBody.nickName || "",
mobile: actionBody.mobile || "", mobile: actionBody.mobile || "",
password: uPassword,
org_name: actionBody.orgName || "", org_name: actionBody.orgName || "",
org_path: actionBody.orgPath || "", org_path: actionBody.orgPath || "",
is_enabled: 1, is_enabled: 1,
...@@ -46,8 +42,8 @@ class AppUserPinByLoginVcodeCache extends CacheBase { ...@@ -46,8 +42,8 @@ class AppUserPinByLoginVcodeCache extends CacheBase {
last_login_time: new Date() last_login_time: new Date()
}; };
userInfo = await this.appuserDao.create(params); userInfo = await this.appuserDao.create(params);
userInfo.userpin = actionBody.userpin; params.password = "";
return system.getResultSuccess(userInfo); return system.getResultSuccess(params);
} }
} }
module.exports = AppUserPinByLoginVcodeCache; module.exports = AppUserPinByLoginVcodeCache;
const CacheBase = require("../cache.base");
const system = require("../../system");
const settings = require("../../../config/settings");
//缓存首次登录的赠送的宝币数量
class VCodeCache extends CacheBase {
constructor() {
super();
this.smsUtil = system.getObject("util.smsClient");
}
// isdebug() {
// return settings.env == "dev";
// }
desc() {
return "缓存给手机发送的验证码60妙";
}
prefix() {
return settings.cacheprefix + "g_vcode:appkey_";
}
async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
//【XXX】您的验证码是:602639(5分钟内有效),工作人员不会索取,请勿泄露。-------描述在模板中配置
var params = val;
var vcode = await this.smsUtil.getUidStr(6, 10);
if (params && params.reqType) {
switch (params.reqType) {
case "defaultVcode":
const msg = "您的验证码:" + vcode + ",请在60秒输入完成验证,若非本人操作,请勿泄露"
this.smsUtil.sendDefaultVcodeMsg(params.mobile, msg);
break;
case "defaultOtherVcode"://暂时没有用到
this.smsUtil.aliSendMsg(params.mobile, params.tmplCode, params.signName, JSON.stringify({ code: vcode }));
break;
case "otherVcode":
this.smsUtil.aliOtherSendMsg(params.mobile, params.accessKeyId, params.accessKeySecret, params.tmplCode,
params.signName, JSON.stringify({ code: vcode }));
break;
default:
break;
}
}
return system.getResultSuccess({ vcode: vcode });
}
}
module.exports = VCodeCache;
...@@ -27,5 +27,35 @@ class AppuserDao extends Dao { ...@@ -27,5 +27,35 @@ class AppuserDao extends Dao {
raw: true raw: true
}); });
} }
/**
* 通过密码进行登录
* @param {*} channel_userid
* @param {*} password
* @param {*} uapp_id
*/
async getItemByPwd(channel_userid, password, uapp_id) {
return this.model.findOne({
where: {
channel_userid: channel_userid,
password: password,
uapp_id: uapp_id
},
attributes: ["id",
"uapp_id",
"channel_userid",
"channel_username",
"channel_nickname",
"open_id",
"head_url",
"mobile",
"org_name",
"org_path",
"email",
"is_admin",
"is_super",
"is_enabled"],
raw: true
});
}
} }
module.exports = AppuserDao; module.exports = AppuserDao;
...@@ -13,6 +13,7 @@ module.exports = (db, DataTypes) => { ...@@ -13,6 +13,7 @@ module.exports = (db, DataTypes) => {
org_name: DataTypes.STRING(255), org_name: DataTypes.STRING(255),
org_path: DataTypes.STRING(255), org_path: DataTypes.STRING(255),
email: DataTypes.STRING(50), email: DataTypes.STRING(50),
password: DataTypes.STRING(255),
is_admin: { is_admin: {
type: DataTypes.BOOLEAN, type: DataTypes.BOOLEAN,
defaultValue: false, defaultValue: false,
...@@ -27,19 +28,19 @@ module.exports = (db, DataTypes) => { ...@@ -27,19 +28,19 @@ module.exports = (db, DataTypes) => {
}, },
last_login_time: DataTypes.DATE, last_login_time: DataTypes.DATE,
}, { }, {
paranoid: false,//假的删除 paranoid: false,//假的删除
underscored: true, underscored: true,
version: true, version: true,
freezeTableName: true, freezeTableName: true,
timestamps: true, timestamps: true,
updatedAt: false, updatedAt: false,
//freezeTableName: true, //freezeTableName: true,
// define the table's name // define the table's name
tableName: 'p_app_user', tableName: 'p_app_user',
validate: { validate: {
}, },
indexes: [ indexes: [
] ]
}); });
} }
...@@ -294,7 +294,7 @@ Date.prototype.Format = function (fmt) { //author: meizz ...@@ -294,7 +294,7 @@ Date.prototype.Format = function (fmt) { //author: meizz
System.exTime = 4 * 3600;//缓存过期时间,4小时 System.exTime = 4 * 3600;//缓存过期时间,4小时
System.shortExTime = 300;//300 System.shortExTime = 300;//缓存过期时间,5分钟
//缓存失效 //缓存失效
System.cacheInvalidation = -88; System.cacheInvalidation = -88;
......
...@@ -14,6 +14,8 @@ class OpPlatformUtils { ...@@ -14,6 +14,8 @@ class OpPlatformUtils {
this.registerUrl = settings.paasUrl() + "api/auth/accessAuth/register"; this.registerUrl = settings.paasUrl() + "api/auth/accessAuth/register";
this.loginByVCodeUrl = settings.paasUrl() + "api/auth/accessAuth/loginByVCode"; this.loginByVCodeUrl = settings.paasUrl() + "api/auth/accessAuth/loginByVCode";
this.modiPasswordByMobileUrl = settings.paasUrl() + "api/auth/accessAuth/modiPasswordByMobile"; this.modiPasswordByMobileUrl = settings.paasUrl() + "api/auth/accessAuth/modiPasswordByMobile";
this.vCodeExTime = 120;//验证码缓存秒数
this.appuserDao = system.getObject("db.dbapp.appuserDao");
} }
getUserPinKey(userpin) { getUserPinKey(userpin) {
return settings.cacheprefix + "_userPin:" + userpin; return settings.cacheprefix + "_userPin:" + userpin;
...@@ -79,7 +81,7 @@ class OpPlatformUtils { ...@@ -79,7 +81,7 @@ class OpPlatformUtils {
return system.getResultSuccess(restResult.data); return system.getResultSuccess(restResult.data);
} }
/** /**
* 通过自定义模板获取手机模板短信 * 合作方通过自定义模板获取手机模板短信
* @param {*} param { * @param {*} param {
mobile: actionBody.mobile, mobile: actionBody.mobile,
tmplCode: "SMS_151685065", tmplCode: "SMS_151685065",
...@@ -88,45 +90,55 @@ class OpPlatformUtils { ...@@ -88,45 +90,55 @@ class OpPlatformUtils {
accessKeySecret: "Z3wUHmZ0hnQst6uaTY3GzOYVoWwxb9" accessKeySecret: "Z3wUHmZ0hnQst6uaTY3GzOYVoWwxb9"
} }
* @param {*} appKey * @param {*} appKey
* @param {*} secret
*/ */
async fetchOtherVCode(param, appKey, secret) { async fetchOtherVCode(param, appKey) {
var reqApiAccessKey = await this.getReqApiAccessKey(appKey, secret); if (!param.mobile) {
if (reqApiAccessKey.status != 0) { return system.getResult(null, "电话号码不能为空.");
return reqApiAccessKey;
} }
//按照访问token if (!param.tmplCode) {
var restResult = await this.restClient.execPostWithAK( return system.getResult(null, "模版编码不能为空.");
param,
this.fetchOtherVCodeUrl, reqApiAccessKey.data.accessKey);
if (restResult.status != 0 || !restResult.data) {
return system.getResult(null, restResult.msg);
} }
return system.getResultSuccess(); if (!param.signName) {
return system.getResult(null, "短信签名不能为空.");
}
if (param.tmplCode && param.tmplCode.indexOf("SMS_") < 0) {
return system.getResult(null, "模版编码有误");
}
if (!param.accessKeyId) {
return system.getResult(null, "模版accessKeyId不能为空.");
}
if (!param.accessKeySecret) {
return system.getResult(null, "模版accessKeySecret不能为空.");
}
var cacheManager = system.getObject("db.common.cacheManager");
const cacheKeyStr = appKey + "_" + param.mobile;
const tmpReslut = await cacheManager["VCodeCache"].getCache(cacheKeyStr);
if (tmpReslut.status != -88) {
return system.getResult(null, "操作过于频繁,请勿重复获取");
}
param.reqType = "otherVcode";
const vcodeResult = await cacheManager["VCodeCache"].cache(cacheKeyStr, param, this.vCodeExTime, null);
return system.getResult(vcodeResult);
} }
/** /**
* 获取默认的手机模板短信 * 获取默认的手机模板短信
* @param {*} mobile * @param {*} mobile
* @param {*} appKey * @param {*} appKey
* @param {*} secret
*/ */
async fetchDefaultVCode(mobile, appKey, secret) { async fetchDefaultVCode(mobile, appkey) {
var reqApiAccessKey = await this.getReqApiAccessKey(appKey, secret); if (!mobile) {
if (reqApiAccessKey.status != 0) { return system.getResult(null, "电话号码不能为空.");
return reqApiAccessKey;
}
var param = { mobile: mobile }
//按照访问token
var restResult = await this.restClient.execPostWithAK(
param,
this.fetchDefaultVCodeUrl, reqApiAccessKey.data.accessKey);
if (restResult.status != 0 || !restResult.data) {
return system.getResult(null, restResult.msg);
} }
return system.getResultSuccess(restResult); var cacheManager = system.getObject("db.common.cacheManager");
const cacheKeyStr = appkey + "_" + mobile;
const tmpReslut = await cacheManager["VCodeCache"].getCache(cacheKeyStr);
if (tmpReslut.status != -88) {
return system.getResult(null, "操作过于频繁,请勿重复获取");
}
const param = { mobile: mobile, reqType: "defaultVcode" }
const vcodeResult = await cacheManager["VCodeCache"].cache(cacheKeyStr, param, this.vCodeExTime, null);
return system.getResult(vcodeResult);
} }
/** /**
* 创建用户信息 * 创建用户信息
...@@ -270,7 +282,7 @@ class OpPlatformUtils { ...@@ -270,7 +282,7 @@ class OpPlatformUtils {
return system.getResultSuccess(restResult.data); return system.getResultSuccess(restResult.data);
} }
async modiPasswordByMobile(mobile, vcode, newPwd, appKey, secret) { async modiPasswordByMobile(mobile, vcode, newPwd, appKey, secret) {//----暂时不用
var reqApiAccessKey = await this.getReqApiAccessKey(appKey, secret); var reqApiAccessKey = await this.getReqApiAccessKey(appKey, secret);
if (reqApiAccessKey.status != 0) { if (reqApiAccessKey.status != 0) {
return reqApiAccessKey; return reqApiAccessKey;
...@@ -291,7 +303,7 @@ class OpPlatformUtils { ...@@ -291,7 +303,7 @@ class OpPlatformUtils {
async getReqTokenByHosts(actionBody) { async getReqTokenByHosts(actionBody) {
var cacheManager = system.getObject("db.common.cacheManager"); var cacheManager = system.getObject("db.common.cacheManager");
var inputkey = actionBody.reqType == "hosts" ? actionBody.appHosts : actionBody.appkey; var inputkey = actionBody.reqType == "hosts" ? actionBody.appHosts : actionBody.appkey;
var result = await cacheManager["AppTokenByHostsCache"].cache(inputkey, actionBody, system.exTime); var result = await cacheManager["AppTokenByHostsCache"].cache(inputkey, actionBody, system.shortExTime);
return result; return result;
} }
...@@ -303,23 +315,23 @@ class OpPlatformUtils { ...@@ -303,23 +315,23 @@ class OpPlatformUtils {
var inputkey = pobj.appInfo.uapp_key + "_" + pobj.actionBody.channelUserId; var inputkey = pobj.appInfo.uapp_key + "_" + pobj.actionBody.channelUserId;
var cacheManager = system.getObject("db.common.cacheManager"); var cacheManager = system.getObject("db.common.cacheManager");
var result = await cacheManager["AppUserPinByUserNameCache"].getCache(inputkey); var result = await cacheManager["AppUserPinByUserNameCache"].getCache(inputkey);
if (result && result.status == 0) { // if (result && result.status == 0) {
if (result.data.userpin) { // if (result.data.userpin) {
// 2020 0723 lin修改 登录并重新设置过期时间 // // 2020 0723 lin修改 登录并重新设置过期时间
var inputkey = this.getUserPinKey(inputkey); // var inputkey = this.getUserPinKey(inputkey);
var userpinKey = this.getUserPinKey(result.data.userpin); // var userpinKey = this.getUserPinKey(result.data.userpin);
await this.redisClient.setExpire(inputkey, system.exTime); // await this.redisClient.setExpire(inputkey, system.exTime);
await this.redisClient.setExpire(userpinKey, system.exTime); // await this.redisClient.setExpire(userpinKey, system.exTime);
return system.getResultFail(system.reDoLoginFail, "请勿重复处理", { userpin: result.data.userpin || "" }); // return system.getResultFail(system.reDoLoginFail, "请勿重复处理", { userpin: result.data.userpin || "" });
} else { // } else {
await this.clearLoginCache(inputkey); // await this.clearLoginCache(inputkey);
} // }
} // }
var result = await cacheManager["AppUserPinByUserNameCache"].cache(inputkey, pobj, system.exTime); var result = await cacheManager["AppUserPinByUserNameCache"].cache(inputkey, pobj, system.shortExTime);
if (result && result.status == 0) { // if (result && result.status == 0) {
var userpinKey = this.getUserPinKey(pobj.actionBody.userpin); // var userpinKey = this.getUserPinKey(pobj.actionBody.userpin);
this.redisClient.setWithEx(userpinKey, JSON.stringify(result), system.exTime); // this.redisClient.setWithEx(userpinKey, JSON.stringify(result), system.exTime);
} // }
return result; return result;
} }
...@@ -334,10 +346,9 @@ class OpPlatformUtils { ...@@ -334,10 +346,9 @@ class OpPlatformUtils {
// if (result && result.status == 0) { // if (result && result.status == 0) {
// return system.getResultFail(system.reDoLoginFail, "请勿重复登录", { userpin: result.data.userpin || "" }); // return system.getResultFail(system.reDoLoginFail, "请勿重复登录", { userpin: result.data.userpin || "" });
// } // }
var result = await cacheManager["AppUserPinByLoginPwdCache"].cache(inputkey, pobj, system.exTime); var result = await cacheManager["AppUserPinByLoginPwdCache"].cache(inputkey, pobj, system.shortExTime);
if (result && result.status == 0) { if (!result || result.status != 0) {
var userpinKey = this.getUserPinKey(pobj.actionBody.userpin); return system.getResult(null, "用户名或密码错误");
this.redisClient.setWithEx(userpinKey, JSON.stringify(result), system.exTime);
} }
return result; return result;
} }
...@@ -346,8 +357,12 @@ class OpPlatformUtils { ...@@ -346,8 +357,12 @@ class OpPlatformUtils {
* @param {*} pobj pobj.actionBody:{mobile:XXX,vcode:XXX,reqType:"reg",password:XXX-reqType为reg时有此值} * @param {*} pobj pobj.actionBody:{mobile:XXX,vcode:XXX,reqType:"reg",password:XXX-reqType为reg时有此值}
*/ */
async getReqUserPinByLgoinVcode(pobj) { async getReqUserPinByLgoinVcode(pobj) {
var inputkey = pobj.appInfo.uapp_key + "_" + pobj.actionBody.mobile;
var cacheManager = system.getObject("db.common.cacheManager"); var cacheManager = system.getObject("db.common.cacheManager");
var inputkey = pobj.appInfo.uapp_key + "_" + pobj.actionBody.mobile;
var cacheCode = await this.cacheManager["VCodeCache"].getCache(inputkey);
if (!cacheCode || pobj.vcode != cacheCode.vcode) {
return system.getResultFail(system.verifyVCodeFail, "验证码校验不成功,请重新获取验证码验证.", system.verifyVCodeFail);
}
// if (pobj.actionBody.reqType != "reg") { // if (pobj.actionBody.reqType != "reg") {
// var result = await cacheManager["AppUserPinByLoginVcodeCache"].getCache(inputkey); // var result = await cacheManager["AppUserPinByLoginVcodeCache"].getCache(inputkey);
// if (result && result.status == 0) { // if (result && result.status == 0) {
...@@ -364,8 +379,15 @@ class OpPlatformUtils { ...@@ -364,8 +379,15 @@ class OpPlatformUtils {
} }
return result; return result;
} }
async getEncryptStr(str) {
if (!str) {
throw new Error("字符串不能为空");
}
var md5 = this.md5(str + "_" + settings.salt);
return md5.toString().toLowerCase();
}
/** /**
* 通过手机验证码修改用户密码 * 通过手机验证码修改用户密码,前端修改后要移除掉userpin让用户进行重新登录
* @param {*} pobj * @param {*} pobj
* @param {*} actionBody {mobile:XX,vcode:XXX,newPwd:XXX,userpin:XXXXX} * @param {*} actionBody {mobile:XX,vcode:XXX,newPwd:XXX,userpin:XXXXX}
*/ */
...@@ -382,11 +404,17 @@ class OpPlatformUtils { ...@@ -382,11 +404,17 @@ class OpPlatformUtils {
if (!pobj.appInfo) { if (!pobj.appInfo) {
return system.getResult(null, "pobj.appInfo can not be empty !"); return system.getResult(null, "pobj.appInfo can not be empty !");
} }
var acckapp = await this.modiPasswordByMobile(actionBody.mobile, actionBody.vcode, actionBody.newPwd, pobj.appInfo.uapp_key, pobj.appInfo.uapp_secret); var inputkey = pobj.appInfo.uapp_key + "_" + pobj.actionBody.mobile;
return acckapp; var cacheCode = await this.cacheManager["VCodeCache"].getCache(inputkey);
if (!cacheCode || pobj.vcode != cacheCode.vcode) {
return system.getResultFail(system.verifyVCodeFail, "验证码校验不成功,请重新获取验证码验证.", system.verifyVCodeFail);
}
const uPassword = await this.getEncryptStr(actionBody.newPwd);//uPassword
await this.appuserDao.updateByWhere({ password: uPassword }, { where: { channel_userid: mobile, uapp_id: pobj.appInfo.uapp_id } })
return system.getResultSuccess();
} }
/** /**
* 获取账户信息 * 获取账户信息---改版后废弃--20201026-sy
* @param {*} pobj pobj.actionBody:{userpin:XXX} * @param {*} pobj pobj.actionBody:{userpin:XXX}
*/ */
async getUserLoginInfo(pobj) { async getUserLoginInfo(pobj) {
......
const system=require("../system"); const system = require("../system");
class SmsClient{ const Core = require('@alicloud/pop-core');
constructor(){ class SmsClient {
this.smsTeml="http://123.57.156.109:4103/api/Send"; constructor() {
this.restClient=system.getObject("util.restClient"); this.smsTeml = "http://123.57.156.109:4103/api/Send";
this.restClient = system.getObject("util.restClient");
this.aliclient = new Core({
accessKeyId: 'LTAI4FtNp3wcqFzaADvo1WtZ',
accessKeySecret: 'VBKn1Anx4UmMF0LKNz7PVaCFG1phcg',
endpoint: 'https://dysmsapi.aliyuncs.com',
apiVersion: '2017-05-25'
});
}
/**
* 公司宝阿里云发送
* @param {*} mobile 手机号
* @param {*} tmplcode 模板编码
* @param {*} signName 短信头签名
* @param {*} jsonContent 内容
*/
async aliSendMsg(mobile, tmplcode, signName, jsonContent) {
var params = {
"RegionId": "default",
"PhoneNumbers": mobile,
"SignName": signName,
"TemplateCode": tmplcode,
"TemplateParam": jsonContent
} }
async sendMsg(to,content){ var requestOption = {
var txtObj ={ method: 'POST'
"appId":8, };
"mobilePhone":to, this.aliclient.request('SendSms', params, requestOption).then((result) => {
"content":content console.log(JSON.stringify(result));
}, (ex) => {
console.log(ex);
})
}
/**
* 合作方阿里云发送
* @param {*} mobile 手机号
* @param {*} accessKeyId 阿里云key
* @param {*} accessKeySecret 阿里云密钥
* @param {*} tmplcode 模板编码
* @param {*} signName 短信头签名
* @param {*} jsonContent 内容
*/
async aliOtherSendMsg(mobile, accessKeyId, accessKeySecret, tmplcode, signName, jsonContent) {
var params = {
"RegionId": "default",
"PhoneNumbers": mobile,
"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);
});
}
/**
* 公司宝默认的短信发送
* @param {*} mobile 手机号
* @param {*} content 内容
*/
async sendDefaultVcodeMsg(mobile, content) {
var txtObj = {
"appId": 8,
"mobilePhone": mobile,
"content": content
}
return this.restClient.execPost(txtObj, this.smsTeml);
}
async getUidStr(len, radix) {
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
var uuid = [], i;
radix = radix || chars.length;
if (len) {
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
} else {
var r;
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
uuid[14] = '4';
for (i = 0; i < 36; i++) {
if (!uuid[i]) {
r = 0 | Math.random() * 16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
}
} }
return this.restClient.execPost(txtObj,this.smsTeml);
} }
return uuid.join('');
}
} }
module.exports=SmsClient; module.exports = SmsClient;
// var sms=new SmsClient();
// sms.aliSendMsg("13381139519","SMS_173946419","iboss",JSON.stringify({code:"hello"}));
var path = require('path'); var path = require('path');
var ENVINPUT={ var ENVINPUT = {
DB_HOST:process.env.DB_HOST, DB_HOST: process.env.DB_HOST,
DB_PORT:process.env.DB_PORT, DB_PORT: process.env.DB_PORT,
DB_USER:process.env.DB_USER, DB_USER: process.env.DB_USER,
DB_PWD:process.env.DB_PWD, DB_PWD: process.env.DB_PWD,
DB_NAME:process.env.CENTER_APP_DB_NAME, DB_NAME: process.env.CENTER_APP_DB_NAME,
REDIS_HOST:process.env.REDIS_HOST, REDIS_HOST: process.env.REDIS_HOST,
REDIS_PORT:process.env.REDIS_PORT, REDIS_PORT: process.env.REDIS_PORT,
REDIS_PWD:process.env.REDIS_PWD, REDIS_PWD: process.env.REDIS_PWD,
REDIS_DB:process.env.CENTER_APP_REDIS_DB, REDIS_DB: process.env.CENTER_APP_REDIS_DB,
APP_ENV:process.env.APP_ENV?process.env.APP_ENV:"dev" APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "dev"
}; };
var settings = { var settings = {
env:ENVINPUT.APP_ENV, env: ENVINPUT.APP_ENV,
appKey: "201911061250", appKey: "201911061250",
secret: "f99d413b767f09b5dff0b3610366cc46", secret: "f99d413b767f09b5dff0b3610366cc46",
salt: "%iatpD1gcxz7iF#B", salt: "%iatpD1gcxz7iF#B",
...@@ -79,10 +79,10 @@ var settings = { ...@@ -79,10 +79,10 @@ var settings = {
return localsettings.redis; return localsettings.redis;
} else { } else {
return { return {
host:ENVINPUT.REDIS_HOST, host: ENVINPUT.REDIS_HOST,
port:ENVINPUT.REDIS_PORT, port: ENVINPUT.REDIS_PORT,
password:ENVINPUT.REDIS_PWD, password: ENVINPUT.REDIS_PWD,
db:ENVINPUT.REDIS_DB, db: ENVINPUT.REDIS_DB,
}; };
} }
}, },
...@@ -92,24 +92,24 @@ var settings = { ...@@ -92,24 +92,24 @@ var settings = {
return localsettings.database; return localsettings.database;
} else { } else {
return { return {
dbname : ENVINPUT.DB_NAME, dbname: ENVINPUT.DB_NAME,
user : ENVINPUT.DB_USER, user: ENVINPUT.DB_USER,
password : ENVINPUT.DB_PWD, password: ENVINPUT.DB_PWD,
config : { config: {
host: ENVINPUT.DB_HOST, host: ENVINPUT.DB_HOST,
dialect: 'mysql', dialect: 'mysql',
operatorsAliases: false, operatorsAliases: false,
pool: { pool: {
max: 5, max: 5,
min: 0, min: 0,
acquire: 90000000, acquire: 90000000,
idle: 1000000 idle: 1000000
}, },
debug:false, debug: false,
dialectOptions:{ dialectOptions: {
requestTimeout: 999999, requestTimeout: 999999,
// instanceName:'DEV' // instanceName:'DEV'
} //设置MSSQL超时时间 } //设置MSSQL超时时间
}, },
}; };
} }
......
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