|
@@ -21,10 +21,11 @@ import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
-import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_API_QUERY_FAILED;
|
|
|
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_API_QUERY_ERROR;
|
|
|
+import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_API_QUERY_FAILED;
|
|
|
import static cn.iocoder.yudao.module.trade.framework.delivery.core.convert.ExpressQueryConvert.INSTANCE;
|
|
|
|
|
|
+// TODO @jason:可以参考 KdNiaoExpressQueryProvider 建议改改哈
|
|
|
/**
|
|
|
* 快递 100 服务商
|
|
|
*
|
|
@@ -34,8 +35,8 @@ import static cn.iocoder.yudao.module.trade.framework.delivery.core.convert.Expr
|
|
|
public class Kd100ExpressQueryProvider implements ExpressQueryProvider {
|
|
|
|
|
|
private static final String REAL_TIME_QUERY_URL = "https://poll.kuaidi100.com/poll/query.do";
|
|
|
- private final RestTemplate restTemplate;
|
|
|
|
|
|
+ private final RestTemplate restTemplate;
|
|
|
private final TradeExpressQueryProperties.Kd100Config config;
|
|
|
|
|
|
public Kd100ExpressQueryProvider(RestTemplate restTemplate, TradeExpressQueryProperties.Kd100Config config) {
|
|
@@ -45,16 +46,19 @@ public class Kd100ExpressQueryProvider implements ExpressQueryProvider {
|
|
|
|
|
|
@Override
|
|
|
public List<ExpressQueryRespDTO> realTimeQueryExpress(ExpressQueryReqDTO reqDTO) {
|
|
|
+ // 发起查询
|
|
|
Kd100ExpressQueryReqDTO kd100ReqParam = INSTANCE.convert2(reqDTO);
|
|
|
- // 快递公司编码需要转成小写
|
|
|
- kd100ReqParam.setExpressCompanyCode(kd100ReqParam.getExpressCompanyCode().toLowerCase());
|
|
|
+ kd100ReqParam.setExpressCompanyCode(kd100ReqParam.getExpressCompanyCode().toLowerCase()); // 快递公司编码需要转成小写
|
|
|
Kd100ExpressQueryRespDTO respDTO = sendExpressQueryReq(REAL_TIME_QUERY_URL, kd100ReqParam,
|
|
|
Kd100ExpressQueryRespDTO.class);
|
|
|
- log.debug("快递 100 接口 查询接口返回 {}", respDTO);
|
|
|
+ log.debug("[realTimeQueryExpress][快递 100 接口 查询接口返回 {}]", respDTO);
|
|
|
+ // 处理结果
|
|
|
if (Objects.equals("false", respDTO.getResult())) {
|
|
|
- log.error("快递 100 接口 返回失败 {} ", respDTO.getMessage());
|
|
|
+ log.error("[realTimeQueryExpress][快递 100 接口 返回失败 {}]", respDTO.getMessage());
|
|
|
throw exception(EXPRESS_API_QUERY_FAILED, respDTO.getMessage());
|
|
|
+ // TODO @json:else 可以不用写哈;
|
|
|
} else {
|
|
|
+ // TODO @jason:convertList2 如果空,应该返回 list 了;
|
|
|
if (CollUtil.isNotEmpty(respDTO.getTracks())) {
|
|
|
return INSTANCE.convertList2(respDTO.getTracks());
|
|
|
} else {
|
|
@@ -65,12 +69,14 @@ public class Kd100ExpressQueryProvider implements ExpressQueryProvider {
|
|
|
|
|
|
/**
|
|
|
* 发送快递 100 实时快递查询请求,可以作为通用快递 100 通用请求接口。 目前没有其它场景需要使用。暂时放这里
|
|
|
+ *
|
|
|
* @param url 请求 url
|
|
|
* @param req 对应请求的请求参数
|
|
|
* @param respClass 对应请求的响应 class
|
|
|
* @param <Req> 每个请求的请求结构 Req DTO
|
|
|
* @param <Resp> 每个请求的响应结构 Resp DTO
|
|
|
*/
|
|
|
+ // TODO @jason:可以改成 request,发起请求哈;
|
|
|
private <Req, Resp> Resp sendExpressQueryReq(String url, Req req, Class<Resp> respClass) {
|
|
|
// 请求头
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
@@ -78,19 +84,20 @@ public class Kd100ExpressQueryProvider implements ExpressQueryProvider {
|
|
|
// 生成签名
|
|
|
String param = JsonUtils.toJsonString(req);
|
|
|
String sign = generateReqSign(param, config.getKey(), config.getCustomer());
|
|
|
- log.debug("快递 100 快递 接口生成签名的: {}", sign);
|
|
|
// 请求体
|
|
|
MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
|
|
|
requestBody.add("customer", config.getCustomer());
|
|
|
requestBody.add("sign", sign);
|
|
|
requestBody.add("param", param);
|
|
|
- log.debug("快递 100 接口的请求参数: {}", requestBody);
|
|
|
-
|
|
|
- HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(requestBody, headers);
|
|
|
+ log.debug("[sendExpressQueryReq][快递 100 接口的请求参数: {}]", requestBody);
|
|
|
// 发送请求
|
|
|
+ HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(requestBody, headers);
|
|
|
+ // TODO @jason:可以使用 restTemplate 的 post 方法哇?
|
|
|
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
|
|
|
- log.debug("快递 100 接口响应结果 {}", responseEntity);
|
|
|
+ log.debug("[sendExpressQueryReq][快递 100 接口响应结果 {}]", responseEntity);
|
|
|
+
|
|
|
// 处理响应
|
|
|
+ // TODO @jason:if return 原则;if (!responseEntity.getStatusCode().is2xxSuccessful()) 抛出异常;接着处理成功的
|
|
|
if (responseEntity.getStatusCode().is2xxSuccessful()) {
|
|
|
String response = responseEntity.getBody();
|
|
|
return JsonUtils.parseObject(response, respClass);
|
|
@@ -101,7 +108,8 @@ public class Kd100ExpressQueryProvider implements ExpressQueryProvider {
|
|
|
|
|
|
private String generateReqSign(String param, String key, String customer) {
|
|
|
String plainText = String.format("%s%s%s", param, key, customer);
|
|
|
- log.debug("快递 100 接口待签名的数据 {}", plainText);
|
|
|
+ // TODO @jason:DigestUtil.md5Hex(plainText);
|
|
|
return HexUtil.encodeHexStr(DigestUtil.md5(plainText), false);
|
|
|
}
|
|
|
+
|
|
|
}
|