From 44d542a97d1bae8e9bdc5551b2bb90abb76757d1 Mon Sep 17 00:00:00 2001 From: YIN Date: Fri, 28 Feb 2025 15:57:19 +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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/biz/OpenContrller.java | 26 ++- .../com/cpxt/common/config/EMSConfig.java | 88 +++++++ .../domain/OrderStatusChangePushEntity.java | 2 +- .../com/cpxt/biz/orderutil/CityDelivery.java | 217 +++++------------- 4 files changed, 164 insertions(+), 169 deletions(-) create mode 100644 cpxt-common/src/main/java/com/cpxt/common/config/EMSConfig.java diff --git a/cpxt-admin/src/main/java/com/cpxt/web/controller/biz/OpenContrller.java b/cpxt-admin/src/main/java/com/cpxt/web/controller/biz/OpenContrller.java index 327da69..2b7a8e2 100644 --- a/cpxt-admin/src/main/java/com/cpxt/web/controller/biz/OpenContrller.java +++ b/cpxt-admin/src/main/java/com/cpxt/web/controller/biz/OpenContrller.java @@ -59,9 +59,15 @@ public class OpenContrller { }else { // 修改子单信息(状态、预计送达时间) bizOrderSub.setSubOrderStatus(orderStatusChangePushEntity.getStatus()); - if (ObjectUtil.isNotEmpty(orderStatusChangePushEntity.getRemark().getDeliverTime())){ - bizOrderSub.setExpectTime(DateUtil.parseTime(orderStatusChangePushEntity.getRemark().getDeliverTime())); + if (!Helper.NStr(orderStatusChangePushEntity.getRemark()).equals("")){ + String remark = Helper.NStr(orderStatusChangePushEntity.getRemark()); + JSONObject jsonremark = JSONObject.parseObject(remark); + String deliverTime = Helper.NStr(jsonremark.get("deliverTime")); + if (!deliverTime.equals("")){ + bizOrderSub.setExpectTime(DateUtil.parseTime(deliverTime)); + } } + // 修改订单信息(状态、开始配送时间和到达时间) BizOrder bizOrder = bizOrderMapper.selectByOrderSn(bizOrderSub.getOrderSn()); String status = orderStatusChangePushEntity.getStatus(); @@ -96,9 +102,19 @@ public class OpenContrller { BizOrderSubStatusChangeLog log = new BizOrderSubStatusChangeLog(); BeanUtils.copyProperties(orderStatusChangePushEntity, log); - log.setEmailNbr(orderStatusChangePushEntity.getRemark().getExpressNbr()); - if (!Helper.NStr(orderStatusChangePushEntity.getRemark().getDeliverTime()).equals("")) - log.setDeliverTime(DateUtils.parseDate(orderStatusChangePushEntity.getRemark().getDeliverTime())); + if (!Helper.NStr(orderStatusChangePushEntity.getRemark()).equals("")){ + String remark = Helper.NStr(orderStatusChangePushEntity.getRemark()); + JSONObject jsonremark = JSONObject.parseObject(remark); + String deliverTime = Helper.NStr(jsonremark.get("deliverTime")); + String expressNbr = Helper.NStr(jsonremark.get("expressNbr")); + if (!deliverTime.equals("")){ + log.setDeliverTime(DateUtil.parseTime(deliverTime)); + } + if (!expressNbr.equals("")){ + log.setEmailNbr(expressNbr); + } + } + logMapper.insert(log); resultMap.put("timestamp",System.currentTimeMillis()); diff --git a/cpxt-common/src/main/java/com/cpxt/common/config/EMSConfig.java b/cpxt-common/src/main/java/com/cpxt/common/config/EMSConfig.java new file mode 100644 index 0000000..2713b0d --- /dev/null +++ b/cpxt-common/src/main/java/com/cpxt/common/config/EMSConfig.java @@ -0,0 +1,88 @@ +package com.cpxt.common.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * 读取项目相关配置 + * + * @author ruoyi + */ +@Component +@ConfigurationProperties(prefix = "ems") +public class EMSConfig +{ + private static String devApiUrl; + private static String devClientKey; + private static String devClientSecret; + private static String devSm4Key; + + private static String prodApiUrl; + private static String prodClientKey; + private static String prodClientSecret; + private static String prodSm4Key; + + public static String getDevApiUrl() { + return devApiUrl; + } + + public static void setDevApiUrl(String devApiUrl) { + EMSConfig.devApiUrl = devApiUrl; + } + + public static String getDevClientKey() { + return devClientKey; + } + + public static void setDevClientKey(String devClientKey) { + EMSConfig.devClientKey = devClientKey; + } + + public static String getDevClientSecret() { + return devClientSecret; + } + + public static void setDevClientSecret(String devClientSecret) { + EMSConfig.devClientSecret = devClientSecret; + } + + public static String getDevSm4Key() { + return devSm4Key; + } + + public static void setDevSm4Key(String devSm4Key) { + EMSConfig.devSm4Key = devSm4Key; + } + + public static String getProdApiUrl() { + return prodApiUrl; + } + + public static void setProdApiUrl(String prodApiUrl) { + EMSConfig.prodApiUrl = prodApiUrl; + } + + public static String getProdClientKey() { + return prodClientKey; + } + + public static void setProdClientKey(String prodClientKey) { + EMSConfig.prodClientKey = prodClientKey; + } + + public static String getProdClientSecret() { + return prodClientSecret; + } + + public static void setProdClientSecret(String prodClientSecret) { + EMSConfig.prodClientSecret = prodClientSecret; + } + + public static String getProdSm4Key() { + return prodSm4Key; + } + + public static void setProdSm4Key(String prodSm4Key) { + EMSConfig.prodSm4Key = prodSm4Key; + } +} diff --git a/cpxt-system/src/main/java/com/cpxt/biz/domain/OrderStatusChangePushEntity.java b/cpxt-system/src/main/java/com/cpxt/biz/domain/OrderStatusChangePushEntity.java index eba5816..dce2690 100644 --- a/cpxt-system/src/main/java/com/cpxt/biz/domain/OrderStatusChangePushEntity.java +++ b/cpxt-system/src/main/java/com/cpxt/biz/domain/OrderStatusChangePushEntity.java @@ -41,7 +41,7 @@ public class OrderStatusChangePushEntity { /** * 备注 */ - private RemarkBean remark; + private String remark; @NoArgsConstructor @Data 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 34533e3..bf8ad49 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 @@ -12,9 +12,11 @@ import com.cpxt.biz.domain.BizOrderSub; import com.cpxt.biz.domain.SysArea; import com.cpxt.biz.mapper.BizCustomerMapper; import com.cpxt.biz.mapper.SysAreaMapper; + import com.cpxt.common.utils.DateUtils; import com.cpxt.common.utils.Helper; import com.cpxt.system.mapper.SysDictDataMapper; +import com.cpxt.system.service.ISysConfigService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; @@ -38,6 +40,10 @@ public class CityDelivery { @Resource private RedisTemplate redisTemplate; + + @Autowired + private ISysConfigService configService; + @Autowired private SysDictDataMapper sysDictDataMapper; @@ -48,106 +54,22 @@ public class CityDelivery { private BizCustomerMapper bizCustomerMapper; // test - String clientKey = "7480617400984563";//accessKey - String clientSecret = "91wCEvn82CeyMg3k"; - String sm4Key = "MJy05dcI4mPbGB61"; String appType = "wxmp"; 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); + // # 测试环境 + String devApiUrl = "https://wyjcs.gdwyj.cn/szelec/city-delivery-api"; + String devClientKey = "7480617400984563"; + String devClientSecret = "91wCEvn82CeyMg3k"; + String devSm4Key = "MJy05dcI4mPbGB61"; + + // # 生产环境 + String prodApiUrl = "https://tcjsapi.ems.com.cn"; + String prodClientKey = "1163619987703896"; + String prodClientSecret = "c9cvEziasYGWenrT"; + String prodSm4Key = "0b0BxDAzFcl8h0TQ"; - 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接口 @@ -156,7 +78,6 @@ public class CityDelivery { BizCustomer bizCustomer = bizCustomerMapper.selectByName(bizOrder.getCustomerName()); String code = bizCustomer.getCode(); - String url = "https://wyjcs.gdwyj.cn/szelec/city-delivery-api/api/base/order/add"; String goodsType = bizOrderSub.getGoodsType(); String goodsTypeLabel = sysDictDataMapper.selectDictLabel("sys_goods_type", goodsType); @@ -337,6 +258,25 @@ public class CityDelivery { String token = refreshToken(); log.info("========================================准备请求========================================"); log.info("body:" + body); + + String url = ""; + String clientKey = ""; + String clientSecret = ""; + String sm4Key = ""; + + int mode = Helper.FInt(configService.selectConfigByKey("sys.interface.env")); + if (mode == 1){ + url = prodApiUrl + "/api/base/order/add"; + clientKey = prodClientKey; + clientSecret = prodClientSecret; + sm4Key = prodSm4Key; + }else{ + url = devApiUrl + "/api/base/order/add"; + clientKey = devClientKey; + clientSecret = devClientSecret; + sm4Key = devSm4Key; + } + /** * post请求,需要放data */ @@ -387,69 +327,29 @@ public class CityDelivery { return response.body(); } - /** - * 同城急送平台工具,获取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 // @GetMapping("/getToken") public void getToken() { + String url = ""; + String clientKey = ""; + String clientSecret = ""; + String sm4Key = ""; + + int mode = Helper.FInt(configService.selectConfigByKey("sys.interface.env")); + if (mode == 1){ + url = prodApiUrl + "/api/mini/app/login/token"; + clientKey = prodClientKey; + clientSecret = prodClientSecret; + sm4Key = prodSm4Key; + }else{ + url = devApiUrl + "/api/mini/app/login/token"; + clientKey = devClientKey; + clientSecret = devClientSecret; + sm4Key = devSm4Key; + } + System.out.println("获取token"); - String url = "https://wyjcs.gdwyj.cn/szelec/city-delivery-api/api/mini/app/login/token"; String nonce = UUID.randomUUID().toString().replace("-", ""); Long timestamp = System.currentTimeMillis(); //body @@ -521,15 +421,6 @@ public class CityDelivery { redisTemplate.opsForValue().set("city_delivery_token_expirationTimestamp", expirationTimestamp); } - /*@GetMapping("/111") - @Anonymous - public void test(){ - String body = "{\"success\":true,\"message\":\"\",\"code\":200,\"result\":{\"expirationTimestamp\":1737624154641,\"token\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb2dpbiIsImxvZ2luSWQiOiIxMDAwMiIsInJuU3RyIjoiRDA5VGtjUTZ4Y3dobjdMNDFISXdWTjM1bGdScWt1cVkiLCJjbGllbnRUeXBlIjoib3RoZXIiLCJ1c2VySWQiOiIxMDAwMiJ9.yA3zq8e4uDZCLBlMpL0dfyIfkP3zoegcNt9iHSjB-jM\"},\"timestamp\":1737620554641}\n"; - JSONObject jsonObject = JSON.parseObject(body); - System.out.println("jsonObject = " + jsonObject); - - }*/ - /** * 刷新token *