From 994960da31604d67983ebb4d635e5d751b0a37e9 Mon Sep 17 00:00:00 2001 From: tanghc Date: Fri, 25 Sep 2020 13:49:36 +0800 Subject: [PATCH 1/2] 4.0.3 --- .../gitee/sop/servercommon/bean/OpenContext.java | 14 ++++++++++++++ .../sop/servercommon/bean/OpenContextImpl.java | 13 ++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContext.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContext.java index b371cde1..8dafd420 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContext.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContext.java @@ -1,6 +1,7 @@ package com.gitee.sop.servercommon.bean; import java.util.Date; +import java.util.Map; /** * 获取开放平台请求参数。 @@ -9,6 +10,19 @@ import java.util.Date; */ public interface OpenContext { + /** + * 获取某个参数值 + * @param name 参数名称 + * @return 没有返回null + */ + String getParameter(String name); + + /** + * 返回所有的请求参数 + * @return 返回所有的请求参数 + */ + Map getParameterMap(); + /** * 返回appid * diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java index 344286b1..1a0c91ba 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java @@ -5,6 +5,7 @@ import org.apache.commons.lang3.time.DateUtils; import java.text.ParseException; import java.util.Date; +import java.util.Map; import static com.gitee.sop.servercommon.bean.ParamNames.API_NAME; import static com.gitee.sop.servercommon.bean.ParamNames.APP_AUTH_TOKEN_NAME; @@ -22,7 +23,7 @@ import static com.gitee.sop.servercommon.bean.ParamNames.VERSION_NAME; * @author tanghc */ public class OpenContextImpl implements OpenContext { - private JSONObject requestParams; + private final JSONObject requestParams; private Object bizObject; public OpenContextImpl(JSONObject requestParams) { @@ -33,6 +34,16 @@ public class OpenContextImpl implements OpenContext { this.bizObject = bizObject; } + @Override + public String getParameter(String name) { + return requestParams.getString(name); + } + + @Override + public Map getParameterMap() { + return requestParams; + } + @Override public String getAppId() { return requestParams.getString(APP_KEY_NAME); From 87a2a3a629562f3c51fca398daccb96465e2ae2c Mon Sep 17 00:00:00 2001 From: tanghc Date: Fri, 25 Sep 2020 14:03:51 +0800 Subject: [PATCH 2/2] 4.0.3 --- .../sop/servercommon/bean/OpenContext.java | 95 ++++++++++++++----- .../servercommon/bean/OpenContextImpl.java | 82 +--------------- 2 files changed, 73 insertions(+), 104 deletions(-) diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContext.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContext.java index 8dafd420..73527ce4 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContext.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContext.java @@ -1,8 +1,23 @@ package com.gitee.sop.servercommon.bean; +import org.apache.commons.lang3.time.DateUtils; + +import java.text.ParseException; import java.util.Date; import java.util.Map; +import static com.gitee.sop.servercommon.bean.ParamNames.API_NAME; +import static com.gitee.sop.servercommon.bean.ParamNames.APP_AUTH_TOKEN_NAME; +import static com.gitee.sop.servercommon.bean.ParamNames.APP_KEY_NAME; +import static com.gitee.sop.servercommon.bean.ParamNames.BIZ_CONTENT_NAME; +import static com.gitee.sop.servercommon.bean.ParamNames.CHARSET_NAME; +import static com.gitee.sop.servercommon.bean.ParamNames.FORMAT_NAME; +import static com.gitee.sop.servercommon.bean.ParamNames.NOTIFY_URL_NAME; +import static com.gitee.sop.servercommon.bean.ParamNames.SIGN_TYPE_NAME; +import static com.gitee.sop.servercommon.bean.ParamNames.TIMESTAMP_NAME; +import static com.gitee.sop.servercommon.bean.ParamNames.TIMESTAMP_PATTERN; +import static com.gitee.sop.servercommon.bean.ParamNames.VERSION_NAME; + /** * 获取开放平台请求参数。 * @@ -10,81 +25,109 @@ import java.util.Map; */ public interface OpenContext { - /** - * 获取某个参数值 - * @param name 参数名称 - * @return 没有返回null - */ - String getParameter(String name); - /** * 返回所有的请求参数 + * * @return 返回所有的请求参数 */ Map getParameterMap(); /** - * 返回appid + * 返回业务对象 * - * @return 返回appid + * @return 业务对象 */ - String getAppId(); + Object getBizObject(); + /** - * 返回业务参数json字符串 + * 获取某个参数值 * - * @return 返回字符串业务参数 + * @param name 参数名称 + * @return 没有返回null */ - String getBizContent(); + default String getParameter(String name) { + Object value = getParameterMap().get(name); + return value == null ? null : value.toString(); + } /** - * 返回业务对象 + * 返回appid * - * @return 业务对象 + * @return 返回appId */ - Object getBizObject(); + default String getAppId() { + return getParameter(APP_KEY_NAME); + } + + /** + * 返回业务参数json字符串 + * + * @return 返回字符串业务参数 + */ + default String getBizContent() { + return getParameter(BIZ_CONTENT_NAME); + } + /** * 返回字符编码 * * @return 如UTF-8 */ - String getCharset(); + default String getCharset() { + return getParameter(CHARSET_NAME); + } /** * 返回接口名 * * @return 如:alipay.goods.get */ - String getMethod(); + default String getMethod() { + return getParameter(API_NAME); + } /** * 返回版本号 * * @return 如:1.0 */ - String getVersion(); + default String getVersion() { + return getParameter(VERSION_NAME); + } /** * 返回参数格式化 * * @return 如:json */ - String getFormat(); + default String getFormat() { + return getParameter(FORMAT_NAME); + } /** * 返回签名类型 * * @return 如:RSA2 */ - String getSignType(); + default String getSignType() { + return getParameter(SIGN_TYPE_NAME); + } /** * 返回时间戳 * * @return */ - Date getTimestamp(); + default Date getTimestamp() { + String timestampStr = getParameter(TIMESTAMP_NAME); + try { + return DateUtils.parseDate(timestampStr, TIMESTAMP_PATTERN); + } catch (ParseException e) { + return null; + } + } /** @@ -92,13 +135,17 @@ public interface OpenContext { * * @return 返回token */ - String getAppAuthToken(); + default String getAppAuthToken() { + return getParameter(APP_AUTH_TOKEN_NAME); + } /** * 返回回调地址 * * @return 返回回调地址 */ - String getNotifyUrl(); + default String getNotifyUrl() { + return getParameter(NOTIFY_URL_NAME); + } } diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java index 1a0c91ba..e272eb18 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java @@ -1,32 +1,15 @@ package com.gitee.sop.servercommon.bean; -import com.alibaba.fastjson.JSONObject; -import org.apache.commons.lang3.time.DateUtils; - -import java.text.ParseException; -import java.util.Date; import java.util.Map; -import static com.gitee.sop.servercommon.bean.ParamNames.API_NAME; -import static com.gitee.sop.servercommon.bean.ParamNames.APP_AUTH_TOKEN_NAME; -import static com.gitee.sop.servercommon.bean.ParamNames.APP_KEY_NAME; -import static com.gitee.sop.servercommon.bean.ParamNames.BIZ_CONTENT_NAME; -import static com.gitee.sop.servercommon.bean.ParamNames.CHARSET_NAME; -import static com.gitee.sop.servercommon.bean.ParamNames.FORMAT_NAME; -import static com.gitee.sop.servercommon.bean.ParamNames.NOTIFY_URL_NAME; -import static com.gitee.sop.servercommon.bean.ParamNames.SIGN_TYPE_NAME; -import static com.gitee.sop.servercommon.bean.ParamNames.TIMESTAMP_NAME; -import static com.gitee.sop.servercommon.bean.ParamNames.TIMESTAMP_PATTERN; -import static com.gitee.sop.servercommon.bean.ParamNames.VERSION_NAME; - /** * @author tanghc */ public class OpenContextImpl implements OpenContext { - private final JSONObject requestParams; + private final Map requestParams; private Object bizObject; - public OpenContextImpl(JSONObject requestParams) { + public OpenContextImpl(Map requestParams) { this.requestParams = requestParams; } @@ -34,77 +17,16 @@ public class OpenContextImpl implements OpenContext { this.bizObject = bizObject; } - @Override - public String getParameter(String name) { - return requestParams.getString(name); - } - @Override public Map getParameterMap() { return requestParams; } - @Override - public String getAppId() { - return requestParams.getString(APP_KEY_NAME); - } - @Override public Object getBizObject() { return bizObject; } - @Override - public String getBizContent() { - return requestParams.getString(BIZ_CONTENT_NAME); - } - - @Override - public String getCharset() { - return requestParams.getString(CHARSET_NAME); - } - - @Override - public String getMethod() { - return requestParams.getString(API_NAME); - } - - @Override - public String getVersion() { - return requestParams.getString(VERSION_NAME); - } - - @Override - public String getFormat() { - return requestParams.getString(FORMAT_NAME); - } - - @Override - public String getSignType() { - return requestParams.getString(SIGN_TYPE_NAME); - } - - @Override - public Date getTimestamp() { - String timestampStr = requestParams.getString(TIMESTAMP_NAME); - try { - return DateUtils.parseDate(timestampStr, TIMESTAMP_PATTERN); - } catch (ParseException e) { - return null; - } - } - - @Override - public String getAppAuthToken() { - return requestParams.getString(APP_AUTH_TOKEN_NAME); - } - - @Override - public String getNotifyUrl() { - return requestParams.getString(NOTIFY_URL_NAME); - } - - @Override public String toString() { return requestParams.toString();