From be5209453b6049fdf35b73ac9737546260a9c2c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B7=AF=E6=98=8E=E6=85=A7?= <1191093413@qq.com> Date: Tue, 2 Jan 2024 15:43:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=A2=E5=AD=97=E4=BF=A1=E6=81=AF=E5=8D=95?= =?UTF-8?q?=E3=80=81=E4=BA=BA=E8=84=B8=E8=AF=86=E5=88=AB=E4=BA=8C=E7=BB=B4?= =?UTF-8?q?=E7=A0=81=E4=BC=A0=E5=85=A5=E5=8F=82=E6=95=B0key=E5=B0=8F?= =?UTF-8?q?=E5=86=99=E8=BD=AC=E5=8C=96=E4=B8=BA=E5=A4=A7=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jianshui/common/constant/Constants.java | 8 ++ .../jianshui/common/utils/JsonKeyCase.java | 97 +++++++++++++++++++ .../api/ElephantInvoiceApiV6ServiceImpl.java | 22 ++++- 3 files changed, 123 insertions(+), 4 deletions(-) create mode 100644 jianshui-common/src/main/java/com/jianshui/common/utils/JsonKeyCase.java diff --git a/jianshui-common/src/main/java/com/jianshui/common/constant/Constants.java b/jianshui-common/src/main/java/com/jianshui/common/constant/Constants.java index 647842c..0a3d7f9 100644 --- a/jianshui-common/src/main/java/com/jianshui/common/constant/Constants.java +++ b/jianshui-common/src/main/java/com/jianshui/common/constant/Constants.java @@ -158,4 +158,12 @@ public class Constants { * 服务管理 cache key */ public static final String SERVICE_MANAGE = "service_manage:"; + + public static final int INT_0 = 0; + + public static final String JSONObject = "JSONObject"; + + public static final String JSONArray = "JSONArray"; + + } \ No newline at end of file diff --git a/jianshui-common/src/main/java/com/jianshui/common/utils/JsonKeyCase.java b/jianshui-common/src/main/java/com/jianshui/common/utils/JsonKeyCase.java new file mode 100644 index 0000000..20f9ce9 --- /dev/null +++ b/jianshui-common/src/main/java/com/jianshui/common/utils/JsonKeyCase.java @@ -0,0 +1,97 @@ +package com.jianshui.common.utils; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.jianshui.common.constant.Constants; + +public class JsonKeyCase { + + /* + * 默认转大写 + */ + public static JSONObject JsonKeyCase(JSONObject data){ + return JsonKeyCase(data,Constants.INT_0); + } + + /* + * json对象中的key转换 + */ + public static JSONObject JsonKeyCase(JSONObject data,int flag){ + + JSONObject newData = new JSONObject(); + + if(data == null ){ + return data; + } + + for (String key : data.keySet()) { + + Object value = data.get(key); + + String name = value.getClass().getName(); + + if (name.endsWith(Constants.JSONObject)){ + + value = JsonKeyCase((JSONObject) value,flag); + + + }else if (name.endsWith(Constants.JSONArray)){ + + value = arrayKeyrCase((JSONArray) value,flag); + + } + + String newKey; + + if (flag == Constants.INT_0) { + newKey = key.toUpperCase(); + }else { + newKey = key.toLowerCase(); + } + + newData.put(newKey, value); + } + + return newData; + + } + + /* + * 默认转大写 + */ + public static JSONArray arrayKeyrCase(JSONArray data){ + return arrayKeyrCase(data,Constants.INT_0); + } + + + /* + * jsonArray转换 + */ + + public static JSONArray arrayKeyrCase(JSONArray data,int flag){ + + if (data == null){ + return data; + } + + JSONArray newArray = new JSONArray(); + for (Object datum : data) { + + String name = datum.getClass().getName(); + + if (name.endsWith(Constants.JSONObject)){ + + datum = JsonKeyCase((JSONObject) datum,flag); + + }else if (name.endsWith(Constants.JSONArray)){ + + datum = arrayKeyrCase((JSONArray) datum,flag); + + } + newArray.add(datum); + } + + return newArray; + } + +} diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java index e77bd37..b2eeeba 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java @@ -25,10 +25,7 @@ import com.jianshui.common.enums.ErrorCode; import com.jianshui.common.exception.jianshui.JianshiSystemErrorException; import com.jianshui.common.exception.jianshui.JianshuiParamErrorException; import com.jianshui.common.exception.jianshui.JianshuiServiceException; -import com.jianshui.common.utils.DateUtils; -import com.jianshui.common.utils.StringUtils; -import com.jianshui.common.utils.TimeUtil; -import com.jianshui.common.utils.ValidateUtils; +import com.jianshui.common.utils.*; import com.jianshui.common.utils.http.HttpHelper; import com.jianshui.common.utils.spring.SpringUtils; import com.jianshui.common.utils.uuid.IdUtils; @@ -965,6 +962,8 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { @Override public HXResponse queryRedConfirmationList(JSONObject decryptResult, Companyservice companyservice) { + decryptResult = JsonKeyCase.JsonKeyCase(decryptResult); + log.info("调用大象V6接口报文key转大写后的报文为{}",decryptResult); DxhyInterfaceResponse dxhyInterfaceResponse = null; try { dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.QUERY_RED_CONFIRMATION_LIST_LOCALHOST, ElephantConstantsV6.QUERY_RED_CONFIRMATION_LIST_METHOD, JSONUtil.parse(decryptResult), companyservice); @@ -987,6 +986,9 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { */ @Override public HXResponse queryRedConfirmationItemList(JSONObject decryptResult, Companyservice companyservice) { + + decryptResult = JsonKeyCase.JsonKeyCase(decryptResult); + log.info("调用大象V6接口报文key转大写后的报文为{}",decryptResult); DxhyInterfaceResponse dxhyInterfaceResponse = null; try { dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.QUERY_RED_CONFIRMATION_ITEM_LIST_LOCALHOST, ElephantConstantsV6.QUERY_RED_CONFIRMATION_ITEM_LIST_METHOD, JSONUtil.parse(decryptResult), companyservice); @@ -1008,6 +1010,9 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { */ @Override public HXResponse redConfirmationApply(JSONObject decryptResult, Companyservice companyservice) { + + decryptResult = JsonKeyCase.JsonKeyCase(decryptResult); + log.info("调用大象V6接口报文key转大写后的报文为{}",decryptResult); DxhyInterfaceResponse dxhyInterfaceResponse = null; try { dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.RED_CONFIRMATION_LOCALHOST, ElephantConstantsV6.RED_CONFIRMATION_METHOD, JSONUtil.parse(decryptResult), companyservice); @@ -1030,6 +1035,9 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { */ @Override public HXResponse redConfirmationConfirm(JSONObject decryptResult, Companyservice companyservice) { + + decryptResult = JsonKeyCase.JsonKeyCase(decryptResult); + log.info("调用大象V6接口报文key转大写后的报文为{}",decryptResult); DxhyInterfaceResponse dxhyInterfaceResponse = null; try { dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.RED_CONFIRMATION_CONFIRM_LOCALHOST, ElephantConstantsV6.RED_CONFIRMATION_CONFIRM_METHOD, JSONUtil.parse(decryptResult), companyservice); @@ -1051,6 +1059,9 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { */ @Override public HXResponse rpaLogin(JSONObject decryptResult, Companyservice companyservice) { + + decryptResult = JsonKeyCase.JsonKeyCase(decryptResult); + log.info("调用大象V6接口报文key转大写后的报文为{}",decryptResult); DxhyInterfaceResponse dxhyInterfaceResponse = null; try { dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.RPA_LOGIN_LOCALHOST, ElephantConstantsV6.RPA_LOGIN_METHOD, JSONUtil.parse(decryptResult), companyservice); @@ -1992,6 +2003,9 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { @Override public HXResponse qrcode(JSONObject decryptResult, Companyservice companyservice) { + + decryptResult = JsonKeyCase.JsonKeyCase(decryptResult); + log.info("调用大象V6接口报文key转大写后的报文为{}",decryptResult); DxhyInterfaceResponse dxhyInterfaceResponse = null; try { dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.GET_RPA_QY_CODE_LOCALHOST, ElephantConstantsV6.GET_RPA_QY_CODE_METHOD, JSONUtil.parse(decryptResult), companyservice);