【小程序】快递100智能获取物流公司和物流信息

举个例子,如何只通过一个单号,获取到物流单号的物流信息。要用到下面两个接口,免费,无需注册快递100的key就可以用。

智能识别接口

接口地址:http://www.kuaidi100.com/autonumber/autoComNum?text=[单号]
请求方式:GET

物流详情接口

接口地址:http://www.kuaidi100.com/query?type=[comCode]&postid=[单号]
请求方式:GET

  1. 用快递100页面的快递单号例子

【小程序】快递100智能获取物流公司和物流信息_第1张图片

2.先通过智能接口,获取物流公司编码,获取的数据作为参数,通过物流接口去获取物流信息。

var type;
var postid =  '640025148516';
wx.request({
	url: 'http://www.kuaidi100.com/autonumber/autoComNum',
	data: {
		text: postid
	},
	method: 'GET',
	success: function(res){
		console.log(res)
		var type = res.data.auto[0].comCode;
	}, 
	complete: function(){
		wx.request({
			url: 'http://www.kuaidi100.com/query',
			data: {
				type: type,
				postid: postid
			},
			method: 'GET',
			success: function(res){
				console.log(res)
			}
		})
	}
})

第一个输出,返回三个物流公司编码,一般第一个就是的了。
【小程序】快递100智能获取物流公司和物流信息_第2张图片

第二个输出,data数组里面就是物流详情,可以看到还有com物流公司编码,nu物流单号,status为200,表示这个单号正常。
【小程序】快递100智能获取物流公司和物流信息_第3张图片

你可能感兴趣的:(小程序)