SpringBoot實(shí)現(xiàn)阿里云快遞物流查詢的示例代碼
一、前言
本文將基于springboot2.4.0實(shí)現(xiàn)快遞物流查詢,物流信息的獲取通過(guò)阿里云第三方實(shí)現(xiàn)

快遞查詢API,快遞識(shí)別單號(hào),快遞接口可查詢上百家快遞公司及物流快遞信息包括:順豐、申通、圓通、韻達(dá)、中通、匯通、EMS、天天、國(guó)通、德邦、宅急送等幾百家快遞物流公司單號(hào)查詢接口。與官網(wǎng)實(shí)時(shí)同步更新,包含快遞送達(dá)時(shí)間。
二、快遞物流查詢
注:需要購(gòu)買(mǎi)快遞物流查詢接口服務(wù)獲取AppCode

工具類
其中http請(qǐng)求工具類自行查看demo源碼
@Slf4j
public class LogisticUtil {
/**
* 查詢物流信息
*
* @param params 提交參數(shù)
* @return 物流信息
* @author zhengqingya
* @date 2021/10/23 10:48 下午
*/
public static LogisticVO getLogisticInfo(LogisticDTO params) {
String no = params.getNo();
String type = params.getType();
String appCode = params.getAppCode();
// 請(qǐng)求地址
String requestUrl = String.format("https://kdwlcxf.market.alicloudapi.com/kdwlcx?no=%s&type=%s",
no, StringUtils.isBlank(type) ? "" : type);
// 發(fā)起請(qǐng)求
Map<String, String> headerMap = Maps.newHashMap();
headerMap.put("Authorization", String.format("APPCODE %s", appCode));
String resultJson = HttpUtil.getUrl(requestUrl, headerMap);
LogisticApiResult logisticApiResult = JSON.parseObject(resultJson, LogisticApiResult.class);
Assert.notNull(logisticApiResult, "參數(shù)異常");
Assert.isTrue(logisticApiResult.getStatus() == 0, logisticApiResult.getMsg());
return logisticApiResult.getResult();
}
}
請(qǐng)求實(shí)體類
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("物流-查詢參數(shù)")
public class LogisticDTO {
@ApiModelProperty(value = "快遞單號(hào) 【順豐請(qǐng)輸入運(yùn)單號(hào) : 收件人或寄件人手機(jī)號(hào)后四位。例如:123456789:1234】", required = true, example = "780098068058")
private String no;
@ApiModelProperty(value = "快遞公司代碼: 可不填自動(dòng)識(shí)別,填了查詢更快【代碼見(jiàn)附表】", required = true, example = "zto")
private String type;
@ApiModelProperty(value = "appCode", required = true, example = "xxx")
private String appCode;
}
響應(yīng)實(shí)體類
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("物流-api響應(yīng)結(jié)果")
public class LogisticApiResult {
@ApiModelProperty("狀態(tài)碼")
private Integer status;
@ApiModelProperty("提示信息")
private String msg;
@ApiModelProperty("結(jié)果集")
private LogisticVO result;
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("物流-響應(yīng)參數(shù)")
public class LogisticVO {
@ApiModelProperty("運(yùn)單編號(hào)")
private String number;
@ApiModelProperty("快遞公司編碼[見(jiàn)附表]")
private String type;
@ApiModelProperty("投遞狀態(tài) 0快遞收件(攬件)1在途中 2正在派件 3已簽收 4派送失敗 5.疑難件 6.退件簽收")
private String deliverystatus;
@ApiModelProperty("是否本人簽收")
private String issign;
@ApiModelProperty("快遞公司名字")
private String expName;
@ApiModelProperty("快遞公司官網(wǎng)")
private String expSite;
@ApiModelProperty("快遞公司電話")
private String expPhone;
@ApiModelProperty("快遞員")
private String courier;
@ApiModelProperty("快遞員電話")
private String courierPhone;
@ApiModelProperty("最新軌跡的時(shí)間")
private String updateTime;
@ApiModelProperty("發(fā)貨到收貨耗時(shí)(截止最新軌跡)")
private String takeTime;
@ApiModelProperty("快遞公司logo")
private String logo;
@ApiModelProperty("事件軌跡集")
private List<LogisticItem> list;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("事件軌跡集")
public static class LogisticItem {
@ApiModelProperty("時(shí)間點(diǎn)")
private String time;
@ApiModelProperty("事件詳情")
private String status;
}
}
三、測(cè)試api
@Slf4j
@RestController
@RequestMapping("/test")
@Api(tags = "測(cè)試api")
public class TestController {
@ApiOperation("查詢物流信息")
@GetMapping("getLogistic")
public LogisticVO getLogistic(@ModelAttribute LogisticDTO params) {
return LogisticUtil.getLogisticInfo(params);
}
}
接口文檔 http://127.0.0.1/doc.html

本文demo源碼
https://gitee.com/zhengqingya/java-workspace
到此這篇關(guān)于SpringBoot實(shí)現(xiàn)阿里云快遞物流查詢的示例代碼的文章就介紹到這了,更多相關(guān)SpringBoot 阿里云快遞物流查詢內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringBoot配置文件啟動(dòng)加載順序的方法步驟
SpringBoot的啟動(dòng)加載順序涉及多個(gè)步驟和組件,通過(guò)分層和優(yōu)先級(jí)機(jī)制加載配置文件,確保在啟動(dòng)時(shí)正確配置應(yīng)用程序,本文就來(lái)介紹一下SpringBoot配置文件啟動(dòng)加載順序的方法步驟,感興趣的可以了解一下2024-11-11
JAVA Iterator 轉(zhuǎn)成 List 的操作
這篇文章主要介紹了JAVA Iterator 轉(zhuǎn)成 List 的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-12-12
淺談java中replace()和replaceAll()的區(qū)別
這篇文章主要介紹了java中replace()和replaceAll()的區(qū)別,兩者都是常用的替換字符的方法,感興趣的小伙伴們可以參考一下2015-11-11
Mybatis plus 配置多數(shù)據(jù)源的實(shí)現(xiàn)示例
這篇文章主要介紹了Mybatis plus 配置多數(shù)據(jù)源的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08
為何修改equals方法時(shí)還要重寫(xiě)hashcode方法的原因分析
這篇文章主要介紹了為何修改equals方法時(shí)還要重寫(xiě)hashcode方法的原因分析,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06
JDK1.8中的ConcurrentHashMap使用及場(chǎng)景分析
這篇文章主要介紹了JDK1.8中的ConcurrentHashMap使用及場(chǎng)景分析,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01
SpringBoot整合Shiro框架,實(shí)現(xiàn)用戶權(quán)限管理
Apache Shiro是一個(gè)強(qiáng)大且易用的Java安全框架,執(zhí)行身份驗(yàn)證、授權(quán)、密碼和會(huì)話管理。作為一款安全框架Shiro的設(shè)計(jì)相當(dāng)巧妙。Shiro的應(yīng)用不依賴任何容器,它不僅可以在JavaEE下使用,還可以應(yīng)用在JavaSE環(huán)境中。2021-06-06

