package org.fh.util.express;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.fh.util.express.Constants;
import org.fh.util.express.HttpHeader;
import org.fh.util.express.HttpSchema;
import org.fh.util.express.Method;
/** 获取物流信息
* 创建人:
* 创建时间:2023年3月2日
*/
public class GetExpressMsg {
//购买地址:https://market.aliyun.com/products/57126001/cmapi011120.html#sku=yuncode512000008
//APP KEY 参数一 (阿里巴巴支付后获得)
private final static String APP_KEY = "";
// APP密钥 参数二 (阿里巴巴支付后获得)
private final static String APP_SECRET = "";
//API域名
private final static String HOST = "jisukdcx.market.alicloudapi.com";
//自定义参与签名Header前缀(可选,默认只有"X-Ca-"开头的参与到Header签名)
private final static List<String> CUSTOM_HEADERS_TO_SIGN_PREFIX = new ArrayList<String>();
/**
* HTTP GET
*
* @throws Exception
*/
public static String get(String number) throws Exception {
//请求path
String path = "/express/query";
//String path = "/express/type";
Map<String, String> headers = new HashMap<String, String>();
//(必填)根据期望的Response内容类型设置
headers.put(HttpHeader.HTTP_HEADER_ACCEPT, "application/json");
headers.put("a-header1", "header1Value");
headers.put("b-header2", "header2Value");
CUSTOM_HEADERS_TO_SIGN_PREFIX.clear();
CUSTOM_HEADERS_TO_SIGN_PREFIX.add("a-header1");
CUSTOM_HEADERS_TO_SIGN_PREFIX.add("a-header2");
Request request = new Request(Method.GET, HttpSchema.HTTP + HOST, path, APP_KEY, APP_SECRET, Constants.DEFAULT_TIMEOUT);
request.setHeaders(headers);
request.setSignHeaderPrefixList(CUSTOM_HEADERS_TO_SIGN_PREFIX);
//请求的query
Map<String, String> querys = new HashMap<String, String>();
// querys.put("number", number);
//querys.put("type", "auto");
querys.put("mobile", "收件人/寄件人手机后四位");//顺丰的需要加后四位
querys.put("number", number);
querys.put("type", "auto");
request.setQuerys(querys);
//调用服务端
Response response = Client.execute(request);
String s = JSON.toJSONString(response);
JSONObject jsonObject = JSONObject.parseObject(s);
System.out.println(jsonObject.get("body"));
return jsonObject.get("body").toString();
}
public static void main(String[] args) throws Exception {
GetExpressMsg.get("SF1149779005111");
}
}
阿里快递物流api
于 2023-03-02 14:54:39 首次发布