快递鸟常用免费快递单号物流查询API接口集成案例

随着科技的发展进步,互联网行业的发展,网购已经成为了当下一种主流的消费方式。电商平台及ISV商家对物流api接口的需求有很多,快递单号查询api接口适用于涉及经常发货、寄快递的人群、企业、电商网站、微信公众号平台等对接使用。支持国内外四百多家快递及物流公司的快递单号一站式查询。
【对接使用流程】
 1、将快递单号和快递公司编码发送給快递鸟
 2、快递鸟根据单号和快递公司查询到物流轨迹状态
 3、快递鸟将查询到的物流轨迹状态反馈給电商平台或ISV服务商
 4、电商平台或ISV服务商接收数据并实时处理做数据展示或应用
使用说明:
1.KdniaoAPI.php 不需要修改任何东西
2.example.php 按照说明使用
3.KdniaoAPI.php 代码示例

其他Demo去快递鸟官网免费下载(http://www.kdniao.com/reg)

<?php
//电商ID
defined('EBusinessID') or define('EBusinessID', '请到快递鸟官网申请http://kdniao.com/reg');
//电商加密私钥,快递鸟提供,注意保管,不要泄漏
defined('AppKey') or define('AppKey', '请到快递鸟官网申请http://kdniao.com/reg');
//请求url
defined('ReqURL') or define('ReqURL', 'http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx');
//调用查询物流轨迹
//---------------------------------------------
$logisticResult=getOrderTracesByJson();
echo logisticResult;
//---------------------------------------------
 /**
 * Json方式 查询订单物流轨迹
 */
function getOrderTracesByJson(){
	$requestData= "{'OrderCode':'','ShipperCode':'YTO','LogisticCode':'12345678'}";
		$datas = array(
        'EBusinessID' => EBusinessID,
        'RequestType' => '1002',
        'RequestData' => urlencode($requestData) ,
        'DataType' => '2',
    );
    $datas['DataSign'] = encrypt($requestData, AppKey);
	$result=sendPost(ReqURL, $datas);	
		//根据公司业务处理返回的信息......
		return $result;
}
 /**
 *  post提交数据 
 * @param  string $url 请求Url
 * @param  array $datas 提交的数据 
 * @return url响应返回的html
 */
function sendPost($url, $datas) {
    $temps = array();	
    foreach ($datas as $key => $value) {
        $temps[] = sprintf('%s=%s', $key, $value);		
    }	
    $post_data = implode('&', $temps);
    $url_info = parse_url($url);
	if(empty($url_info['port']))
	{
		$url_info['port']=80;	
	}
    $httpheader = "POST " . $url_info['path'] . " HTTP/1.0
";
    $httpheader.= "Host:" . $url_info['host'] . "
";
    $httpheader.= "Content-Type:application/x-www-form-urlencoded
";
    $httpheader.= "Content-Length:" . strlen($post_data) . "
";
    $httpheader.= "Connection:close

";
    $httpheader.= $post_data;
    $fd = fsockopen($url_info['host'], $url_info['port']);
    fwrite($fd, $httpheader);
    $gets = "";
	$headerFlag = true;
	while (!feof($fd)) {
		if (($header = @fgets($fd)) && ($header == "
" || $header == "
")) {
			break;
		}
	}
    while (!feof($fd)) {
		$gets.= fread($fd, 128);
    }
    fclose($fd);  
        return $gets;
}
/**
 * 电商Sign签名生成
 * @param data 内容   
 * @param appkey Appkey
 * @return DataSign签名
 */
function encrypt($data, $appkey) {
    return urlencode(base64_encode(md5($data.$appkey)));
}
?>

  

原文地址:https://www.cnblogs.com/kdn2019/p/11447699.html