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 { ...@@ -50,6 +50,10 @@ class OrderController extends Controller {
const uuid = require('node-uuid'); const uuid = require('node-uuid');
ctx.validate(this.createRule); ctx.validate(this.createRule);
let { appKey, userId, notifyUrl, backUrl, orderId } = ctx.request.body; 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) { if (orderId) {
await service.order.update({ await service.order.update({
orderId, orderId,
...@@ -103,6 +107,10 @@ class OrderController extends Controller { ...@@ -103,6 +107,10 @@ class OrderController extends Controller {
try { try {
ctx.validate(this.showRule); ctx.validate(this.showRule);
const { appKey, orderId } = ctx.request.body.params; 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); await service.signature.signatureCheck(ctx.request.body);
const data = await service.order.getOneByOrderId(orderId); const data = await service.order.getOneByOrderId(orderId);
if (data) { if (data) {
...@@ -132,6 +140,10 @@ class OrderController extends Controller { ...@@ -132,6 +140,10 @@ class OrderController extends Controller {
async orderShow() { async orderShow() {
const { ctx, service } = this; const { ctx, service } = this;
const { appKey, orderId } = ctx.params; 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); const data = await service.order.getOneByOrderId(orderId);
if (data) { if (data) {
if (data.status === 'success' && (data.appKey === appKey)) { if (data.status === 'success' && (data.appKey === appKey)) {
......
...@@ -24,7 +24,6 @@ module.exports = app => { ...@@ -24,7 +24,6 @@ module.exports = app => {
gjjRouter.get('/params', controller.script.fetchParamsInfo); // 获取登录参数字典 gjjRouter.get('/params', controller.script.fetchParamsInfo); // 获取登录参数字典
gjjRouter.post('/tokens', controller.token.create); // 创建token gjjRouter.post('/tokens', controller.token.create); // 创建token
gjjRouter.post('/orders', controller.order.create); // 创建订单号 gjjRouter.post('/orders', controller.order.create); // 创建订单号
// router.post('/orders/:orderId', controller.order.show); // 获取订单号详情
gjjRouter.get('/hubs/:hubId/scripts', controller.script.fetchHubSeripts);// 根据hubId 获取脚本数据(数组) 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 { ...@@ -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', charset: 'utf-8',
timeout: ['30s', '30s'], timeout: ['30s', '30s'],
dataType: 'json', dataType: 'json',
method: 'GET', method: 'GET',
data: {
appKey,
subject: 'hf'
}
}); });
ctx.logger.info(`【Partner】 fetchTheme ${host + fetchTheme}/${appKey}`, ret.data); ctx.logger.info(`【Partner】 fetchTheme ${host + fetchTheme}/${appKey}`, ret.data);
if (ret.status === 200 && ret.data && ret.data.appKey === appKey) { 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), 'EX', 300); 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) { async fetchScripts(appKey) {
......
...@@ -13,9 +13,7 @@ module.exports = appInfo => { ...@@ -13,9 +13,7 @@ module.exports = appInfo => {
maxDays: 5, maxDays: 5,
} }
// config.verifyAppKey = {
// match: '/orders',
// }
// 是否启用csrf安全 // 是否启用csrf安全
config.security = { config.security = {
......
...@@ -25,12 +25,14 @@ module.exports = () => { ...@@ -25,12 +25,14 @@ module.exports = () => {
config.partnerAPI = { config.partnerAPI = {
host: 'https://uat-nginx.jianbing.com/zeus-api/v1', host: 'https://uat-nginx.jianbing.com/zeus-api/v1',
fetchTheme: '/chaos/hf/partners', fetchTheme: '/chaos/theme',
fetchScripts: '/chaos/partners/scripts', fetchScripts: '/chaos/partners/scripts',
fetchAgreements: '/chaos/agreements', fetchAgreements: '/chaos/agreements',
redisThemePrefix: 'URANUS.HF.PARNTERS.THEME', redisThemePrefix: 'URANUS.HF.PARNTERS.THEME',
redisScriptsPrefix: 'URANUS.HF.PARNTERS.SCRIPTS', redisScriptsPrefix: 'URANUS.HF.PARNTERS.SCRIPTS',
redisAgreementsPrefix: 'URANUS.HF.PARNTERS.Agreements', redisAgreementsPrefix: 'URANUS.HF.PARNTERS.Agreements',
fetchInfo: '/chaos/partner',
redisInfoPrefix:'URANUS.HF.PARNTERS.Info',
}; };
config.scriptsAPI = { config.scriptsAPI = {
...@@ -45,7 +47,7 @@ module.exports = () => { ...@@ -45,7 +47,7 @@ module.exports = () => {
fetchScriptByCityNameUrl: '/chaos/hf/city_scripts', fetchScriptByCityNameUrl: '/chaos/hf/city_scripts',
redisScriptsKey: 'URANUS.HF.SCRIPTS', redisScriptsKey: 'URANUS.HF.SCRIPTS',
redisParamsKey: 'URANUS.HF.PARAMS', redisParamsKey: 'URANUS.HF.PARAMS',
redisScriptListKey:'URANUS.HF.SCRIPTLIST', redisScriptListKey: 'URANUS.HF.SCRIPTLIST',
}; };
config.storageAPI = { config.storageAPI = {
...@@ -68,7 +70,7 @@ module.exports = () => { ...@@ -68,7 +70,7 @@ module.exports = () => {
signatureUrl: '/Access/SignValidityCheck', signatureUrl: '/Access/SignValidityCheck',
fetchParnterUrl: '', fetchParnterUrl: '',
signatureType: 'gjj', signatureType: 'gjj',
customerUrl:'/customer/query', customerUrl: '/customer/query',
}; };
config.lockKeys = { config.lockKeys = {
...@@ -105,10 +107,6 @@ module.exports = () => { ...@@ -105,10 +107,6 @@ module.exports = () => {
}], }],
}; };
config.GJJ_OpenAPI = {
appKey: '60670203E411FD62BA9E953CFB73F881',
appSecret: '0BDD1ECC147503C477563E5C1438C366D70E4F80',
};
config.callbackUrl = 'https://dev-nginx.jianbing.com/gjjh5/callback'; config.callbackUrl = 'https://dev-nginx.jianbing.com/gjjh5/callback';
......
...@@ -66,12 +66,14 @@ module.exports = () => { ...@@ -66,12 +66,14 @@ module.exports = () => {
config.partnerAPI = { config.partnerAPI = {
host: process.env.PARTNERAPI_HOST || 'https://uat-nginx.jianbing.com/zeus-api/v1', host: process.env.PARTNERAPI_HOST || 'https://uat-nginx.jianbing.com/zeus-api/v1',
fetchTheme: '/chaos/hf/partners', fetchTheme: '/chaos/theme',
fetchScripts: '/chaos/partners/scripts', fetchScripts: '/chaos/partners/scripts',
fetchAgreements: '/chaos/agreements', fetchAgreements: '/chaos/agreements',
redisThemePrefix: 'URANUS.HF.PARNTERS.THEME', redisThemePrefix: 'URANUS.HF.PARNTERS.THEME',
redisScriptsPrefix: 'URANUS.HF.PARNTERS.SCRIPTS', redisScriptsPrefix: 'URANUS.HF.PARNTERS.SCRIPTS',
redisAgreementsPrefix: 'URANUS.HF.PARNTERS.Agreements', redisAgreementsPrefix: 'URANUS.HF.PARNTERS.Agreements',
fetchInfo: '/chaos/partner',
redisInfoPrefix:'URANUS.HF.PARNTERS.Info',
}; };
config.lockKeys = { 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