xuhy
2026-02-06 d782bff0762c1f821ef98f610bd37ccc49c8f285
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
56
57
package com.ruoyi.web.controller.yuncang.api.basic;
 
 
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.web.controller.yuncang.utils.WdtClient;
import lombok.extern.slf4j.Slf4j;
 
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
 
@Slf4j
public class LogisticsQuery {
 
    /**
     * 物流查询
     * @param sid     卖家账号,接口请求的公共参数sid
     * @param appkey     接口账号,接口请求的公共参数appkey
     * @param appsecret     接口秘钥,接口请求的参数appsecret ,用于计算签名
     * @param url     接口地址,接口请求的公共参数url
     * @param logistics_no     物流单号
     * @return
     */
    public static JSONObject logisticsQuery(String sid, String appkey, String appsecret, String url, String logistics_no) {
        WdtClient client = new WdtClient(sid, appkey, appsecret, url);
        Map<String, String> params = new HashMap<String, String>();
        params.put("logistics_no", logistics_no);
        try {
            String response = client.execute("logistics.php", params);
            log.info("物流查询结果:{}", response);
            JSONObject jsonObject = JSONObject.parseObject(response);
            if(jsonObject.getInteger("code") == 0){
                return jsonObject;
            }else{
                log.info("物流查询失败");
                throw new ServiceException(jsonObject.getString("message"));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static void main(String[] args) {
        WdtClient client = new WdtClient("apidevnew2", "hytycw02-test", "c7ae51196", "https://sandbox.wangdian.cn/openapi2/");
        Map<String, String> params = new HashMap<String, String>();
        params.put("logistics_no", "SF1519018370586");
 
        try {
            String response = client.execute("logistics.php", params);
            System.out.println(response);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
}