k94314517
2024-09-10 29fc101ccd5165a1c3d762ba3a240b1a0ab4ddfe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.doumee.core.utils.kuaidi100;
 
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import org.apache.commons.codec.digest.DigestUtils;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Rk
 * @create 2023/4/24 14:01
 */
public class ExpressUtils {
 
 
    private static String key = "jyAJUdnw9566";
 
    private static String customer = "B0C9AC739B017E6D6AE9C6869FF56DFB";
 
    private static final String POLL_QUERY_URL = "https://poll.kuaidi100.com/poll/query.do";
 
    /**
     * 物流信息查询  快递100
     * @param expressCode
     * @param company
     * @return
     */
    public static DeliveryDTO queryExpress(String expressCode,String company,String phone){
        Map<String, String> param = new HashMap<>();
        //快递单号
        param.put("num", expressCode);
        //是否显示路由状态信息
        param.put("resultv2","1");
        //手机号
        param.put("phone",phone);
        String mgsData = JSON.toJSONString(param);
        String sign= DigestUtils.md5Hex(mgsData + key + customer).toUpperCase();
        String url =POLL_QUERY_URL+"?customer="+customer+ "&sign=" +sign+ "&param="+mgsData;
        String deliveryJson = HttpUtil.get(url);
        DeliveryDTO deliveryDTO = JSON.parseObject(deliveryJson, DeliveryDTO.class);
        if(!deliveryDTO.getMessage().equals("ok")){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),deliveryDTO.getMessage());
        }
        deliveryDTO.setDvyCompany(company);
        deliveryDTO.setDvyFlowId(expressCode);
        return deliveryDTO;
    }
 
 
}