From 861890b642315f9c5ed7ffaa5c127385e823ab1f Mon Sep 17 00:00:00 2001 From: YIN Date: Wed, 22 Jan 2025 16:34:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E5=BD=93=E5=89=8D=E8=AE=A2=E5=8D=95=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cpxt-admin/pom.xml | 5 ++ .../biz/orderutil/cityDelivery.java | 59 ++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/cpxt-admin/pom.xml b/cpxt-admin/pom.xml index c129ca1..f8b2dc8 100644 --- a/cpxt-admin/pom.xml +++ b/cpxt-admin/pom.xml @@ -80,6 +80,11 @@ guava 33.0.0-jre + + com.alibaba + fastjson + 2.0.4 + diff --git a/cpxt-admin/src/main/java/com/cpxt/web/controller/biz/orderutil/cityDelivery.java b/cpxt-admin/src/main/java/com/cpxt/web/controller/biz/orderutil/cityDelivery.java index 5bc79b1..d78e1e1 100644 --- a/cpxt-admin/src/main/java/com/cpxt/web/controller/biz/orderutil/cityDelivery.java +++ b/cpxt-admin/src/main/java/com/cpxt/web/controller/biz/orderutil/cityDelivery.java @@ -126,9 +126,66 @@ public class cityDelivery { System.out.println("sign:" + genSign); } + /** + * 同城急送平台工具,获取token + */ + @Anonymous + @GetMapping("/getToken2") + public void getTokenPostMan(){ + Long timeStamp = System.currentTimeMillis(); + String nonce = UUID.randomUUID().toString().replace("-",""); + System.out.println("timeStamp:" + timeStamp); + System.out.println("nonce:" + nonce); + //body + Map map = new HashMap(); + map.put("clientKey",clientKey); + map.put("clientSecret",clientSecret); + map.put("appType",appType); + map.put("clientType",client_type); + map.put("version",version); + + Map sortedParams1 = new TreeMap<>(map); + Set> entrySet1 = sortedParams1.entrySet(); + StringBuilder stringToSign = new StringBuilder(); + for (Map.Entry param : entrySet1) { + stringToSign.append(param.getKey()).append("=").append(param.getValue()).append(","); + } + + String encryptBase64 = cityDelivery_SM4Util.encryptCBC(stringToSign.toString(),clientSecret,sm4Key); + System.out.println("body:" + encryptBase64); + //签名 + Map sortedMap2 = new TreeMap<>(); + + //get请求,组装成 k v类型 +// sortedMap2.put(paramName,request.getParameter(paramName)); + /** + * post请求,需要放data + */ + Map bodyMap = new HashMap(); + bodyMap.put("body",encryptBase64); + String bodyJson = JSON.toJSONString(bodyMap); + sortedMap2.put("data", JSON.toJSONString(bodyJson)); + sortedMap2.put("access_id",clientKey); + sortedMap2.put("nonce", nonce); + sortedMap2.put("timestamp",timeStamp); + //排序 + Map sortedParams2 = new TreeMap<>(sortedMap2); + Set> entrySet2 = sortedParams2.entrySet(); + // 遍历排序后的字典,将所有参数按"key=value"格式拼接在一起 + StringBuilder stringToSign2 = new StringBuilder(); + for (Map.Entry param : entrySet2) { + stringToSign2.append(param.getKey()).append("=").append(param.getValue()).append(","); + } + stringToSign2.append("accessSecret").append("=").append(clientSecret); +// String genSign = DigestUtils.md5Hex(stringToSign2.toString()); + String genSign = cityDelivery_SM4Util.encryptCBC(stringToSign2.toString(),clientSecret,sm4Key); + System.out.println("------------"); + System.out.println("sign:" + genSign); + } + //获取token @Anonymous - @PostMapping("/getToken") + @GetMapping("/getToken") public void getToken(){ System.out.println("获取token"); String url = "https://wyjcs.gdwyj.cn/szelec/city-delivery-api/api/mini/app/login/token"; From 8de118b22e2e53b9e4c4c0ecb8026bf3ca1044e9 Mon Sep 17 00:00:00 2001 From: YIN Date: Thu, 23 Jan 2025 09:15:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=8E=A8=E9=80=81=E9=82=AE=E6=94=BF?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../biz/orderutil/cityDelivery.java | 98 ++++++++++++++++++- 1 file changed, 96 insertions(+), 2 deletions(-) diff --git a/cpxt-admin/src/main/java/com/cpxt/web/controller/biz/orderutil/cityDelivery.java b/cpxt-admin/src/main/java/com/cpxt/web/controller/biz/orderutil/cityDelivery.java index d78e1e1..e84a240 100644 --- a/cpxt-admin/src/main/java/com/cpxt/web/controller/biz/orderutil/cityDelivery.java +++ b/cpxt-admin/src/main/java/com/cpxt/web/controller/biz/orderutil/cityDelivery.java @@ -41,6 +41,98 @@ public class cityDelivery { * 同城急送平台工具,post接口 */ @Anonymous + @GetMapping("/getOrder") + public void cityDelivery_signBody22(){ + Long timeStamp = System.currentTimeMillis(); + String nonce = UUID.randomUUID().toString().replace("-",""); + System.out.println("nonce:"+nonce ); + System.out.println("timeStamp:"+timeStamp ); + //签名 + Map sortedMap = new TreeMap<>(); + //下单接口 + String body = "{\n" + + " \"customerCode\": \"HFCP\",\n" + + " \"payTypeFirst\": \"03\",\n" + + " \"channelOrderNo\": \"Y202501021005-1\",\n" + + " \"platformOrderNo\": \"\",\n" + + " \"expressNbr\": \"\",\n" + + " \"coordinateTransformType\": \"02\",\n" + + " \"weight\": \"501\",\n" + + " \"expectedTime\": \"2025-01-22,18:12:00\",\n" + + " \"postageFee\": \"2000\",\n" + +// " \"convertFlag\": false,\n" + + " \"orderSource\": \"other\",\n" + + " \"orderSourcePlatform\": \"其他\",\n" + + " \"costFee\": \"0\",\n" + + " \"tipFee\": \"0\",\n" + + " \"insuredFee\": \"0\",\n" + + " \"otherFee1\": \"0\",\n" + + " \"otherFee2\": \"0\",\n" + + " \"packageDesc\": \"药品\",\n" + + " \"remark\": \"手机尾号1234\",\n" + + " \"addressFirst\": {\n" + + " \"senderProviceCode\": \"340000\",\n" + + " \"senderProviceName\": \"安徽省\",\n" + + " \"senderCityCode\": \"340100\",\n" + + " \"senderCityName\": \"合肥市\",\n" + + " \"senderCountyCode\": \"340102\",\n" + + " \"senderCountyName\": \"瑶海区\",\n" + + " \"senderContactName\": \"中山三院\",\n" + + " \"senderContactPhone\": \"17523029470\",\n" + + " \"senderLongitude\": \"117.307179\",\n" + + " \"senderLatitude\": \"31.856484\",\n" + + " \"senderStreetCode\": \"001\",\n" + + " \"senderStreetName\": \"明光路街道\",\n" + + " \"senderAddr\": \"明光路188号\",\n" + + " \"receiverProviceCode\": \"340000\",\n" + + " \"receiverProviceName\": \"安徽省\",\n" + + " \"receiverCityCode\": \"340100\",\n" + + " \"receiverCityName\": \"合肥市\",\n" + + " \"receiverCountyCode\": \"340103\",\n" + + " \"receiverCountyName\": \"庐阳区\",\n" + + " \"receiverContactName\": \"陈先生\",\n" + + " \"receiverContactPhone\": \"13711511111\",\n" + + " \"receiverAddr\": \"信源大厦20楼2007\",\n" + + " \"receiverLongitude\": \"117.285075\",\n" + + " \"receiverLatitude\": \"31.882703\",\n" + + " \"receiverStreetCode\": \"002\",\n" + + " \"receiverStreetName\": \"双岗街道\"\n" + + " },\n" + + " \"businessJson\": {\n" + +// " \"a\": \"a\",\n" + +// " \"b\": \"b\"\n" + + " }\n" + + "}"; + //查询物流轨迹 +// String body = "{\n" + +// " \"expressNbr\": \"1158114584567\",\n" + +// " \"channelOrderNo\": \"\"\n" + +// "}"; + //get请求,组装成 k v类型 +// sortedMap.put(paramName,request.getParameter(paramName)); + /** + * post请求,需要放data + */ + String bodyjson = JSON.toJSONString(StrUtil.removeAll(body, specialChars)); + System.out.println("bodyjson: " + bodyjson); + + sortedMap.put("data", JSON.toJSONString(StrUtil.removeAll(body, specialChars))); + sortedMap.put("access_id",clientKey); + sortedMap.put("nonce", nonce); + sortedMap.put("timestamp",timeStamp); + //排序 + Map sortedParams = new TreeMap<>(sortedMap); + Set> entrySet = sortedParams.entrySet(); + // 遍历排序后的字典,将所有参数按"key=value"格式拼接在一起 + StringBuilder stringToSign = new StringBuilder(); + for (Map.Entry param : entrySet) { + stringToSign.append(param.getKey()).append("=").append(param.getValue()).append(","); + } + stringToSign.append("accessSecret").append("=").append(clientSecret); + String genSign = cityDelivery_SM4Util.encryptCBC(stringToSign.toString(),clientSecret,sm4Key); + System.out.println("sign:" + genSign); + } + public void cityDelivery_signBody2(){ Long timeStamp = System.currentTimeMillis(); String nonce = UUID.randomUUID().toString().replace("-",""); @@ -50,11 +142,11 @@ public class cityDelivery { Map sortedMap = new TreeMap<>(); //下单接口 String body = "{\n" + - " \"customerCode\": \"GZHX\",\n" + + " \"customerCode\": \"HFCP\",\n" + " \"payTypeFirst\": \"03\",\n" + " \"convertFlag\": false,\n" + " \"weight\": \"501\",\n" + - " \"expectedTime\": \"2024-11-11 12:12:00\",\n" + + " \"expectedTime\": \"2025-01-22 18:12:00\",\n" + " \"platformOrderNo\": \"\",\n" + " \"channelOrderNo\": \"\",\n" + " \"orderSource\": \"meituan\",\n" + @@ -109,6 +201,8 @@ public class cityDelivery { /** * post请求,需要放data */ + String bodyjson = JSON.toJSONString(StrUtil.removeAll(body, specialChars)); + System.out.println("bodyjson :" + bodyjson); sortedMap.put("data", JSON.toJSONString(StrUtil.removeAll(body, specialChars))); sortedMap.put("access_id",clientKey); sortedMap.put("nonce", nonce);