From be19f870dc4c0bfcb3eba33b64057f2bbcdf5313 Mon Sep 17 00:00:00 2001 From: IT-xiaoXiong <774495953@qq.com> Date: Thu, 18 Nov 2021 15:42:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B3=95=E5=A4=A7=E5=A4=A7?= =?UTF-8?q?=E5=90=88=E5=90=8C=E8=AF=B7=E6=B1=82=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fadada/util/FaDDRequestUtils.java | 44 ++++++++++++++----- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/com/api/aiyh_pcn/fadada/util/FaDDRequestUtils.java b/com/api/aiyh_pcn/fadada/util/FaDDRequestUtils.java index 5bc9c3f..e539988 100644 --- a/com/api/aiyh_pcn/fadada/util/FaDDRequestUtils.java +++ b/com/api/aiyh_pcn/fadada/util/FaDDRequestUtils.java @@ -5,6 +5,8 @@ import aiyh.utils.httpUtil.HttpArgsType; import aiyh.utils.httpUtil.ResponeVo; import aiyh.utils.httpUtil.util.HttpUtils; import aiyh.utils.zwl.common.ToolUtil; +import cn.hutool.core.util.URLUtil; +import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSONObject; import com.api.aiyh_pcn.fadada.dao.FaDDServiceMapping; import com.fasterxml.jackson.core.JsonProcessingException; @@ -16,6 +18,7 @@ import weaver.aiyh_pcn.fadada.entity.FileInfo; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -38,11 +41,17 @@ public class FaDDRequestUtils { private final static ToolUtil TOOL_UTIL = new ToolUtil(); static { - header.put("appId", "100001"); + String appId = TOOL_UTIL.getSystemParamValue("FDD_appId"); + if(StringUtils.isNullOrEmpty(appId)){ + appId = "100001"; + TOOL_UTIL.writeErrorLog("查询到的FDD_appId为空!"); + } + header.put("appId", appId); header.put("signType", "SHA256"); String apiKey = TOOL_UTIL.getSystemParamValue("FDD_apiKey"); if(StringUtils.isNullOrEmpty(apiKey)){ apiKey = "TulQxnZSRKeHoQfmeZzOUzGn6KpTDkDK"; + TOOL_UTIL.writeErrorLog("查询到的FDD_apiKey为空!"); } header.put("apikey", apiKey); header.put("Content-Type", HttpArgsType.APPLICATION_JSON); @@ -144,7 +153,7 @@ public class FaDDRequestUtils { header.put("sign", builderSign(data)); ResponeVo responeVo = null; try { - responeVo = httpUtils.apiPost("https://apigwaws-lite.porsche-cloudservice.com/env-101/econtract/econtract/contract/api/v1/contract/sign/detail/view", + responeVo = httpUtils.apiPost("https://apigwaws.porsche-cloudservice.com/env-101/por-econtract/econtract/contract/api/v1/contract/sign/detail/view", data, null); TOOL_UTIL.writeDebuggerLog("查询合同状态:" + JSONObject.toJSONString(data)); TOOL_UTIL.writeDebuggerLog(responeVo.getEntityString() + "\n"); @@ -164,22 +173,30 @@ public class FaDDRequestUtils { "&signType=" + header.get("signType") + "×tamp=" + header.get("timestamp"); // System.out.println(signStr); - String appKey = "L7P59oqA2An0XgJ1LeMN0fRu1"; + String appKey = TOOL_UTIL.getSystemParamValue("FDD_appKey"); + if(StringUtils.isNullOrEmpty(appKey)){ + TOOL_UTIL.writeErrorLog("查询到的FDD_appKey为空!"); + appKey = "L7P59oqA2An0XgJ1LeMN0fRu1"; + } + TOOL_UTIL.writeErrorLog("app签名:" + appKey); + TOOL_UTIL.writeErrorLog("signStr:" + signStr); + TOOL_UTIL.writeDebuggerLog("请求头信息:" + JSONObject.toJSONString(header)); +// String appKey = "L7P59oqA2An0XgJ1LeMN0fRu1"; String sha256 = string2SHA256(signStr) + appKey; // System.out.println(sign); return Base64.getEncoder().encodeToString(string2SHA256(sha256).getBytes(StandardCharsets.UTF_8)); } public static String builderBizContent(Map data) { - String jsonString = JSONObject.toJSONString(data); + String jsonString = JSONUtil.toJsonStr(data); + TOOL_UTIL.writeDebuggerLog("bizContent进行JSON编码:" + jsonString); String encode = null; - try { - encode = URLEncoder.encode(jsonString, "UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - return null; - } - return Base64.getEncoder().encodeToString(encode.getBytes(StandardCharsets.UTF_8)); + // encode = URLEncoder.encode(jsonString, "UTF-8"); + encode = URLUtil.encodeAll(jsonString, StandardCharsets.UTF_8); + TOOL_UTIL.writeDebuggerLog("bizContent进行JSON编码后URLEncoder编码:" + encode); + String s = Base64.getEncoder().encodeToString(encode.getBytes(StandardCharsets.UTF_8)); + TOOL_UTIL.writeDebuggerLog("bizContent进行JSON编码后URLEncoder编码后进行base64编码:" + s); + return s; } private static String string2SHA256(String str) { @@ -189,10 +206,13 @@ public class FaDDRequestUtils { messageDigest = MessageDigest.getInstance("SHA-256"); byte[] hash = messageDigest.digest(str.getBytes(StandardCharsets.UTF_8)); encdeStr = Hex.encodeHexString(hash); + TOOL_UTIL.writeDebuggerLog("进行SHA-256加密:" + encdeStr); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } - return encdeStr.toUpperCase(); + String s = encdeStr.toUpperCase(); + TOOL_UTIL.writeDebuggerLog("进行SHA-256加密后转为全大写:" + s); + return s; } }