Commit 06f74711 by 宋毅

tj

parent f098e32d
......@@ -70,8 +70,8 @@ class APIBase {
return x >= 0;
}
async checkAcck(gname, methodname, pobj, query, req) {
var uAppInfo = null;
var selfAppInfo = null;
// var uAppInfo = null;
// var selfAppInfo = null;
var ispass = await this.isCheckWhiteList(gname, methodname);
if (ispass) {
return system.getResultSuccess();
......@@ -80,21 +80,13 @@ class APIBase {
if (!token) {
return system.getResult(null, "token不能为空");
}
uAppInfo = await this.cacheManager["ApiAccessKeyCheckCache"].cache(token, { status: true }, this.exTime);
if (!uAppInfo || (uAppInfo.status && uAppInfo.status != 0)) {
return uAppInfo;
}
var selfAppInfo = await this.cacheManager["ApiAppKeyCheckCache"].cache(uAppInfo.data.app.appkey, null, this.exTime);
if (!selfAppInfo || (selfAppInfo.status && selfAppInfo.status != 0)) {
return selfAppInfo;
var selfAppInfo = await this.cacheManager["AppTokenByHostsCache"].getCache(token, system.exTime);
if (selfAppInfo.status != 0) {
return result;
}
// if (!appInfo) {
// return system.getResult(null, "通过token获取sign的密钥信息失败,请重新获取");
// }
// var signResult = await this.verifySign(pobj.action_body, appInfo.appSecret);
// if (signResult.status != 0) {
// return system.getResultFail(system.signFail, signResult.msg);
// }
req.app = selfAppInfo.data;
if (pobj.isUser && pobj.isUser == "yes") {
var channelUserId = pobj.channelUserId ? pobj.channelUserId : pobj.actionBody.channelUserId || "";
if (!channelUserId && pobj.actionBody.channelUser) {
......@@ -105,7 +97,7 @@ class APIBase {
}
var userCacheKey = selfAppInfo.data.uappKey + "_" + channelUserId;
var userInfo = await this.cacheManager["ApiUserCache"].cache(userCacheKey, channelUserId,
this.exTime, pobj.actionBody, selfAppInfo, uAppInfo.data.app.id);
this.exTime, pobj.actionBody, selfAppInfo, selfAppInfo.data.uAppId);
if (!userInfo || (userInfo.status && userInfo.status != 0)) {
return userInfo;
}
......@@ -115,7 +107,6 @@ class APIBase {
req.user = userInfo.data;
pobj.actionBody.channelUserId = channelUserId;
}
req.app = selfAppInfo.data;
return system.getResultSuccess();
}
async doexec(gname, methodname, pobj, query, req) {
......
......@@ -71,17 +71,7 @@ class APIBase extends DocBase {
if (ispass) {
return result;
}//在百名单里面
if (appkey) {
appInfo = await this.cacheManager["ApiAccessKeyCheckCache"].cache(appkey, { status: true }, 3000);
if (!appInfo || !appInfo.app) {
result.status = system.tokenFail;
result.msg = "请求头accesskey失效,请重新获取";
}
}//验证accesskey
else {
result.status = -1;
result.msg = "请求头没有相关访问参数,请验证后在进行请求";
}
return result;
}
async doexec(gname, methodname, pobj, query, req) {
......
......@@ -5,6 +5,7 @@ class AccessAuthAPI extends APIBase {
super();
this.opPlatformUtils = system.getObject("util.businessManager.opPlatformUtils");
this.toolSve = system.getObject("service.trademark.toolSve");
this.redisClient = system.getObject("util.redisClient");
}
/**
* 接口跳转-POST请求
......@@ -52,7 +53,7 @@ class AccessAuthAPI extends APIBase {
opResult = system.getResultSuccess(null, "测试成功");
break;
case "getVerifyCode":
opResult = await this.opPlatformUtils.getVerifyCodeByMoblie(action_body);
opResult = await this.opPlatformUtils.getVerifyCodeByMoblie(action_process, action_body);
if (opResult.status == 0) {
return system.getResultSuccess()
}
......@@ -109,22 +110,25 @@ class AccessAuthAPI extends APIBase {
}
async getToken(pobj, qobj, req) {
var appkey = pobj.appkey;
var secret = pobj.secret;
if (!appkey) {
return system.getResult(null, "appkey参数不能为空");
if (!pobj.appkey) {
return system.getResult(null, "pobj.appkey参数不能为空");
}
if (!secret) {
return system.getResult(null, "secret参数不能为空");
if (!pobj.secret) {
return system.getResult(null, "pobj.secret参数不能为空");
}
var result = await this.opPlatformUtils.getReqApiAccessKey(appkey, secret);
if (result && result.status && result.status != 0) {
return result;
var cacheKey = "getToken:appkey_" + pobj.appkey;
var jsonToken = await this.redisClient.get(cacheKey);
if (jsonToken) {
return JSON.parse(jsonToken);
}
var resultData = {
token: result && result.data ? result.data.accessKey : ""
};
return system.getResultSuccess(resultData);
var token = this.getUUID();
var opResult = await this.opPlatformUtils.getReqTokenByHosts(pobj, token);
if (opResult.status != 0) {
return opResult;
}
var result = system.getResultSuccess({ token: token });
this.redisClient.setWithEx(cacheKey, JSON.stringify(result), system.shortExTime);
return result;
}
/**
* 开放平台回调处理
......
const CacheBase = require("../cache.base");
const system = require("../../system");
const settings = require("../../../config/settings");
//缓存首次登录的赠送的宝币数量
class ApiAccessKeyCheckCache extends CacheBase {
constructor() {
super();
this.restS = system.getObject("util.restClient");
}
desc() {
return "应用中来访访问token缓存";
}
prefix() {
return settings.cacheprefix + "_verify_reqaccesskey:";
}
async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var cacheManager = system.getObject("db.common.cacheManager");
//当来访key缓存不存在时,需要去开放平台检查是否存在来访key缓存
var acckapp = await cacheManager["ApiAccessKeyCache"].cache(settings.appKey, null, ex);//先获取本应用accessKey
if (acckapp.status != 0) {
return system.getResult(null, "获取本应用accessKey错误");
}
var checkresult = await this.restS.execPostWithAK({ checkAccessKey: inputkey }, settings.paasUrl() + "api/auth/accessAuth/authAccessKey", acckapp.data.accessKey);
if (checkresult.status == 0) {
return checkresult;
// var s = checkresult.data;
// return JSON.stringify(s);
} else {
await cacheManager["ApiAccessKeyCache"].invalidate(settings.appKey);
var acckapp = await cacheManager["ApiAccessKeyCache"].cache(settings.appKey, null, ex);//先获取本应用accessKey
var checkresult = await this.restS.execPostWithAK({ checkAccessKey: inputkey }, settings.paasUrl() + "api/auth/accessAuth/authAccessKey", acckapp.data.accessKey);
return checkresult;
// var s = checkresult.data;
// return JSON.stringify(s);
}
}
}
module.exports = ApiAccessKeyCheckCache;
......@@ -23,16 +23,16 @@ class ApiUserCache extends CacheBase {
var uAppId = items[2];
var channelUserId = val || "";
var uUserName = channelUserId + "$" + selfAppInfo.data.uappKey;//uUserName
// var uUserName = channelUserId;//channelUserId + "$" + selfAppInfo.data.uappKey;//uUserName
var createUserPwd = inputkey;//(格式:selfAppInfo.data.uappKey+”_“+channelUserId)
var userInfo = await this.appuserDao.getItemByUUserId(uUserName, selfAppInfo.data.id);
var userInfo = await this.appuserDao.getItemByUUserId(channelUserId, selfAppInfo.data.id);
if (userInfo) {
var loginNum = Number(userInfo.loginNum || 0) + 1;
this.appuserDao.updateByWhere({ lastLoginTime: new Date(), loginNum: loginNum }, { where: { id: userInfo.id } });
return system.getResultSuccess(userInfo);
}
var uUserInfo = await this.opPlatformUtils.createUserInfo(uUserName, actionBody.channelUserMoblie || "15010888888",
var uUserInfo = await this.opPlatformUtils.createUserInfo(channelUserId, actionBody.channelUserMoblie || "15010888888",
createUserPwd, selfAppInfo.data.uappKey, selfAppInfo.data.appSecret);
if (uUserInfo.status != 2000 && uUserInfo.status != 0) {
return uUserInfo;
......@@ -47,7 +47,7 @@ class ApiUserCache extends CacheBase {
orgName: actionBody.orgName || "",
orgPath: actionBody.orgPath || "",
uUserName: uUserName,
uUserName: channelUserId,
uAppId: uAppId,
isEnabled: 1,
lastLoginTime: new Date()
......
......@@ -4,27 +4,34 @@ const settings = require("../../../config/settings");
class AppTokenByHostsCache extends CacheBase {
constructor() {
super();
this.opPlatformUtils = system.getObject("util.businessManager.opPlatformUtils");
this.restClient = system.getObject("util.restClient");
this.appDao = system.getObject("db.dbapp.appDao");
}
desc() {
return "应用中缓存访问token";
}
prefix() {
return settings.cacheprefix + "_accesskey:";
return settings.cacheprefix + "_accessTokenKey:";
}
async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var app_hosts = val;
if (!app_hosts) {
return system.getResult(null, "app_hosts can not be empty");
var pobj = val;
var item = await this.appDao.getItemByUappKey(pobj.appkey, pobj.secret);
if (!item) {
return system.getResult(null, "params to data is empty !");
}
var acckapp = await this.restClient.execPost({ app_hosts: app_hosts }, settings.centerAppUrl() + "auth/accessAuth/getTokenByHosts");
var result = acckapp.stdout;
console.log(acckapp.stdout, "AppTokenByHostsCache............. acckapp.stdout..........")
if (result) {
var tmp = JSON.parse(result);
return tmp;
if (item.status != 1) {
return system.getResult(null, "params to item is Disable !");
}
return system.getResult(null, "data is empty");
var result = await this.opPlatformUtils.getReqApiAccessKey(pobj.appkey, pobj.secret);
if (!result) {
return system.getResult(null, "platform to data is empty !");
}
if (result.status != 0) {
return result;
}
item.token = result.data.accessKey;
return system.getResultSuccess(item);
}
}
module.exports = AppTokenByHostsCache;
......@@ -16,16 +16,26 @@ class AppUserPinByLoginVcodeCache extends CacheBase {
}
async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var actionBody = val;
var userInfo = null;
if (actionBody.reqType == "reg") {
userInfo = await this.appuserDao.getItemByUUserId(actionBody.mobile, actionBody.appInfo.id);
if (userInfo) {
if (userInfo.isEnabled != 1) {
return system.getResultFail(system.userDisable, "用户信息禁用 !");
}
return system.getResultFail(system.existUser, "用户已存在,请勿重复注册");
}
}
var uUserInfo = await this.opPlatformUtils.loginByVCode(actionBody.mobile, actionBody.vcode, actionBody.password,
actionBody.appInfo.uappKey, actionBody.appInfo.appSecret);
if (uUserInfo.status != 0) {
return uUserInfo;
}//2030验证码校验不成功 或 注册失败
var userInfo = await this.appuserDao.getItemByUUserId(actionBody.mobile, actionBody.appInfo.id);
userInfo = await this.appuserDao.getItemByUUserId(actionBody.mobile, actionBody.appInfo.id);
if (userInfo) {
if (userInfo.is_enabled != 1) {
return system.getResult(null, "user to item is Disable !");
if (userInfo.isEnabled != 1) {
return system.getResultFail(system.userDisable, "用户信息禁用 !!");
}
return system.getResultSuccess(userInfo);
}
......
......@@ -28,5 +28,30 @@ class AppDao extends Dao {
raw: true
});
}
async getItemByUappKey(uAppKey, secret) {
return this.model.findOne({
where: {
uappKey: uAppKey,
appSecret: secret
},
attributes: ["id",
"name", // 应用名称
"appDataOpType", // 应用数据操作类型:00独立,10全委托,20部分委托
"appPayType", // 支付类型:00第三方应用自己支付,10平台代收款
"contactName", // 联系人姓名
"contactMobile", // 联系人手机
"contactEmail", // 联系人邮箱
"uappKey", // 平台应用key
"appSecret", // 密钥信息,用于进行签名请求接口
"status", // 状态 0禁用 1启用
"uAppId",
"channelAppId", // 渠道appID
"channelAppKey", // 渠道appKey
"pushOrderUrl", //获取渠道推送订单的url
"appSourceCode", //app来源code
"notes"],
raw: true
});
}
}
module.exports = AppDao;
......@@ -139,38 +139,6 @@ class ServiceBase {
}
return tResult;
}
async apiCallWithAk(url, params) {
var acckapp = await this.cacheManager["ApiAccessKeyCache"].cache(settings.appKey);
var acck = acckapp.accessKey;
//按照访问token
var restResult = await this.restS.execPostWithAK(params, url, acck);
if (restResult) {
if (restResult.status == 0) {
var resultRtn = restResult.data;
return resultRtn;
} else {
await this.cacheManager["ApiAccessKeyCache"].invalidate(settings.appKey);
return null;
}
}
return null;
}
// async apiCallWithAkNoWait(url,params){
// var acckapp=await this.cacheManager["ApiAccessKeyCache"].cache(settings.appKey);
// var acck=acckapp.accessKey;
// //按照访问token
// var restResult=await this.restS.execPostWithAK(params,url,acck);
// if(restResult){
// if(restResult.status==0){
// var resultRtn=restResult.data;
// return resultRtn;
// }else{
// await this.cacheManager["ApiAccessKeyCache"].invalidate(settings.appKey);
// return null;
// }
// }
// return null;
// }
static getDaoName(ClassObj) {
return ClassObj["name"].substring(0, ClassObj["name"].lastIndexOf("Service")).toLowerCase() + "Dao";
}
......
......@@ -292,6 +292,7 @@ Date.prototype.Format = function (fmt) { //author: meizz
return fmt;
}
System.exTime = 4 * 3600;//缓存过期时间,4小时
System.shortExTime = 1 * 3600;//缓存过期时间,4小时
System.objTable = {};
......@@ -323,5 +324,7 @@ System.existData = 1400;
System.noUserFail = 2070;
//用户信息禁用
System.userDisable = 2080;
//用户已存在,请勿重复注册
System.existUser = 2000;
module.exports = System;
\ No newline at end of file
......@@ -8,6 +8,7 @@ class OpPlatformUtils {
this.restClient = system.getObject("util.restClient");
this.createUserUrl = settings.paasUrl() + "api/auth/accessAuth/register";
this.fetchDefaultVCodeUrl = settings.paasUrl() + "api/auth/accessAuth/fetchDefaultVCode";
this.fetchOtherVCodeUrl = settings.paasUrl() + "api/auth/accessAuth/fetchOtherVCode";
this.loginUrl = settings.paasUrl() + "api/auth/accessAuth/loginByMd5Password";
this.authByCodeUrl = settings.paasUrl() + "api/auth/accessAuth/authByCode";
this.loginByVCodeUrl = settings.paasUrl() + "api/auth/accessAuth/loginByVCode";
......@@ -20,13 +21,14 @@ class OpPlatformUtils {
var u = uuid.replace(/\-/g, "");
return u;
}
async getReqApiAccessKey(appKey, secret) {
var cacheManager = system.getObject("db.common.cacheManager");
var reqApiAccessKey = null;
if (appKey && secret) {
reqApiAccessKey = await cacheManager["ApiAccessKeyCache"].cache(appKey, null, 1, secret);
reqApiAccessKey = await cacheManager["ApiAccessKeyCache"].cache(appKey, null, 10, secret);
} else {
reqApiAccessKey = await cacheManager["ApiAccessKeyCache"].cache(settings.appKey, null, 1);
reqApiAccessKey = await cacheManager["ApiAccessKeyCache"].cache(settings.appKey, null, 10);
}
if (!reqApiAccessKey || !reqApiAccessKey.data) {
return system.getResult(null, "获取请求token失败");
......@@ -72,7 +74,22 @@ class OpPlatformUtils {
}
return system.getResultSuccess(restResult.data);
}
async fetchVCode(mobile, appKey, secret) {
async fetchOtherVCode(param, appKey, secret) {
var reqApiAccessKey = await this.getReqApiAccessKey(appKey, secret);
if (reqApiAccessKey.status != 0) {
return reqApiAccessKey;
}
//按照访问token
var restResult = await this.restClient.execPostWithAK(
param,
this.fetchOtherVCodeUrl, reqApiAccessKey.data.accessKey);
if (restResult.status != 0 || !restResult.data) {
return system.getResult(null, restResult.msg);
}
return system.getResultSuccess();
}
async fetchDefaultVCode(mobile, appKey, secret) {
var reqApiAccessKey = await this.getReqApiAccessKey(appKey, secret);
if (reqApiAccessKey.status != 0) {
return reqApiAccessKey;
......@@ -205,12 +222,9 @@ class OpPlatformUtils {
return restResult;
}
//------------------------新的方式------------------------------------------------------------------------------------
async getReqTokenByHosts(appHosts, tokenValue) {
if (!appHosts) {
return system.getResult(null, "appHosts can not be empty");
}
async getReqTokenByHosts(pobj, tokenValue) {//通过密钥进行获取token,跟平台的token没有关系
var cacheManager = system.getObject("db.common.cacheManager");
var result = await cacheManager["AppTokenByHostsCache"].cache(tokenValue, appHosts, system.exTime);
var result = await cacheManager["AppTokenByHostsCache"].cache(tokenValue, pobj, system.exTime);
return result;
}
......@@ -247,18 +261,32 @@ class OpPlatformUtils {
return system.getResult(null, "actionBody.password can not be empty");
}
}
actionBody.reqType = reqType;
var cacheManager = system.getObject("db.common.cacheManager");
var result = await cacheManager["AppUserPinByLoginVcodeCache"].cache(userPinValue, actionBody, system.exTime);
return result;
}
async getVerifyCodeByMoblie(actionBody) {
async getVerifyCodeByMoblie(action_process, actionBody) {
if (!actionBody.mobile) {
return system.getResult(null, "pobj.mobile can not be empty !");
}
if (!actionBody.appInfo) {
return system.getResult(null, "pobj.appInfo can not be empty !");
}
var acckapp = await this.fetchVCode(actionBody.mobile, actionBody.appInfo.uappKey, actionBody.appInfo.appSecret);
var acckapp = null;
if (action_process == "bw") {
var param = {
mobile: actionBody.mobile,
tmplCode: "SMS_151685065",
signName: "小望科技",
accessKeyId: "LTAI4Fjk6qBh4GELjkBxfyJF",
accessKeySecret: "Z3wUHmZ0hnQst6uaTY3GzOYVoWwxb9"
}
acckapp = await this.fetchOtherVCode(param, actionBody.appInfo.uappKey, actionBody.appInfo.appSecret);
}
else {
acckapp = await this.fetchDefaultVCode(actionBody.mobile, actionBody.appInfo.uappKey, actionBody.appInfo.appSecret);
}
return acckapp;
}
async putUserPwdByMobile(actionBody) {
......
var path = require('path');
var ENVINPUT={
DB_HOST:process.env.DB_HOST,
DB_PORT:process.env.DB_PORT,
DB_USER:process.env.DB_USER,
DB_PWD:process.env.DB_PWD,
DB_NAME:process.env.ZC_CHANNEL_DB_NAME,
REDIS_HOST:process.env.REDIS_HOST,
REDIS_PORT:process.env.REDIS_PORT,
REDIS_PWD:process.env.REDIS_PWD,
REDIS_DB:process.env.ZC_CHANNEL_REDIS_DB,
APP_ENV:process.env.APP_ENV?process.env.APP_ENV:"dev"
var ENVINPUT = {
DB_HOST: process.env.DB_HOST,
DB_PORT: process.env.DB_PORT,
DB_USER: process.env.DB_USER,
DB_PWD: process.env.DB_PWD,
DB_NAME: process.env.ZC_CHANNEL_DB_NAME,
REDIS_HOST: process.env.REDIS_HOST,
REDIS_PORT: process.env.REDIS_PORT,
REDIS_PWD: process.env.REDIS_PWD,
REDIS_DB: process.env.ZC_CHANNEL_REDIS_DB,
APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "dev"
};
var settings = {
env:ENVINPUT.APP_ENV,
env: ENVINPUT.APP_ENV,
appKey: "201911061250",
secret: "f99d413b767f09b5dff0b3610366cc46",
salt: "%iatpD1gcxz7iF#B",
cacheprefix: "centerChannel",
cacheprefix: "igirlChannel",
usertimeout: 3600,//单位秒
basepath: path.normalize(path.join(__dirname, '../..')),
port: process.env.NODE_PORT || 4003,
......@@ -33,14 +33,14 @@ var settings = {
} else {
return "http://center-app-service/";
}
},
},
centerChannelUrl: function () {
if (this.env == "dev") {
return "http://gsb.qifu.gongsibao.com:4011/";
} else {
return "http://center-channel-service/";
}
},
},
reqTransferurl: function () {
if (this.env == "dev") {
return "http://192.168.18.61:3003/";
......@@ -93,10 +93,10 @@ var settings = {
return localsettings.redis;
} else {
return {
host:ENVINPUT.REDIS_HOST,
port:ENVINPUT.REDIS_PORT,
password:ENVINPUT.REDIS_PWD,
db:ENVINPUT.REDIS_DB,
host: ENVINPUT.REDIS_HOST,
port: ENVINPUT.REDIS_PORT,
password: ENVINPUT.REDIS_PWD,
db: ENVINPUT.REDIS_DB,
};
}
},
......@@ -106,24 +106,24 @@ var settings = {
return localsettings.database;
} else {
return {
dbname : ENVINPUT.DB_NAME,
user : ENVINPUT.DB_USER,
password : ENVINPUT.DB_PWD,
config : {
host: ENVINPUT.DB_HOST,
dialect: 'mysql',
operatorsAliases: false,
pool: {
max: 5,
min: 0,
acquire: 90000000,
idle: 1000000
},
debug:false,
dialectOptions:{
requestTimeout: 999999,
// instanceName:'DEV'
} //设置MSSQL超时时间
dbname: ENVINPUT.DB_NAME,
user: ENVINPUT.DB_USER,
password: ENVINPUT.DB_PWD,
config: {
host: ENVINPUT.DB_HOST,
dialect: 'mysql',
operatorsAliases: false,
pool: {
max: 5,
min: 0,
acquire: 90000000,
idle: 1000000
},
debug: false,
dialectOptions: {
requestTimeout: 999999,
// instanceName:'DEV'
} //设置MSSQL超时时间
},
};
}
......
......@@ -111,7 +111,7 @@
#### 返回结果
``` javascript
{
"status": 0,// 0为成功,2030为验证码错误,2060为重复登录,否则失败
"status": 0,// 0为成功,2000用户已存在,2030为验证码错误,2080用户信息禁用,请勿重复注册,否则失败
"msg": "success",
"data": {
"userpin": "230ecdf3333944ff834f56fba10a02aa", //用户登录后的凭证,增、删、改、查、涉及用户的需要传递此值在请求头中
......
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