推送邮政订单

master
YIN 2025-02-28 15:57:19 +08:00
parent 5643b4605b
commit 44d542a97d
4 changed files with 164 additions and 169 deletions

View File

@ -59,9 +59,15 @@ public class OpenContrller {
}else { }else {
// 修改子单信息(状态、预计送达时间) // 修改子单信息(状态、预计送达时间)
bizOrderSub.setSubOrderStatus(orderStatusChangePushEntity.getStatus()); bizOrderSub.setSubOrderStatus(orderStatusChangePushEntity.getStatus());
if (ObjectUtil.isNotEmpty(orderStatusChangePushEntity.getRemark().getDeliverTime())){ if (!Helper.NStr(orderStatusChangePushEntity.getRemark()).equals("")){
bizOrderSub.setExpectTime(DateUtil.parseTime(orderStatusChangePushEntity.getRemark().getDeliverTime())); 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()); BizOrder bizOrder = bizOrderMapper.selectByOrderSn(bizOrderSub.getOrderSn());
String status = orderStatusChangePushEntity.getStatus(); String status = orderStatusChangePushEntity.getStatus();
@ -96,9 +102,19 @@ public class OpenContrller {
BizOrderSubStatusChangeLog log = new BizOrderSubStatusChangeLog(); BizOrderSubStatusChangeLog log = new BizOrderSubStatusChangeLog();
BeanUtils.copyProperties(orderStatusChangePushEntity, log); BeanUtils.copyProperties(orderStatusChangePushEntity, log);
log.setEmailNbr(orderStatusChangePushEntity.getRemark().getExpressNbr()); if (!Helper.NStr(orderStatusChangePushEntity.getRemark()).equals("")){
if (!Helper.NStr(orderStatusChangePushEntity.getRemark().getDeliverTime()).equals("")) String remark = Helper.NStr(orderStatusChangePushEntity.getRemark());
log.setDeliverTime(DateUtils.parseDate(orderStatusChangePushEntity.getRemark().getDeliverTime())); 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); logMapper.insert(log);
resultMap.put("timestamp",System.currentTimeMillis()); resultMap.put("timestamp",System.currentTimeMillis());

View File

@ -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;
}
}

View File

@ -41,7 +41,7 @@ public class OrderStatusChangePushEntity {
/** /**
* *
*/ */
private RemarkBean remark; private String remark;
@NoArgsConstructor @NoArgsConstructor
@Data @Data

View File

@ -12,9 +12,11 @@ import com.cpxt.biz.domain.BizOrderSub;
import com.cpxt.biz.domain.SysArea; import com.cpxt.biz.domain.SysArea;
import com.cpxt.biz.mapper.BizCustomerMapper; import com.cpxt.biz.mapper.BizCustomerMapper;
import com.cpxt.biz.mapper.SysAreaMapper; import com.cpxt.biz.mapper.SysAreaMapper;
import com.cpxt.common.utils.DateUtils; import com.cpxt.common.utils.DateUtils;
import com.cpxt.common.utils.Helper; import com.cpxt.common.utils.Helper;
import com.cpxt.system.mapper.SysDictDataMapper; import com.cpxt.system.mapper.SysDictDataMapper;
import com.cpxt.system.service.ISysConfigService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
@ -38,6 +40,10 @@ public class CityDelivery {
@Resource @Resource
private RedisTemplate<String, Object> redisTemplate; private RedisTemplate<String, Object> redisTemplate;
@Autowired
private ISysConfigService configService;
@Autowired @Autowired
private SysDictDataMapper sysDictDataMapper; private SysDictDataMapper sysDictDataMapper;
@ -48,106 +54,22 @@ public class CityDelivery {
private BizCustomerMapper bizCustomerMapper; private BizCustomerMapper bizCustomerMapper;
// test // test
String clientKey = "7480617400984563";//accessKey
String clientSecret = "91wCEvn82CeyMg3k";
String sm4Key = "MJy05dcI4mPbGB61";
String appType = "wxmp"; String appType = "wxmp";
String client_type = "other"; String client_type = "other";
String version = "1.0.0"; String version = "1.0.0";
/** // # 测试环境
* post String devApiUrl = "https://wyjcs.gdwyj.cn/szelec/city-delivery-api";
*/ String devClientKey = "7480617400984563";
public void cityDelivery_signBody22() { String devClientSecret = "91wCEvn82CeyMg3k";
Long timeStamp = System.currentTimeMillis(); String devSm4Key = "MJy05dcI4mPbGB61";
String nonce = UUID.randomUUID().toString().replace("-", "");
System.out.println("nonce:" + nonce); // # 生产环境
System.out.println("timeStamp:" + timeStamp); String prodApiUrl = "https://tcjsapi.ems.com.cn";
//签名 String prodClientKey = "1163619987703896";
Map<String, Object> sortedMap = new TreeMap<>(); String prodClientSecret = "c9cvEziasYGWenrT";
//下单接口 String prodSm4Key = "0b0BxDAzFcl8h0TQ";
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));
/**
* postdata
*/
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<String, Object> sortedParams = new TreeMap<>(sortedMap);
Set<Map.Entry<String, Object>> entrySet = sortedParams.entrySet();
// 遍历排序后的字典,将所有参数按"key=value"格式拼接在一起
StringBuilder stringToSign = new StringBuilder();
for (Map.Entry<String, Object> 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 * post
@ -156,7 +78,6 @@ public class CityDelivery {
BizCustomer bizCustomer = bizCustomerMapper.selectByName(bizOrder.getCustomerName()); BizCustomer bizCustomer = bizCustomerMapper.selectByName(bizOrder.getCustomerName());
String code = bizCustomer.getCode(); String code = bizCustomer.getCode();
String url = "https://wyjcs.gdwyj.cn/szelec/city-delivery-api/api/base/order/add";
String goodsType = bizOrderSub.getGoodsType(); String goodsType = bizOrderSub.getGoodsType();
String goodsTypeLabel = sysDictDataMapper.selectDictLabel("sys_goods_type", goodsType); String goodsTypeLabel = sysDictDataMapper.selectDictLabel("sys_goods_type", goodsType);
@ -337,6 +258,25 @@ public class CityDelivery {
String token = refreshToken(); String token = refreshToken();
log.info("========================================准备请求========================================"); log.info("========================================准备请求========================================");
log.info("body" + body); 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;
}
/** /**
* postdata * postdata
*/ */
@ -387,69 +327,29 @@ public class CityDelivery {
return response.body(); 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<String, Object> sortedParams1 = new TreeMap<>(map);
Set<Map.Entry<String, Object>> entrySet1 = sortedParams1.entrySet();
StringBuilder stringToSign = new StringBuilder();
for (Map.Entry<String, Object> 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<String, Object> sortedMap2 = new TreeMap<>();
//get请求组装成 k v类型
// sortedMap2.put(paramName,request.getParameter(paramName));
/**
* postdata
*/
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<String, Object> sortedParams2 = new TreeMap<>(sortedMap2);
Set<Map.Entry<String, Object>> entrySet2 = sortedParams2.entrySet();
// 遍历排序后的字典,将所有参数按"key=value"格式拼接在一起
StringBuilder stringToSign2 = new StringBuilder();
for (Map.Entry<String, Object> 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 //获取token
// @Anonymous // @Anonymous
// @GetMapping("/getToken") // @GetMapping("/getToken")
public void 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"); 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("-", ""); String nonce = UUID.randomUUID().toString().replace("-", "");
Long timestamp = System.currentTimeMillis(); Long timestamp = System.currentTimeMillis();
//body //body
@ -521,15 +421,6 @@ public class CityDelivery {
redisTemplate.opsForValue().set("city_delivery_token_expirationTimestamp", expirationTimestamp); 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 * token
* *