From c39a087e352a62da03b0b38911727de9bf8fe2a5 Mon Sep 17 00:00:00 2001 From: tanghc Date: Wed, 15 May 2019 17:31:42 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9A=90=E8=97=8F=E8=BF=94=E5=9B=9E=E7=9A=84si?= =?UTF-8?q?gn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sop/gatewaycommon/bean/ApiConfig.java | 5 ++++ .../result/BaseExecutorAdapter.java | 26 ++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ApiConfig.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ApiConfig.java index 81195ecc..c7af2d33 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ApiConfig.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ApiConfig.java @@ -150,6 +150,11 @@ public class ApiConfig { */ private boolean openLimit = true; + /** + * 显示返回sign + */ + private boolean showReturnSign = true; + public void addAppSecret(Map appSecretPair) { for (Map.Entry entry : appSecretPair.entrySet()) { this.isvManager.update(new IsvDefinition(entry.getKey(), entry.getValue())); diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/BaseExecutorAdapter.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/BaseExecutorAdapter.java index f40d39e2..e360c493 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/BaseExecutorAdapter.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/BaseExecutorAdapter.java @@ -120,25 +120,19 @@ public abstract class BaseExecutorAdapter implements ResultExecutor public String merge(T exchange, JSONObject jsonObjectService) { JSONObject ret = new JSONObject(); String name = "error"; - String sign = ""; Map params = this.getApiParam(exchange); if (params != null) { Object method = params.get(ParamNames.API_NAME); if (method != null) { name = String.valueOf(method); } - Object clientSign = params.get(ParamNames.SIGN_NAME); - if (clientSign != null) { - sign = String.valueOf(clientSign); - } } ApiConfig apiConfig = ApiConfig.getInstance(); // 点换成下划线 DataNameBuilder dataNameBuilder = apiConfig.getDataNameBuilder(); String method = dataNameBuilder.build(name); ret.put(method, jsonObjectService); - // 先隐藏返回签名字段 - ret.put(ParamNames.SIGN_NAME, sign); + this.appendReturnSign(apiConfig, params, ret); ResultAppender resultAppender = apiConfig.getResultAppender(); if (resultAppender != null) { resultAppender.append(ret, params); @@ -146,4 +140,22 @@ public abstract class BaseExecutorAdapter implements ResultExecutor return ret.toJSONString(); } + protected void appendReturnSign(ApiConfig apiConfig, Map params, JSONObject ret) { + if (apiConfig.isShowReturnSign() && params != null) { + Object appKey = params.get(ParamNames.APP_KEY_NAME); + String sign = this.createReturnSign(String.valueOf(appKey)); + ret.put(ParamNames.SIGN_NAME, sign); + } + } + + /** + * 这里需要使用平台的私钥生成一个sign,需要配置两套公私钥。目前暂未实现 + * @param appKey + * @return + */ + protected String createReturnSign(String appKey) { + // TODO: 返回sign + return null; + } + }