快宝 第三方物流查询

一、快宝第三方

第三方快递api还蛮多的,选择快宝的原因是因为老板觉得价格便宜......

物流单号查询|物流跟踪API|运单号查询|运单查询API文档_快宝开放平台

二、使用步骤

1.物流查询

/*

@method 物流查询接口

@param string waybill_codes 物流单号

*/

function express_query($waybill_code)

{

// 公共参数设置

// 正式地址

$host = "https://kop.kuaidihelp.com/api";

$headers = array();

// Content-Type定义

array_push($headers, "Content-Type" . ":" . "application/x-www-form-urlencoded; charset=UTF-8");

$appId = "appId"; // 替换成你真实的值

$ts = time();

$appKey = "appKey";// 替换成你真实的值

// 接口名称

$method = "express.info.get";

// 请求参数设置

$data = [

"waybill_codes" => $waybill_code,

"result_sort" => 0,

];

// 参数主体

$bodys = [

"app_id" => $appId,

"method" => $method,

"sign" => md5($appId . $method . $ts . $appKey),

"ts" => $ts,

"data" => json_encode($data)

];

$bodys = http_build_query($bodys);

$url = $host;

$curl = curl_init();

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");

curl_setopt($curl, CURLOPT_URL, $url);

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

curl_setopt($curl, CURLOPT_FAILONERROR, false);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

curl_setopt($curl, CURLOPT_HEADER, false);

if (1 == strpos("$" . $host, "https://")) {

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

}

curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);

echo (curl_exec($curl));

}

2.智能识别单号品牌

/*

@method 物流查询接口

@param string waybill_codes 物流单号

*/

function express_query($waybill_code)

{

// 公共参数设置

// 正式地址

$host = "https://kop.kuaidihelp.com/api";

$headers = array();

// Content-Type定义

array_push($headers, "Content-Type" . ":" . "application/x-www-form-urlencoded; charset=UTF-8");

$appId = "appId";

$ts = time();

$appKey = "appKey";

// 接口名称

$method = "express.brand.identify";

// 智能识别单号品牌

$data = [

"waybill_code" => $waybill_code

];

// 参数主体

$bodys = [

"app_id" => $appId,

"method" => $method,

"sign" => md5($appId . $method . $ts . $appKey),

"ts" => $ts,

"data" => json_encode($data)

];

$bodys = http_build_query($bodys);

$url = $host;

$curl = curl_init();

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");

curl_setopt($curl, CURLOPT_URL, $url);

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

curl_setopt($curl, CURLOPT_FAILONERROR, false);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

curl_setopt($curl, CURLOPT_HEADER, false);

if (1 == strpos("$" . $host, "https://")) {

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

}

curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);

echo (curl_exec($curl));

}

3.合并

物流查询

识别单号品牌

除了以上截图的地方有区别其他是相同的代码,可以多接收一个type或则别的用来区分参数,通过if判断一下请求哪一个方法,将他们合并成一个方法

// 订单参数设置

if ($type == 1) {

// 接口名称

$method = "express.info.get";

// 物流查询

$data = [

"waybill_codes" => $waybill_code,

"result_sort" => 0,

];

} else if ($type == 2) {

// 接口名称

$method = "express.brand.identify";

// 智能识别单号品牌

$data = [

"waybill_code" => $waybill_code

];

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值