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();
|
}
|
}
|
|
}
|