php 快递100接口

/**
	物流  快递100
	
	name   物流公司名称 (shunfeng 顺丰) 可在官网查看物流公司的简称

	number   单号
	
*/
function logistics($name,$number){
	

    //参数设置
    $post_data = array();
    $post_data["customer"] = '***************';
    $key= 'key' ;
	
	$data['com']=$name;  //查询的快递公司的编码, 一律用小写字母
	$data['num']=$number;  //查询的快递单号, 单号的最大长度是32个字符 358263398950
    $post_data["param"] =json_encode($data);

    $url='http://poll.kuaidi100.com/poll/query.do';
    $post_data["sign"] = md5($post_data["param"].$key.$post_data["customer"]);
    $post_data["sign"] = strtoupper($post_data["sign"]);
    $o="";
    foreach ($post_data as $k=>$v)
    {
        $o.= "$k=".urlencode($v)."&";		//默认UTF-8编码格式
    }
    $post_data=substr($o,0,-1);
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data);
	curl_setopt($ch, CURLOPT_TIMEOUT,3);
	$result = curl_exec($ch);	

	//$data = str_replace("\"",'"',$result );
	$data = json_decode($result,true);
	//dump($data);
	return  $data;
}

猜你喜欢

转载自blog.csdn.net/qq_18105691/article/details/79543203