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);