Commit 3b31375e authored by 姜登's avatar 姜登

新增appKey配置

parent d897fdaa
Pipeline #4112 passed with stage
in 58 seconds
......@@ -50,6 +50,10 @@ class OrderController extends Controller {
const uuid = require('node-uuid');
ctx.validate(this.createRule);
let { appKey, userId, notifyUrl, backUrl, orderId } = ctx.request.body;
const appKeyInfo = await service.partner.fetchInfo(appKey);
if (!(appKeyInfo && appKeyInfo.valid === true && appKeyInfo.enableHf === true)) {
return ctx.fail('未开通此服务');
}
if (orderId) {
await service.order.update({
orderId,
......@@ -103,6 +107,10 @@ class OrderController extends Controller {
try {
ctx.validate(this.showRule);
const { appKey, orderId } = ctx.request.body.params;
const appKeyInfo = await service.partner.fetchInfo(appKey);
if (!(appKeyInfo && appKeyInfo.valid === true && appKeyInfo.enableHfData === true)) {
return ctx.fail('未开通此服务');
}
await service.signature.signatureCheck(ctx.request.body);
const data = await service.order.getOneByOrderId(orderId);
if (data) {
......@@ -132,6 +140,10 @@ class OrderController extends Controller {
async orderShow() {
const { ctx, service } = this;
const { appKey, orderId } = ctx.params;
const appKeyInfo = await service.partner.fetchInfo(appKey);
if (!(appKeyInfo && appKeyInfo.valid === true && appKeyInfo.enableHfView === true)) {
return ctx.fail('未开通此服务');
}
const data = await service.order.getOneByOrderId(orderId);
if (data) {
if (data.status === 'success' && (data.appKey === appKey)) {
......
......@@ -24,7 +24,6 @@ module.exports = app => {
gjjRouter.get('/params', controller.script.fetchParamsInfo); // 获取登录参数字典
gjjRouter.post('/tokens', controller.token.create); // 创建token
gjjRouter.post('/orders', controller.order.create); // 创建订单号
// router.post('/orders/:orderId', controller.order.show); // 获取订单号详情
gjjRouter.get('/hubs/:hubId/scripts', controller.script.fetchHubSeripts);// 根据hubId 获取脚本数据(数组)
......
'use strict';
module.exports = {
schedule: {
interval: '5m', // 5分钟间隔
type: 'all', // 所有woker
immediate: true,
},
async task(ctx) {
try {
const dbRes = await ctx.cusPro.query('SELECT app_key FROM customer_product WHERE goods_sn = 102 AND state = 1', {
type: 'SELECT',
});
const arr = [];
for (const item of dbRes) {
arr.push(item.app_key);
}
ctx.app.appKeyArr = arr;
} catch (e) {
ctx.logger.error('【schedule/flash_cus_pro】catch error:', JSON.stringify(e));
}
}
};
......@@ -22,17 +22,50 @@ class PartnerService extends Service {
}
}
}
const ret = await ctx.curl(`${host + fetchTheme}/${appKey}/theme`, {
const ret = await ctx.curl(`${host + fetchTheme}`, {
charset: 'utf-8',
timeout: ['30s', '30s'],
dataType: 'json',
method: 'GET',
data: {
appKey,
subject: 'hf'
}
});
ctx.logger.info(`【Partner】 fetchTheme ${host + fetchTheme}/${appKey}`, ret.data);
if (ret.status === 200 && ret.data && ret.data.appKey === appKey) {
await this.app.redis.set(redisThemePrefix + appKey, JSON.stringify(ret.data), 'EX', 300);
if (ret.status === 200 && ret.data && ret.data.length > 0 && ret.data[0].appKey === appKey) {
await this.app.redis.set(redisThemePrefix + appKey, JSON.stringify(ret.data[0]), 'EX', 300);
}
return ret.data;
return ret.data[0];
}
async fetchInfo(appKey){
const { ctx, partnerAPI: { fetchInfo, host, redisInfoPrefix } } = this;
if (appKey) {
const data = await this.app.redis.get(redisInfoPrefix + appKey);
if (data) {
try {
return JSON.parse(data);
} catch (err) {
ctx.logger.error('【Scripts】fetchInfo', redisInfoPrefix + appKey, 'result:', data, err);
await this.app.redis.del(redisInfoPrefix + appKey);
}
}
}
const ret = await ctx.curl(`${host + fetchInfo}`, {
charset: 'utf-8',
timeout: ['30s', '30s'],
dataType: 'json',
method: 'GET',
data: {
appKey
}
});
ctx.logger.info(`【Partner】 fetchTheme ${host + fetchInfo}?appKey=${appKey}`, ret.data);
if (ret.status === 200 && ret.data && ret.data.length > 0 && ret.data[0].appKey === appKey) {
await this.app.redis.set(redisInfoPrefix + appKey, JSON.stringify(ret.data[0]), 'EX', 300);
}
return ret.data[0];
}
async fetchScripts(appKey) {
......
......@@ -13,9 +13,7 @@ module.exports = appInfo => {
maxDays: 5,
}
// config.verifyAppKey = {
// match: '/orders',
// }
// 是否启用csrf安全
config.security = {
......
......@@ -25,12 +25,14 @@ module.exports = () => {
config.partnerAPI = {
host: 'https://uat-nginx.jianbing.com/zeus-api/v1',
fetchTheme: '/chaos/hf/partners',
fetchTheme: '/chaos/theme',
fetchScripts: '/chaos/partners/scripts',
fetchAgreements: '/chaos/agreements',
redisThemePrefix: 'URANUS.HF.PARNTERS.THEME',
redisScriptsPrefix: 'URANUS.HF.PARNTERS.SCRIPTS',
redisAgreementsPrefix: 'URANUS.HF.PARNTERS.Agreements',
fetchInfo: '/chaos/partner',
redisInfoPrefix:'URANUS.HF.PARNTERS.Info',
};
config.scriptsAPI = {
......@@ -45,7 +47,7 @@ module.exports = () => {
fetchScriptByCityNameUrl: '/chaos/hf/city_scripts',
redisScriptsKey: 'URANUS.HF.SCRIPTS',
redisParamsKey: 'URANUS.HF.PARAMS',
redisScriptListKey:'URANUS.HF.SCRIPTLIST',
redisScriptListKey: 'URANUS.HF.SCRIPTLIST',
};
config.storageAPI = {
......@@ -68,7 +70,7 @@ module.exports = () => {
signatureUrl: '/Access/SignValidityCheck',
fetchParnterUrl: '',
signatureType: 'gjj',
customerUrl:'/customer/query',
customerUrl: '/customer/query',
};
config.lockKeys = {
......@@ -105,10 +107,6 @@ module.exports = () => {
}],
};
config.GJJ_OpenAPI = {
appKey: '60670203E411FD62BA9E953CFB73F881',
appSecret: '0BDD1ECC147503C477563E5C1438C366D70E4F80',
};
config.callbackUrl = 'https://dev-nginx.jianbing.com/gjjh5/callback';
......
......@@ -66,12 +66,14 @@ module.exports = () => {
config.partnerAPI = {
host: process.env.PARTNERAPI_HOST || 'https://uat-nginx.jianbing.com/zeus-api/v1',
fetchTheme: '/chaos/hf/partners',
fetchTheme: '/chaos/theme',
fetchScripts: '/chaos/partners/scripts',
fetchAgreements: '/chaos/agreements',
redisThemePrefix: 'URANUS.HF.PARNTERS.THEME',
redisScriptsPrefix: 'URANUS.HF.PARNTERS.SCRIPTS',
redisAgreementsPrefix: 'URANUS.HF.PARNTERS.Agreements',
fetchInfo: '/chaos/partner',
redisInfoPrefix:'URANUS.HF.PARNTERS.Info',
};
config.lockKeys = {
......
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