一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - SpringBoot實現阿里云快遞物流查詢的示例代碼

SpringBoot實現阿里云快遞物流查詢的示例代碼

2022-03-06 00:55鄭清 Java教程

本文將基于springboot實現快遞物流查詢,物流信息的獲取通過阿里云第三方實現,具有一定的參考價值,感興趣的可以了解一下

一、前言

本文將基于springboot2.4.0實現快遞物流查詢,物流信息的獲取通過阿里云第三方實現。

可參考: https://market.aliyun.com/products/57124001/cmapi022273.html?spm=5176.730005.productlist.d_cmapi022273.e8357d36FVX3Eu&innerSource=search#sku=yuncode1627300000

SpringBoot實現阿里云快遞物流查詢的示例代碼

快遞查詢API,快遞識別單號,快遞接口可查詢上百家快遞公司及物流快遞信息包括:順豐、申通、圓通、韻達、中通、匯通、EMS、天天、國通、德邦、宅急送等幾百家快遞物流公司單號查詢接口。與官網實時同步更新,包含快遞送達時間。

 

二、快遞物流查詢

注:需要購買快遞物流查詢接口服務獲取AppCode

SpringBoot實現阿里云快遞物流查詢的示例代碼

工具類

其中http請求工具類自行查看demo源碼

@Slf4j
public class LogisticUtil {

  /**
   * 查詢物流信息
   *
   * @param params 提交參數
   * @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();

      // 請求地址
      String requestUrl = String.format("https://kdwlcxf.market.alicloudapi.com/kdwlcx?no=%s&type=%s",
              no, StringUtils.isBlank(type) ? "" : type);
      // 發起請求
      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, "參數異常");
      Assert.isTrue(logisticApiResult.getStatus() == 0, logisticApiResult.getMsg());
      return logisticApiResult.getResult();
  }
}

請求實體類

@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("物流-查詢參數")
public class LogisticDTO {

  @ApiModelProperty(value = "快遞單號 【順豐請輸入運單號 : 收件人或寄件人手機號后四位。例如:123456789:1234】", required = true, example = "780098068058")
  private String no;

  @ApiModelProperty(value = "快遞公司代碼: 可不填自動識別,填了查詢更快【代碼見附表】", required = true, example = "zto")
  private String type;

  @ApiModelProperty(value = "appCode", required = true, example = "xxx")
  private String appCode;
}

響應實體類

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("物流-api響應結果")
public class LogisticApiResult {

  @ApiModelProperty("狀態碼")
  private Integer status;

  @ApiModelProperty("提示信息")
  private String msg;

  @ApiModelProperty("結果集")
  private LogisticVO result;

}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("物流-響應參數")
public class LogisticVO {

  @ApiModelProperty("運單編號")
  private String number;

  @ApiModelProperty("快遞公司編碼[見附表]")
  private String type;

  @ApiModelProperty("投遞狀態 0快遞收件(攬件)1在途中 2正在派件 3已簽收 4派送失敗 5.疑難件 6.退件簽收")
  private String deliverystatus;

  @ApiModelProperty("是否本人簽收")
  private String issign;

  @ApiModelProperty("快遞公司名字")
  private String expName;

  @ApiModelProperty("快遞公司官網")
  private String expSite;

  @ApiModelProperty("快遞公司電話")
  private String expPhone;

  @ApiModelProperty("快遞員")
  private String courier;

  @ApiModelProperty("快遞員電話")
  private String courierPhone;

  @ApiModelProperty("最新軌跡的時間")
  private String updateTime;

  @ApiModelProperty("發貨到收貨耗時(截止最新軌跡)")
  private String takeTime;

  @ApiModelProperty("快遞公司logo")
  private String logo;

  @ApiModelProperty("事件軌跡集")
  private List<LogisticItem> list;

  @Data
  @Builder
  @NoArgsConstructor
  @AllArgsConstructor
  @ApiModel("事件軌跡集")
  public static class LogisticItem {
      @ApiModelProperty("時間點")
      private String time;

      @ApiModelProperty("事件詳情")
      private String status;
  }
}

 

三、測試api

@Slf4j
@RestController
@RequestMapping("/test")
@Api(tags = "測試api")
public class TestController {

  @ApiOperation("查詢物流信息")
  @GetMapping("getLogistic")
  public LogisticVO getLogistic(@ModelAttribute LogisticDTO params) {
      return LogisticUtil.getLogisticInfo(params);
  }

}

接口文檔 http://127.0.0.1/doc.html

SpringBoot實現阿里云快遞物流查詢的示例代碼

本文demo源碼

https://gitee.com/zhengqingya/java-workspace

到此這篇關于SpringBoot實現阿里云快遞物流查詢的示例代碼的文章就介紹到這了,更多相關SpringBoot 阿里云快遞物流查詢內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!

原文鏈接:https://zhengqing.blog.csdn.net/article/details/120927980

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: poren18日本老师hd | 精品湿 | 公交车强校花系列小说 | 贰佰麻豆剧果冻传媒一二三区 | 99在线观看视频免费精品9 | 高清男的插曲女的 欢迎你老狼 | 久久视频这只精品99re6 | 国产三级自拍视频 | 人与蛇boxxⅹ| 三体动漫在线观看免费完整版2022 | 午夜福利理论片高清在线 | 免费看的毛片 | 精品视频 九九九 | 日本色资源 | 三级伦理在线播放 | 美女被免费视频 | 国产高清视频在线 | 成人福利视频网址 | 亚洲第一色网站 | 国产高清ujzzujzz| bt国产| 国产一卡2卡3卡四卡精品网站 | 成人在线av视频 | 国产成人高清视频 | 国产日韩视频一区 | 2021国产精品露脸在线 | 校花被吃奶还摸下面 | 国产成人精品午夜免费 | 草莓视频首页 | 精品女同同性视频很黄很色 | 国产亚洲精品激情一区二区三区 | 精品免费 | 我与么公激情性完整视频 | 好姑娘在线视频观看免费 | 国产成人免费片在线视频观看 | 欧美精品国产第一区二区 | 国产精品一区二区在线观看完整版 | 我不卡影院手机在线观看 | 女生被草| 国产亚洲精品第一综合另类 | 亚洲国产成人久久77 |