From e948c3b71b54d731894714677d605bb7660b2834 Mon Sep 17 00:00:00 2001 From: YIN Date: Tue, 11 Feb 2025 11:18:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E9=80=81=E9=82=AE=E6=94=BF=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/biz/TestContrller.java | 116 ++++++++ .../com/cpxt/biz/orderutil/CityDelivery.java | 271 +++++++++--------- pom.xml | 2 +- 3 files changed, 254 insertions(+), 135 deletions(-) create mode 100644 cpxt-admin/src/main/java/com/cpxt/web/controller/biz/TestContrller.java diff --git a/cpxt-admin/src/main/java/com/cpxt/web/controller/biz/TestContrller.java b/cpxt-admin/src/main/java/com/cpxt/web/controller/biz/TestContrller.java new file mode 100644 index 0000000..db4f052 --- /dev/null +++ b/cpxt-admin/src/main/java/com/cpxt/web/controller/biz/TestContrller.java @@ -0,0 +1,116 @@ +package com.cpxt.web.controller.biz; + +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson2.JSON; +import com.cpxt.biz.orderutil.CityDelivery_SM4Util; +import com.cpxt.common.annotation.Anonymous; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.UUID; + +@RestController +@Slf4j +@RequestMapping("/test") +public class TestContrller { + private static final char[] specialChars = {'\n', '\r', '\t', '\f', '\b', ' '}; + + // test + String clientKey = "7480617400984563";//accessKey + String clientSecret = "91wCEvn82CeyMg3k"; + String sm4Key = "MJy05dcI4mPbGB61"; + String appType = "wxmp"; + String client_type = "other"; + String version = "1.0.0"; + + @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\": \"02\",\n" + + " \"channelOrderNo\": \"Y202501221001-1\",\n" + + " \"platformOrderNo\": \"\",\n" + + " \"expressNbr\": \"\",\n" + + " \"coordinateTransformType\": \"02\",\n" + + " \"weight\": \"1000\",\n" + + " \"expectedTime\": \"2025-02-10,21:00:00\",\n" + + " \"postageFee\": \"800\",\n" + + " \"orderSource\": \"other\",\n" + + " \"orderSourcePlatform\": \"其他\",\n" + + " \"costFee\": \"0\",\n" + + " \"tipFee\": \"0\",\n" + + " \"insuredFee\": \"0\",\n" + + " \"otherFee1\": \"0\",\n" + + " \"otherFee2\": \"0\",\n" + + " \"packageDesc\": \"食品\",\n" + + " \"remark\": \"\",\n" + + " \"addressFirst\": {\n" + + " \"senderProviceCode\": \"340000\",\n" + + " \"senderProviceName\": \"安徽省\",\n" + + " \"senderCityCode\": \"340100\",\n" + + " \"senderCityName\": \"合肥市\",\n" + + " \"senderCountyCode\": \"340121\",\n" + + " \"senderCountyName\": \"长丰县\",\n" + + " \"senderContactName\": \"巴莉甜甜工厂\",\n" + + " \"senderContactPhone\": \"15856235263\",\n" + + " \"senderLongitude\": \"117.30488400\",\n" + + " \"senderLatitude\": \"31.87844600\",\n" + + " \"senderStreetCode\": \"340121400000\",\n" + + " \"senderStreetName\": \"双凤开发区\",\n" + + " \"senderAddr\": \"合肥市长丰县凤麟路10号\",\n" + + " \"receiverProviceCode\": \"340000\",\n" + + " \"receiverProviceName\": \"安徽省\",\n" + + " \"receiverCityCode\": \"340100\",\n" + + " \"receiverCityName\": \"合肥市\",\n" + + " \"receiverCountyCode\": \"340122\",\n" + + " \"receiverCountyName\": \"肥东县\",\n" + + " \"receiverContactName\": \"舒城港汇\",\n" + + " \"receiverContactPhone\": \"15856235263\",\n" + + " \"receiverAddr\": \"巴莉甜甜(舒城港汇店)\",\n" + + " \"receiverLongitude\": \"116.93721100\",\n" + + " \"receiverLatitude\": \"31.47053900\",\n" + + " \"receiverStreetCode\": \"340122402000\",\n" + + " \"receiverStreetName\": \"合肥循环经济示范园\"\n" + + " },\n" + + " \"businessJson\": {\n" + + " }\n" + + "}"; + + String bodyjson = JSON.toJSONString(StrUtil.removeAll(body, specialChars)); + System.out.println("bodyjson: " + bodyjson); + + sortedMap.put("data", bodyjson); + 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); + + log.info("bodyjson:" + bodyjson); + log.info("nonce:" + nonce); + log.info("timestamp:" + timeStamp); + log.info("sign:" + genSign); + } +} diff --git a/cpxt-system/src/main/java/com/cpxt/biz/orderutil/CityDelivery.java b/cpxt-system/src/main/java/com/cpxt/biz/orderutil/CityDelivery.java index 869daaa..aff8f0e 100644 --- a/cpxt-system/src/main/java/com/cpxt/biz/orderutil/CityDelivery.java +++ b/cpxt-system/src/main/java/com/cpxt/biz/orderutil/CityDelivery.java @@ -11,6 +11,8 @@ import com.cpxt.biz.domain.BizOrderSub; import com.cpxt.biz.domain.SysArea; import com.cpxt.biz.mapper.SysAreaMapper; import com.cpxt.common.annotation.Anonymous; +import com.cpxt.common.utils.DateUtils; +import com.cpxt.common.utils.Helper; import com.cpxt.system.mapper.SysDictDataMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -52,100 +54,6 @@ public class CityDelivery { String client_type = "other"; String version = "1.0.0"; - /** - * 同城急送平台工具,post接口 - */ - 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); - } - /** * 同城急送平台工具,post接口 */ @@ -159,9 +67,13 @@ public class CityDelivery { String subOrderSn = bizOrderSub.getSubOrderSn(); if (subOrderSn == null) subOrderSn = ""; BigDecimal weight = bizOrderSub.getWeight(); + int intweight = Helper.FInt(weight.multiply(new BigDecimal(1000))); String remark = bizOrderSub.getRemark(); if (remark == null) remark = ""; + BigDecimal fee = bizOrderSub.getOrderFee(); + int intfee = Helper.FInt(fee.multiply(new BigDecimal(100))); + // 寄件人信息 String senderArea = bizOrder.getSenderArea(); // 寄件人街道代码 if (senderArea == null) senderArea = ""; @@ -259,6 +171,11 @@ public class CityDelivery { if (bizOrder.getReceiverLat() != null){ receiverLat = bizOrder.getReceiverLat().toString(); } + Date createtime = bizOrder.getCreateTime(); + Date exptime = new Date(); + if (createtime!=null) + exptime = DateUtils.addHours(createtime, 5); + String exptime_str = DateUtils.parseDateToStr("yyyy-MM-dd,HH:mm:ss", exptime); Long timeStamp = System.currentTimeMillis(); String nonce = UUID.randomUUID().toString().replace("-", ""); @@ -274,17 +191,17 @@ public class CityDelivery { " \"platformOrderNo\": \"\",\n" + " \"expressNbr\": \"\",\n" + " \"coordinateTransformType\": \"02\",\n" + - " \"weight\": \"" + weight + "\",\n" + - " \"expectedTime\": \"\",\n" + - " \"postageFee\": \"\",\n" + + " \"weight\": \"" + intweight + "\",\n" + + " \"expectedTime\": \""+exptime_str+"\",\n" + + " \"postageFee\": \""+ intfee +"\",\n" + // " \"convertFlag\": false,\n" + " \"orderSource\": \"other\",\n" + " \"orderSourcePlatform\": \"其他\",\n" + - " \"costFee\": \"\",\n" + - " \"tipFee\": \"\",\n" + - " \"insuredFee\": \"\",\n" + - " \"otherFee1\": \"\",\n" + - " \"otherFee2\": \"\",\n" + + " \"costFee\": \"0\",\n" + + " \"tipFee\": \"0\",\n" + + " \"insuredFee\": \"0\",\n" + + " \"otherFee1\": \"0\",\n" + + " \"otherFee2\": \"0\",\n" + " \"packageDesc\": \"" + goodsTypeLabel + "\",\n" + " \"remark\": \"" + remark + "\",\n" + " \"addressFirst\": {\n" + @@ -315,6 +232,122 @@ public class CityDelivery { " \"receiverStreetCode\": \"" + receiverArea + "\",\n" + " \"receiverStreetName\": \"" + receiverStreetName + "\"\n" + " },\n" + + " \"businessJson\": {}\n" + + "}"; + + // 获取最新token + String token = refreshToken(); + log.info("========================================准备请求========================================"); + log.info("body:" + body); + /** + * post请求,需要放data + */ + String bodyjson = JSON.toJSONString(StrUtil.removeAll(body, specialChars)); + + sortedMap.put("data", bodyjson); + 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); + + log.info("bodyjson:" + bodyjson); + System.out.println("bodyjson: " + bodyjson); + log.info("nonce:" + nonce); + System.out.println("nonce:" + nonce); + log.info("timestamp:" + timeStamp); + System.out.println("timestamp:" + timeStamp); + log.info("sign:" + genSign); + System.out.println("sign:" + genSign); + log.info("Authorization:" + token); + System.out.println("Authorization:" + token); + log.info("========================================开始请求========================================"); +// .body(JSONObject.toJSONString(body)) + HttpResponse response = HttpRequest.post(url) + .body(StrUtil.removeAll(body, specialChars)) + .header("Content-Type", "application/json") + .header("client_type", client_type) + .header("app_type", appType) + .header("access_id", clientKey) + .header("nonce", nonce) + .header("timestamp", timeStamp.toString()) + .header("sign", genSign) + .header("Authorization", token) + .execute(); + log.info("========================================请求结果========================================"); + System.out.println("response:" + response); + log.info("response:" + response); + } + + + /** + * 同城急送平台工具,post接口 + */ + 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" + @@ -327,9 +360,6 @@ public class CityDelivery { // "}"; //get请求,组装成 k v类型 // sortedMap.put(paramName,request.getParameter(paramName)); - String token = refreshToken(); - log.info("========================================准备请求========================================"); - log.info("body:" + body); /** * post请求,需要放data */ @@ -350,37 +380,10 @@ public class CityDelivery { } stringToSign.append("accessSecret").append("=").append(clientSecret); String genSign = CityDelivery_SM4Util.encryptCBC(stringToSign.toString(), clientSecret, sm4Key); - log.info("client_type:" + client_type); - System.out.println("client_type:" + client_type); - log.info("app_type:" + appType); - System.out.println("app_type:" + appType); - log.info("access_id:" + clientKey); - System.out.println("access_id:" + clientKey); - log.info("nonce:" + nonce); - System.out.println("nonce:" + nonce); - log.info("timestamp:" + timeStamp); - System.out.println("timestamp:" + timeStamp); - log.info("sign:" + genSign); - System.out.println("sign:" + genSign); - log.info("Authorization:" + token); - System.out.println("Authorization:" + token); - log.info("========================================开始请求========================================"); - HttpResponse response = HttpRequest.post(url) - .body(JSONObject.toJSONString(body)) - .header("Content-Type", "application/json") - .header("client_type", client_type) - .header("app_type", appType) - .header("access_id", clientKey) - .header("nonce", nonce) - .header("timestamp", timeStamp.toString()) - .header("sign", genSign) - .header("Authorization", token) - .execute(); - log.info("========================================请求结果========================================"); - System.out.println("response:" + response); - log.info("response:" + response); + System.out.println("sign:" + genSign); } + /** * 同城急送平台工具,获取token */ diff --git a/pom.xml b/pom.xml index 100ad57..464282c 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ cpxt http://www.ruoyi.vip - 中国邮政合肥城配平台 + 合肥城配平台 3.8.8