Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use SpringBoot to realize express logistics query

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to use SpringBoot to realize express logistics query". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

Express Logistics Inquiry

Note: Need to purchase express logistics query interface service to obtain AppCode

tool class

http request tools which self-view demo source code

@Slf4jpublic class LogisticUtil { /** * Query logistics information * * @param params Submit Parameters * @return Logistics information * @author zhengqingya * @date 2021/10/23 10:48 pm */ public static LogisticVO getLogisticInfo(LogisticDTO params) { String no = params.getNo(); String type = params.getType(); String appCode = params.getAppCode(); //Request address String requestUrl = String.format("https://kdwlcxf.market.alicloudapi.com/kdwlcx? no=%s&type=%s", no, StringUtils.isBlank(type) ? "" : type); //initiate request Map 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, "parameter exception"); Assert.isTrue(logisticApiResult.getStatus() == 0, logisticApiResult.getMsg()); return logisticApiResult.getResult(); }}

Request Entity Class

@Data@SuperBuilder@NoArgsConstructor@AllArgsConstructor@ApiModel("Logistic-Query Parameters")public class LogisticDTO { @ApiModelProperty(value = "Express waybill number [Shunfeng please enter waybill number: recipient or sender mobile phone number after four digits. For example: 123456789:1234]", required = true, example = "780098068058") private String no; @ApiModelProperty(value = "Express company code: optional automatic identification, faster query if filled in [code see attached table]", required = true, example = "zto") private String type; @ApiModelProperty(value = "appCode", required = true, example = "xxx") private String appCode;}

Response Entity Class

@Data@Builder@NoArgsConstructor@AllArgsConstructor@ApiModel("Logistic-api Response Results")public class LogisticApiResult { @ApiModelProperty("Status Code") private Integer status; @ApiModelProperty("Tips") private String msg; @ApiModelProperty(Result Set) private LogisticVO result;}@Data@Builder@NoArgsConstructor@AllArgsConstructor@ApiModel("Logistic-Response Parameters")public class LogisticVO { @ApiModelProperty("waybill number") private String number; @ApiModelProperty("Courier company code [see attached table]") private String type; @ApiModelProperty("Delivery Status 0 Express Receipt (Collection)1 On the Way 2 Sending 3 Signed 4 Delivery Failure 5. Difficult 6. Return Signature") private String deliverystatus; @ApiModelProperty("Sign in") private String issign; @ApiModelProperty("courier name") private String expName; @ApiModelProperty("Express Company Official Website") private String expSite; @ApiModelProperty("Courier Phone") private String expPhone; @ApiModelProperty("courier") private String courier; @ApiModelProperty("Courier Phone") private String courierPhone; @ApiModelProperty("Time of Latest Track") private String updateTime; @ApiModelProperty("Shipment-to-Receipt Time (Up to Latest Track)") private String takeTime; @ApiModelProperty("courier company logo") private String logo; @ApiModelProperty(Event Track Set) private List list; @Data @Builder @NoArgsConstructor @AllArgsConstructor @ApiModel(Event Track Set) public static class LogisticItem { @ApiModelProperty("Point in Time") private String time; @ApiModelProperty(Event Details) private String status; }} Test api@Slf4j@RestController@RequestMapping("/test")@Api(tags = "Test api")public class TestController { @ApiOperation("Query Logistics Information") @GetMapping("getLogistic") public LogisticVO getLogistic(@ModelAttribute LogisticDTO params) { return LogisticUtil.getLogisticInfo(params); }}

Interface documentation http://127.0.0.1/doc.html

"How to use SpringBoot to realize express logistics query" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report