From 462bfe45f2bd766330db2aa9f4a5abbaa086853b Mon Sep 17 00:00:00 2001 From: CZT <czt18638530771@163.com> Date: 星期一, 23 十月 2023 19:51:37 +0800 Subject: [PATCH] 武汉省平台接口-调整接口封装 --- src/main/java/com/fzzy/push/whhpjl/WhjlApiRemoteService.java | 61 +++--- src/main/java/com/fzzy/otherview/whhpjl/pr/WhjlApi1101PR.java | 29 +- src/main/java/com/fzzy/api/entity/ApiConfs.java | 4 src/main/java/com/fzzy/conf/RestTemplateConfig.java | 35 ++++ src/main/java/com/fzzy/api/utils/SM4Util.java | 201 +++++++++++++++++++++++++ src/main/java/com/fzzy/push/whhpjl/dto/WhjlReqDto.java | 4 src/main/java/com/fzzy/push/whhpjl/Whjl2023HttpClientUtil.java | 89 +++-------- src/main/java/com/fzzy/api/view/ApiConfs.view.xml | 11 + 8 files changed, 322 insertions(+), 112 deletions(-) diff --git a/src/main/java/com/fzzy/api/entity/ApiConfs.java b/src/main/java/com/fzzy/api/entity/ApiConfs.java index bc6d3aa..56cf737 100644 --- a/src/main/java/com/fzzy/api/entity/ApiConfs.java +++ b/src/main/java/com/fzzy/api/entity/ApiConfs.java @@ -62,6 +62,10 @@ @Column(name = "publicKey", length = 200) private String publicKey; + @PropertyDef(label = "鎺堟潈鐮�") + @Column(name = "appCode", length = 50) + private String appCode; + @PropertyDef(label = "鐪佸钩鍙版帴鍙e湴鍧�") @Column(name = "apiUrl", length = 200) private String apiUrl; diff --git a/src/main/java/com/fzzy/api/utils/SM4Util.java b/src/main/java/com/fzzy/api/utils/SM4Util.java new file mode 100644 index 0000000..1ba7bd4 --- /dev/null +++ b/src/main/java/com/fzzy/api/utils/SM4Util.java @@ -0,0 +1,201 @@ +package com.fzzy.api.utils; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; +import org.bouncycastle.util.encoders.Hex; + +import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; +import javax.crypto.spec.SecretKeySpec; +import java.security.Key; +import java.security.SecureRandom; +import java.security.Security; +import java.util.Arrays; + +/** + * @Author: huangyucai + * @Date: 2022/10/31 + * @Desc: + **/ +public class SM4Util { + + static { + Security.addProvider(new BouncyCastleProvider()); + } + + private static final String ENCODING = "UTF-8"; + public static final String ALGORITHM_NAME = "SM4"; + // 鍔犲瘑绠楁硶/鍒嗙粍鍔犲瘑妯″紡/鍒嗙粍濉厖鏂瑰紡 + // PKCS5Padding-浠�8涓瓧鑺備负涓�缁勮繘琛屽垎缁勫姞瀵� + // 瀹氫箟鍒嗙粍鍔犲瘑妯″紡浣跨敤锛歅KCS5Padding + public static final String ALGORITHM_NAME_ECB_PADDING = "SM4/ECB/PKCS5Padding"; + // 128-32浣�16杩涘埗锛�256-64浣�16杩涘埗 + public static final int DEFAULT_KEY_SIZE = 128; + + /** + * 鑷姩鐢熸垚瀵嗛挜锛�16杩涘埗瀛楃涓诧紝闀垮害32锛� + * + * @return + * @explain + */ + public static String generateKey() throws Exception { + return Hex.toHexString(generateKey(DEFAULT_KEY_SIZE)); + } + + /** + * @param keySize + * @return + * @throws Exception + * @explain + */ + public static byte[] generateKey(int keySize) throws Exception { + KeyGenerator kg = KeyGenerator.getInstance(ALGORITHM_NAME, BouncyCastleProvider.PROVIDER_NAME); + kg.init(keySize, new SecureRandom()); + return kg.generateKey().getEncoded(); + } + + /** + * 鐢熸垚ECB鏆楀彿 + * + * @param algorithmName 绠楁硶鍚嶇О + * @param mode 妯″紡 + * @param key + * @return + * @throws Exception + * @explain ECB妯″紡锛堢數瀛愬瘑鐮佹湰妯″紡锛欵lectronic codebook锛� + */ + private static Cipher generateEcbCipher(String algorithmName, int mode, byte[] key) throws Exception { + Cipher cipher = Cipher.getInstance(algorithmName, BouncyCastleProvider.PROVIDER_NAME); + Key sm4Key = new SecretKeySpec(key, ALGORITHM_NAME); + cipher.init(mode, sm4Key); + return cipher; + } + + /** + * sm4鍔犲瘑 + * + * @param hexKey 16杩涘埗瀵嗛挜锛堝拷鐣ュぇ灏忓啓锛� + * @param paramStr 寰呭姞瀵嗗瓧绗︿覆 + * @return 杩斿洖16杩涘埗鐨勫姞瀵嗗瓧绗︿覆 + * @explain 鍔犲瘑妯″紡锛欵CB + * 瀵嗘枃闀垮害涓嶅浐瀹氾紝浼氶殢鐫�琚姞瀵嗗瓧绗︿覆闀垮害鐨勫彉鍖栬�屽彉鍖� + */ + public static String encryptEcb(String hexKey, String paramStr) { + try { + String cipherText = ""; + // 16杩涘埗瀛楃涓�-->byte[] + byte[] keyData = ByteUtils.fromHexString(hexKey); + // String-->byte[] + byte[] srcData = paramStr.getBytes(ENCODING); + // 鍔犲瘑鍚庣殑鏁扮粍 + byte[] cipherArray = encrypt_Ecb_Padding(keyData, srcData); + // byte[]-->hexString + cipherText = ByteUtils.toHexString(cipherArray); + return cipherText; + } catch (Exception e) { + e.printStackTrace(); + return ""; + } + } + + /** + * 鍔犲瘑妯″紡涔婨cb + * + * @param key + * @param data + * @return + * @throws Exception + * @explain + */ + public static byte[] encrypt_Ecb_Padding(byte[] key, byte[] data) throws Exception { + Cipher cipher = generateEcbCipher(ALGORITHM_NAME_ECB_PADDING, Cipher.ENCRYPT_MODE, key); + return cipher.doFinal(data); + } + + /** + * sm4瑙e瘑 + * + * @param hexKey 16杩涘埗瀵嗛挜 + * @param cipherText 16杩涘埗鐨勫姞瀵嗗瓧绗︿覆锛堝拷鐣ュぇ灏忓啓锛� + * @return 瑙e瘑鍚庣殑瀛楃涓� + * @throws Exception + * @explain 瑙e瘑妯″紡锛氶噰鐢‥CB + */ + public static String decryptEcb(String hexKey, String cipherText) { + // 鐢ㄤ簬鎺ユ敹瑙e瘑鍚庣殑瀛楃涓� + String decryptStr = ""; + // hexString-->byte[] + byte[] keyData = ByteUtils.fromHexString(hexKey); + // hexString-->byte[] + byte[] cipherData = ByteUtils.fromHexString(cipherText); + // 瑙e瘑 + byte[] srcData = new byte[0]; + try { + srcData = decrypt_Ecb_Padding(keyData, cipherData); + // byte[]-->String + decryptStr = new String(srcData, ENCODING); + } catch (Exception e) { + } + return decryptStr; + } + + /** + * 瑙e瘑 + * + * @param key + * @param cipherText + * @return + * @throws Exception + * @explain + */ + public static byte[] decrypt_Ecb_Padding(byte[] key, byte[] cipherText) throws Exception { + Cipher cipher = generateEcbCipher(ALGORITHM_NAME_ECB_PADDING, Cipher.DECRYPT_MODE, key); + return cipher.doFinal(cipherText); + } + + /** + * 鏍¢獙鍔犲瘑鍓嶅悗鐨勫瓧绗︿覆鏄惁涓哄悓涓�鏁版嵁 + * + * @param hexKey 16杩涘埗瀵嗛挜锛堝拷鐣ュぇ灏忓啓锛� + * @param cipherText 16杩涘埗鍔犲瘑鍚庣殑瀛楃涓� + * @param paramStr 鍔犲瘑鍓嶇殑瀛楃涓� + * @return 鏄惁涓哄悓涓�鏁版嵁 + * @throws Exception + * @explain + */ + public static boolean verifyEcb(String hexKey, String cipherText, String paramStr) throws Exception { + // 鐢ㄤ簬鎺ユ敹鏍¢獙缁撴灉 + boolean flag = false; + // hexString-->byte[] + byte[] keyData = ByteUtils.fromHexString(hexKey); + // 灏�16杩涘埗瀛楃涓茶浆鎹㈡垚鏁扮粍 + byte[] cipherData = ByteUtils.fromHexString(cipherText); + // 瑙e瘑 + byte[] decryptData = decrypt_Ecb_Padding(keyData, cipherData); + // 灏嗗師瀛楃涓茶浆鎹㈡垚byte[] + byte[] srcData = paramStr.getBytes(ENCODING); + // 鍒ゆ柇2涓暟缁勬槸鍚︿竴鑷� + flag = Arrays.equals(decryptData, srcData); + return flag; + } + + /* public static void main(String[] args) { + try { + String json = "{\"name\":\"jz\"}"; + System.out.println("鏄庢枃锛�" + json); + + // 鐢熸垚32浣�16杩涘埗瀵嗛挜 + String key = SM4Util.generateKey(); + System.out.println("瀵嗛挜锛�" + key); + + String cipher = SM4Util.encryptEcb(key, json); + System.out.println("瀵嗘枃锛�" + cipher); + + System.out.println("鏁版嵁鏄惁鏈夋晥锛�" + SM4Util.verifyEcb(key, cipher, json)); + + String res = SM4Util.decryptEcb(key, cipher); + System.out.println("瑙e瘑鍚庢暟鎹細" + res); + } catch (Exception e) { + e.printStackTrace(); + } + }*/ +} diff --git a/src/main/java/com/fzzy/api/view/ApiConfs.view.xml b/src/main/java/com/fzzy/api/view/ApiConfs.view.xml index e07d98e..e641034 100644 --- a/src/main/java/com/fzzy/api/view/ApiConfs.view.xml +++ b/src/main/java/com/fzzy/api/view/ApiConfs.view.xml @@ -27,6 +27,10 @@ <Property></Property> <Property name="label">鐪佸钩鍙板姞瀵嗗叕閽�</Property> </PropertyDef> + <PropertyDef name="appCode"> + <Property></Property> + <Property name="label">鎺堟潈鐮�</Property> + </PropertyDef> <PropertyDef name="apiUrl"> <Property></Property> <Property name="label">鐪佸钩鍙版帴鍙e湴鍧�</Property> @@ -426,13 +430,18 @@ <Property name="labelWidth">120</Property> <Editor/> </AutoFormElement> - <AutoFormElement layoutConstraint="colSpan:2"> + <AutoFormElement> <Property name="name">publicKey</Property> <Property name="property">publicKey</Property> <Property name="labelWidth">125</Property> <Editor/> </AutoFormElement> <AutoFormElement> + <Property name="name">appCode</Property> + <Property name="property">appCode</Property> + <Editor/> + </AutoFormElement> + <AutoFormElement> <Property name="name">pushProtocol</Property> <Property name="property">pushProtocol</Property> <Property name="labelWidth">125</Property> diff --git a/src/main/java/com/fzzy/conf/RestTemplateConfig.java b/src/main/java/com/fzzy/conf/RestTemplateConfig.java new file mode 100644 index 0000000..85d6b8a --- /dev/null +++ b/src/main/java/com/fzzy/conf/RestTemplateConfig.java @@ -0,0 +1,35 @@ +package com.fzzy.conf; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.ClientHttpRequestFactory; +import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.http.converter.StringHttpMessageConverter; +import org.springframework.web.client.RestTemplate; + +import java.nio.charset.StandardCharsets; + +/** + * RestTemplate鐨勯厤缃紝SpringBoot灏佽鐨凥TTP鍗忚锛孏ET鍜孭OST璇锋眰鏂规硶 + * + * @author Andy + * + */ +@Configuration +public class RestTemplateConfig { + + @Bean + public RestTemplate restTemplate(ClientHttpRequestFactory factory) { + RestTemplate restTemplate = new RestTemplate(factory); + restTemplate.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8)); + return restTemplate; + } + + @Bean + public ClientHttpRequestFactory simpleClientHttpRequestFactory() { + SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); + factory.setConnectTimeout(15000);// 璁剧疆杩炴帴瓒呮椂锛屽崟浣嶆绉� + factory.setReadTimeout(15000);//璁剧疆璇诲彇瓒呮椂 + return factory; + } +} diff --git a/src/main/java/com/fzzy/otherview/whhpjl/pr/WhjlApi1101PR.java b/src/main/java/com/fzzy/otherview/whhpjl/pr/WhjlApi1101PR.java index 31dff23..84dcc8b 100644 --- a/src/main/java/com/fzzy/otherview/whhpjl/pr/WhjlApi1101PR.java +++ b/src/main/java/com/fzzy/otherview/whhpjl/pr/WhjlApi1101PR.java @@ -18,6 +18,7 @@ import com.fzzy.otherview.whhpjl.dto.WhjlApi1101; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; + import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -46,7 +47,7 @@ @DataProvider public List<WhjlApi1101> listData() { List<ApiInfoData> result = apiInfoDataRep.getDataByInteId(WhjlConstant.API_CODE_1101); - if(null == result ||result.isEmpty()){ + if (null == result || result.isEmpty()) { return null; } List<WhjlApi1101> list = new ArrayList<>(); @@ -107,30 +108,31 @@ */ @Expose public String pushData(List<WhjlApi1101> items) { - ResponseDto responseDto; + String result = ""; String kqdm = items.get(0).getKqdm(); ApiConfs apiConf = apiCommonService.getConf(kqdm); - if (null == apiConf) return "绯荤粺娌℃湁鑾峰彇鍒板綋鍓嶅簱鍖洪厤缃俊鎭紝鎵ц澶辫触"; + if (null == apiConf) { + return "绯荤粺娌℃湁鑾峰彇鍒板綋鍓嶅簱鍖洪厤缃俊鎭紝鎵ц澶辫触"; + } //灏佽鍙傛暟 ApiParam param = new ApiParam(apiConf, WhjlConstant.API_CATEGORY_11, WhjlConstant.API_CODE_1101); //鑾峰彇瀹炵幇鎺ュ彛 ApiRemoteService apiService = apiPushManager.getApiRemoteService(param.getPushProtocol()); - if (null == apiService) return "绯荤粺娌℃湁褰撳墠鎺ㄩ�佸崗璁厤缃紝鎵ц澶辫触"; + if (null == apiService) { + return "绯荤粺娌℃湁褰撳墠鎺ㄩ�佸崗璁厤缃紝鎵ц澶辫触"; + } - //鎺ㄩ�侊紝鏁版嵁涓洪泦鍚堝舰寮� - responseDto = apiService.pushData(param, apiConf, items); - if (responseDto.getSuccess() == 0) { - //鎺ㄩ�佹垚鍔燂紝鏇存柊鏁版嵁涓婁紶鐘舵�� - - ApiInfoData infoData; - for (WhjlApi1101 data : items) { - if(Constant.CZBZ_I.equals(data.getCzbz())){ - + ResponseDto responseDto; + ApiInfoData infoData; + for (WhjlApi1101 data : items) { + responseDto = apiService.pushData(param, apiConf, items); + if (responseDto.getSuccess() == 0) { + if (Constant.CZBZ_I.equals(data.getCzbz())) { infoData = new ApiInfoData(); infoData.setId(data.getBizId()); infoData.setKqdm(data.getKqdm()); @@ -142,7 +144,6 @@ data.setCzbz(Constant.CZBZ_U); infoData.setCzbz(Constant.CZBZ_U); infoData.setData(JSON.toJSONString(data)); - apiInfoDataRep.save(infoData); } } diff --git a/src/main/java/com/fzzy/push/whhpjl/Whjl2023HttpClientUtil.java b/src/main/java/com/fzzy/push/whhpjl/Whjl2023HttpClientUtil.java index 8476f64..ab3f144 100644 --- a/src/main/java/com/fzzy/push/whhpjl/Whjl2023HttpClientUtil.java +++ b/src/main/java/com/fzzy/push/whhpjl/Whjl2023HttpClientUtil.java @@ -1,89 +1,50 @@ package com.fzzy.push.whhpjl; import com.alibaba.fastjson.JSON; -import com.fzzy.api.entity.ApiConfs; import com.fzzy.push.whhpjl.dto.WhjlReqDto; import com.fzzy.push.whhpjl.dto.WhjlRespDto; import lombok.extern.slf4j.Slf4j; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; /** * 姝︽眽鍐涚伯鐪佸钩鍙�-涓婁紶鏁版嵁鏈嶅姟绫� + * * @author czt - * @date 2023/08/04 + * @date 2023/10/23 */ @Slf4j +@Component public class Whjl2023HttpClientUtil { + @Autowired + private RestTemplate restTemplate; + + /** - * post formData + * 鏁版嵁涓婃姤post璇锋眰 * @param url + * @param reqData * @return - * @throws Exception */ - @SuppressWarnings("resource") - public static WhjlRespDto postPushData(String url, WhjlReqDto reqData , ApiConfs apiConfs) throws Exception { - log.info("---------鎺ュ彛璇锋眰鍦板潃锛�" +url+ "----------鍙傛暟锛�" + reqData.toString() +"---------"); - BufferedReader in = null; - URL urls = new URL(url); - HttpURLConnection connection = null; - OutputStream outputStream = null; + public WhjlRespDto postPushData(String url, WhjlReqDto reqData) { + log.info("---------鎺ュ彛璇锋眰鍦板潃锛�" + url + "----------鍙傛暟锛�" + JSON.toJSONString(reqData) + "---------"); String rs = ""; WhjlRespDto responseDto; + try { + rs = restTemplate.postForObject(url, reqData, String.class); - connection = (HttpURLConnection) urls.openConnection(); - connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); - connection.setDoOutput(true); - connection.setDoInput(true); - connection.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.8"); - connection.setRequestProperty("Accept", "*/*"); - connection.setRequestProperty("Range", "bytes=" + ""); - connection.setConnectTimeout(20000); - connection.setReadTimeout(30000); - connection.setRequestMethod("POST"); - - outputStream = connection.getOutputStream(); - outputStream.write(reqData.toString().getBytes("UTF-8")); - try { - connection.connect(); - if (connection.getResponseCode() == 200) { - in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); - String line = ""; - while ((line = in.readLine()) != null) { - rs += line; - } - }else{ - log.error("http鐘舵�侊細" + connection.getResponseCode()); - log.error("http娑堟伅锛�" + connection.getResponseMessage()); - } - - } catch (Exception e) { - System.out.println("鍙戠敓寮傚父"); - log.error(e.getMessage(),e); - rs = null; - return new WhjlRespDto(99,e.getMessage()); - } - log.info("---------鎺ュ彛杩斿洖锛�" + rs +"---------"); - responseDto = JSON.parseObject(rs,WhjlRespDto.class); - if(responseDto == null ) return new WhjlRespDto(99,"鎺ュ彛璇锋眰鍙戠敓鏈煡閿欒"); - return responseDto; - } finally { - try { - outputStream.close(); - if (in != null){ - in.close(); - } - } catch (Exception e) { - } - outputStream = null; - if (connection != null) - connection.disconnect(); - connection = null; + } catch (Exception e) { + System.out.println("鍙戠敓寮傚父"); + log.error(e.getMessage(), e); + rs = null; + return new WhjlRespDto(99, e.getMessage()); } + log.info("---------鎺ュ彛杩斿洖锛�" + rs + "---------"); + responseDto = JSON.parseObject(rs, WhjlRespDto.class); + if (responseDto == null) return new WhjlRespDto(99, "鎺ュ彛璇锋眰鍙戠敓鏈煡閿欒"); + return responseDto; } } \ No newline at end of file diff --git a/src/main/java/com/fzzy/push/whhpjl/WhjlApiRemoteService.java b/src/main/java/com/fzzy/push/whhpjl/WhjlApiRemoteService.java index d5b1b13..01e6be7 100644 --- a/src/main/java/com/fzzy/push/whhpjl/WhjlApiRemoteService.java +++ b/src/main/java/com/fzzy/push/whhpjl/WhjlApiRemoteService.java @@ -39,6 +39,8 @@ private ApiTriggerService apiTriggerService; @Autowired private ApiLogRep apiLogRep; + @Autowired + private Whjl2023HttpClientUtil whjl2023HttpClientUtil; @Override public String getProtocol() { @@ -64,7 +66,7 @@ ApiLog apiLog = new ApiLog(); apiLog.setId(ContextUtil.getUUID()); apiLog.setInteId(inteId); - String jsonData = getJsonData(inteId, data); + String jsonData = getJsonData(data); log.info("鎺ュ彛鏁版嵁淇℃伅=" + jsonData); inteId = getInteId(inteId); if (StringUtils.isEmpty(inteId)) { @@ -86,42 +88,38 @@ return responseDto; } + //灏佽鎺ㄩ�佹暟鎹� + WhjlReqDto reqData = new WhjlReqDto(); + //鎶ユ枃鏍囪瘑ID + reqData.setId(ContextUtil.getUUID()); + //韬唤ID + reqData.setUid(conf.getUserName()); //鑾峰彇鎸囦护id String key = RedisConst.buildKey(RedisConst.KYE_ORDER, conf.getKqdm()); String orderId = (String)redisUtil.get(key); if(StringUtils.isEmpty(orderId)){ - ResponseDto responseDto = new ResponseDto(99, "鎸囦护id澶辨晥"); - apiLog.setStatus(99); - apiLog.setResult("鎸囦护id澶辨晥"); - apiLogRep.save(apiLog); - return responseDto; + orderId = reqData.getId(); } - - //灏佽鎺ㄩ�佹暟鎹� - WhjlReqDto reqData = new WhjlReqDto(); - reqData.setId(ContextUtil.getUUID()); - reqData.setUid(conf.getKqdm()); - //鎸囦护ID reqData.setOrderid(orderId); - reqData.setAppcode(conf.getUserName()); - reqData.setTimestamp(ContextUtil.getCurTimeMillis()); + //搴旂敤鐮� + reqData.setAppcode(conf.getAppCode()); + //鏃堕棿鎴� + reqData.setTimestamp(Long.valueOf(ContextUtil.getCurTimeMillis())); + //韬唤绛惧悕锛屽搴旂敤鐮乢鎺堟潈鐮乢绔欑偣缂栫爜_鎶ユ枃ID_鏃堕棿鎴宠繘琛孧D5绠楁硶绛惧悕 + String accessToken = reqData.getAppcode() +"_" + conf.getPassword() +"_" + reqData.getUid() + "_" + reqData.getId() + "_" + reqData.getTimestamp(); + log.info("韬唤绛惧悕锛�" + accessToken); + reqData.setAccesstoken(MyMD5Util.encrypt(accessToken)); + //鏁版嵁鎬绘潯鏁� List<Object> list = (List<Object>)data; reqData.setDatalength(list.size()); - //鏁版嵁杩涜SM4鍔犲瘑 - reqData.setData(AESUtils.encrypt(jsonData, conf.getPublicKey())); - reqData.setOperator("insert"); + //鏁版嵁涓讳綋锛岃繘琛孲M4鍔犲瘑 + reqData.setData(SM4Util.encryptEcb(conf.getPublicKey(), jsonData)); //鎽樿锛屾暟鎹富浣撶殑MD5鍊� - reqData.setDigst(MyMD5Util.encrypt(jsonData)); - //韬唤绛惧悕锛屽搴旂敤鐮乢鎺堟潈鐮乢绔欑偣缂栫爜_鎶ユ枃ID_鏃堕棿鎴宠繘琛孧D5绠楁硶绛惧悕 - StringBuffer buffer = new StringBuffer(); - buffer.append(reqData.getAppcode()).append("_"); - buffer.append(conf.getPublicKey()).append("_"); - buffer.append(conf.getKqmc()).append("_"); - buffer.append(reqData.getId()).append("_"); - buffer.append(reqData.getTimestamp()); - reqData.setDigst(MyMD5Util.encrypt(buffer.toString())); + reqData.setDigest(MyMD5Util.encrypt(jsonData)); + //鎿嶄綔绫诲瀷 + reqData.setOperator("insert"); - WhjlRespDto responseDto = Whjl2023HttpClientUtil.postPushData(conf.getApiUrl() + inteId, reqData, conf); + WhjlRespDto responseDto = whjl2023HttpClientUtil.postPushData(conf.getApiUrl() + inteId, reqData); apiLog.setStatus(responseDto.getCode() == 200 ? 0 : responseDto.getCode()); apiLog.setResult(responseDto.getResult()); apiLogRep.save(apiLog); @@ -137,15 +135,16 @@ } /** - * 璋冩暣鏁版嵁灏佽锛岃幏鍙杍son鏁版嵁 + * 璋冩暣鏁版嵁灏佽鎴恖ist锛岃幏鍙杍son鏁版嵁 * - * @param inteId * @param data * @return * @throws Exception */ - private String getJsonData(String inteId, Object data) { - return JSON.toJSONString(data); + private String getJsonData(Object data) { + List<Object> list = new ArrayList<>(); + list.add(data); + return JSON.toJSONString(list); } private String getInteId(String inteId) { diff --git a/src/main/java/com/fzzy/push/whhpjl/dto/WhjlReqDto.java b/src/main/java/com/fzzy/push/whhpjl/dto/WhjlReqDto.java index f624170..86abf9a 100644 --- a/src/main/java/com/fzzy/push/whhpjl/dto/WhjlReqDto.java +++ b/src/main/java/com/fzzy/push/whhpjl/dto/WhjlReqDto.java @@ -35,7 +35,7 @@ /** * 鏃堕棿鎴� */ - private String timestamp; + private Long timestamp; /** * 韬唤绛惧悕 @@ -55,7 +55,7 @@ /** * 鏁版嵁鎽樿 */ - private String digst; + private String digest; /** * 鎿嶄綔绫诲瀷 -- Gitblit v1.9.3