SpringBoot实现阿里云快递物流查询的示例代码
程序员文章站
2022-03-09 19:36:32
一、前言本文将基于springboot2.4.0实现快递物流查询,物流信息的获取通过阿里云第三方实现可参考: https://market.aliyun.com/products/57124001/c...
一、前言
本文将基于springboot2.4.0实现快递物流查询,物流信息的获取通过阿里云第三方实现
快递查询api,快递识别单号,快递接口可查询上百家快递公司及物流快递信息包括:顺丰、申通、圆通、韵达、中通、汇通、ems、天天、国通、德邦、宅急送等几百家快递物流公司单号查询接口。与官网实时同步更新,包含快递送达时间。
二、快递物流查询
注:需要购买快递物流查询接口服务获取appcode
工具类
其中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
本文demo源码
https://gitee.com/zhengqingya/java-workspace
到此这篇关于springboot实现阿里云快递物流查询的示例代码的文章就介绍到这了,更多相关springboot 阿里云快递物流查询内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!