ThinkPHP5快递物流
ThinkPHP5快递物流
快递110物流:
//查看物流
public function wuliu(){
header("Content-Type: text/html;charset=utf-8");
// $uid = input('uid');
$d_id = input('d_id');
$data = [
'd_id' => $d_id
];
$validate = validate('place');
// 验证器
if (!$validate->scene('d_id')->check($data)) {
return json('100', $validate->getError(), $data);
}
// $order = Db::name('order')->where('id', $d_id)->find();
// $wuliugs = Db::name('logis')->where('id',$order['wuliugs'])->value('code');
$wuliugs= 'yuantong';
$order['wuliuh'] = 'YT4510694886818';
getOrderTracesByJson($order['wuliuh'],$wuliugs);
}/**
* Json方式 查询订单物流轨迹
*/
function getOrderTracesByJson($ding,$code){
header("Content-Type: text/html;charset=utf-8");
$secret = config_group('web_wuliu');
//参数设置
$post_data = array();
$post_data["customer"] = $secret['customer'];
$key= $secret['key'];
$post_data["param"] = json_encode(['com'=>$code,'num'=>$ding]);
$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_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$response = json_decode($response,true);
curl_close($ch);
if(array_key_exists('returnCode',$response)){
if($response['returnCode'] == 500){
$response['status'] = 500;
echo json_encode($response,256);
}else if($response['returnCode'] == 400){
$response['status'] = 400;
echo json_encode($response,256);
}else{
$response['status'] = 404;
echo json_encode($response,256);
}
}else{
$kd_name = Db::name('logis')->where(['code'=>$response['com']])->value('name');
$response['kd_name'] = $kd_name;
echo json_encode($response,256);
}
//echo json_encode($response,256);
die;
}快递配置:
key:xxxxxx customer:xxxxxxxxxxxxxxxxxx
数据库:
CREATE TABLE `bc_logis` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID', `name` varchar(50) CHARACTER SET utf8 DEFAULT NULL COMMENT '快递公司名称', `tel` varchar(50) CHARACTER SET utf8 DEFAULT NULL COMMENT '电话', `status` int(10) DEFAULT '0' COMMENT '状态0:启动,1:关闭', `create_time` varchar(50) CHARACTER SET utf8 DEFAULT NULL COMMENT '时间', `code` varchar(50) CHARACTER SET utf8 DEFAULT NULL COMMENT '编码', PRIMARY KEY (`id`) USING BTREE ) ENGINE=MyISAM AUTO_INCREMENT=455 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;