<?php
/**
* Created by PhpStorm.
* User: Yang
* Date: 2019/8/23
* Time: 10:38
*/ class Kuaidi_Query
{
private $_query_url = 'http://poll.kuaidi100.com/poll/query.do'; //实时查询请求地址
// private $_url = 'http://www.kuaidi100.com/autonumber/auto?num=906919164534&key=IobfFnLz2751'; //实时查询请求地址
private $_auto_url = 'http://www.kuaidi100.com/autonumber/auto'; //实时查询请求地址
private $_key = "";
private $_customer = "";
private $_params = array(); public function __construct($num, $com = '', $phone = '', $from = '', $to = '', $resultv2 = 1)
{
if (empty($com)) {
//归属公司智能判断
$com = $this->check($num);
}
$params = array(
'com' => $com, //快递公司编码
'num' => $num, //快递单号
'phone' => $phone, //手机号
'from' => $from, //出发地城市
'to' => $to, //目的地城市
'resultv2' => $resultv2 //开启行政区域解析
);
$this->_params = $params;
} /**
* 单号归属公司智能判断接口
* @param $num
* @return mixed
*/
public function check($num)
{
$url = $this->_auto_url."?num=".$num."&key=".$this->_key;
$data = $this->get_curl($url);
$data_array = json_decode($data, true);
return $data_array[0]['comCode'];
} /**
* 执行快递查询接口
* @return mixed
*/
public function Query()
{
$post_data = array();
$post_data["customer"] = $this->_customer;
$post_data["param"] = json_encode($this->_params);
$sign = md5($post_data["param"] . $this->_key . $post_data["customer"]);
$post_data["sign"] = strtoupper($sign);
$params = "";
foreach ($post_data as $k => $v) {
$params .= "$k=" . urlencode($v) . "&"; //默认UTF-8编码格式
}
$post_data = substr($params, 0, -1);
$query_data = $this->post_curl($this->_query_url, $post_data);
return $query_data;
} /**
* get 请求
* @param $url
* @return mixed
*/
public function get_curl($url) {
$ch = curl_init();//初始化
curl_setopt($ch, CURLOPT_URL, $url);//访问的URL
curl_setopt($ch, CURLOPT_HEADER, false);//设置不需要头信息
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//只获取页面内容,但不输出
$result = curl_exec($ch);//执行请求
curl_close($ch);//关闭curl,释放资源
$data = str_replace("\"", '"', $result);
return $result;
} /**
* post 请求
* @param $post_data
* @return mixed
*/
public function post_curl($url, $post_data)
{
//发送post请求
$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);
$result = curl_exec($ch);
$data = str_replace("\"", '"', $result);
$data = json_decode($data, true);
return $data;
}
}

使用方式:

<?php
/**
* Created by PhpStorm.
* User: Yang
* Date: 2019/8/23
* Time: 11:03
*/ include "../../Kuaidi_Query.php"; $k = new Kuaidi_Query(3950055201640);
$data = $k->Query();
if ($data['message'] == "ok") {
$list = $data['data'];
var_dump($list);
}else{
var_dump($data['message']);
}

结果展示:

array(11) {
[0]=>
array(6) {
["time"]=>
string(19) "2019-03-23 13:21:54"
["context"]=>
string(115) "【武汉市】 已签收 : 由董雨昂(金龙·四季阳光 )代签收,如有问题联系董雨昂(13147108459)"
["ftime"]=>
string(19) "2019-03-23 13:21:54"
["areaCode"]=>
NULL
["areaName"]=>
NULL
["status"]=>
string(6) "签收"
}
[1]=>
array(6) {
["time"]=>
string(19) "2019-03-23 09:13:51"
["context"]=>
string(106) "【武汉市】 湖北武汉黄陂区公司杨园分部 派件员 董雨昂(13147108459)正在为您派送"
["ftime"]=>
string(19) "2019-03-23 09:13:51"
["areaCode"]=>
string(14) "CN420116000000"
["areaName"]=>
string(26) "湖北,武汉市,黄陂区"
["status"]=>
string(6) "派件"
}
[2]=>
array(6) {
["time"]=>
string(19) "2019-03-23 06:55:27"
["context"]=>
string(113) "【武汉市】 已离开 湖北武汉黄陂区公司 发往 湖北武汉黄陂区公司杨园分部(15391528386)"
["ftime"]=>
string(19) "2019-03-23 06:55:27"
["areaCode"]=>
NULL
["areaName"]=>
NULL
["status"]=>
string(6) "在途"
}
[3]=>
array(6) {
["time"]=>
string(19) "2019-03-23 06:52:47"
["context"]=>
string(72) "【武汉市】 已到达 湖北武汉黄陂区公司 马上为您派送"
["ftime"]=>
string(19) "2019-03-23 06:52:47"
["areaCode"]=>
string(14) "CN420116000000"
["areaName"]=>
string(26) "湖北,武汉市,黄陂区"
["status"]=>
string(6) "派件"
}
[4]=>
array(6) {
["time"]=>
string(19) "2019-03-22 20:30:30"
["context"]=>
string(50) "【武汉市】 已到达 湖北武汉分拨中心"
["ftime"]=>
string(19) "2019-03-22 20:30:30"
["areaCode"]=>
string(14) "CN420100000000"
["areaName"]=>
string(16) "湖北,武汉市"
["status"]=>
string(6) "在途"
}
[5]=>
array(6) {
["time"]=>
string(19) "2019-03-22 20:30:27"
["context"]=>
string(85) "【武汉市】 已离开 湖北武汉分拨中心 发往 湖北武汉黄陂区公司"
["ftime"]=>
string(19) "2019-03-22 20:30:27"
["areaCode"]=>
NULL
["areaName"]=>
NULL
["status"]=>
string(6) "在途"
}
[6]=>
array(6) {
["time"]=>
string(19) "2019-03-22 20:15:30"
["context"]=>
string(50) "【武汉市】 已到达 湖北武汉分拨中心"
["ftime"]=>
string(19) "2019-03-22 20:15:30"
["areaCode"]=>
string(14) "CN420100000000"
["areaName"]=>
string(16) "湖北,武汉市"
["status"]=>
string(6) "在途"
}
[7]=>
array(6) {
["time"]=>
string(19) "2019-03-22 00:48:37"
["context"]=>
string(82) "【汕头市】 已离开 广东揭阳分拨中心 发往 湖北武汉分拨中心"
["ftime"]=>
string(19) "2019-03-22 00:48:37"
["areaCode"]=>
NULL
["areaName"]=>
NULL
["status"]=>
string(6) "在途"
}
[8]=>
array(6) {
["time"]=>
string(19) "2019-03-22 00:46:46"
["context"]=>
string(50) "【汕头市】 已到达 广东揭阳分拨中心"
["ftime"]=>
string(19) "2019-03-22 00:46:46"
["areaCode"]=>
string(14) "CN440500000000"
["areaName"]=>
string(16) "广东,汕头市"
["status"]=>
string(6) "在途"
}
[9]=>
array(6) {
["time"]=>
string(19) "2019-03-21 20:32:50"
["context"]=>
string(94) "【汕头市】 已离开 广东汕头潮阳区公司陈店分部 发往 湖北武汉网点包"
["ftime"]=>
string(19) "2019-03-21 20:32:50"
["areaCode"]=>
NULL
["areaName"]=>
NULL
["status"]=>
string(6) "在途"
}
[10]=>
array(6) {
["time"]=>
string(19) "2019-03-21 19:05:50"
["context"]=>
string(65) "【汕头市】 广东汕头潮阳区公司陈店分部 已揽收"
["ftime"]=>
string(19) "2019-03-21 19:05:50"
["areaCode"]=>
string(14) "CN440513000000"
["areaName"]=>
string(26) "广东,汕头市,潮阳区"
["status"]=>
string(6) "揽收"
}
}

PHP 之快递100接口封装的更多相关文章

  1. php利用快递100接口获取物流信息

    PHP使用CURL调用快递100接口查询运单信息 类代码如下: <?php/** * 快递100接口调用类 * @author 齐云海 * date: 2019/05/29 */ class E ...

  2. 在Asp.Net MVC中利用快递100接口实现订阅物流轨迹功能

    前言 分享一篇关于在电商系统中同步物流轨迹到本地服务器的文章,当前方案使用了快递100做为数据来源接口,这个接口是收费的,不过提供的功能还是非常强大的,有专门的售后维护团队.也有免费的方案,类似于快递 ...

  3. PHP最近做了物流快递查询的接口用得是快递100

    最近做了物流快递查询的接口用得是快递100的,分享下心得体会 主要使用了2种接口,一个是api的 返回json xml 各种数据的 一个是返回的URL的  就是一个带结果的网址  . 1  申请 找一 ...

  4. Delphi xe 10.3.2-快递接口封装-【快递鸟(即时查询和单号识别)】

    编译环境:Windows 7 +Delphi xe 10.3.2 封装了快递鸟接口,注意的坑:MD5要转为小写. function TKDniaoAPI.StrtoMd5(const str: str ...

  5. .netcore 写快递100的快递物流信息查询接口

    快递100的物流信息查询接口,官方提供了一些demo;还好官方提供的代码是.netcore版本写的,不过写的有点low;根据官方提供的代码,我按照.netcore 的风格重构了代码:核心代码如下: / ...

  6. java抓取快递100信息接口

    package zeze; import java.io.IOException; import org.json.JSONArray; import org.json.JSONException; ...

  7. 快速上手微信小程序-快递100

    2007 年 1 月 9 日,乔布斯在旧金山莫斯科尼会展中心发布了首款 iPhone,而在十年后的 1 月 9 日,微信小程序正式上线.张小龙以这样的形式,向乔布斯致敬. 小程序在哪里? 小程序功能模 ...

  8. Java微信公众平台接口封装源码分享

    前言:      这篇博客是在三月初动手项目的时候准备写的,但是为了完成项目只好拖延时间写这篇博客,顺便也可以在项目中应用我自己总结的的一些经验.今天看来,这些方法的应用还是可以的,至少实现了我之前的 ...

  9. C#快递跟踪(基于快递100深度定制)

    本文主要介绍快递跟踪的相关信息.如根据快递单号预测所属快递公司,判断快递是否已被签收,以及改良官方model后可在不用申请授权的情况下实现json,html,xml及text等多种格式以及单行多行,降 ...

随机推荐

  1. requests Use body.encode('utf-8') if you want to send it encoded in UTF-8

    基本环境 使用 requests 模块发送 post 请求,请求体包含中文报错 系统环境:centos7.3 python版本:python3.6.8 请求代码: // 得到中文 param_json ...

  2. default(Nullable(type)) vs default(type)

    default(Nullable<long>) == null default(long?) == null default(long) == 0L

  3. ifeq ifneq ifdef ifndef

    条件语句中使用到了三个关键字:“ifeq”.“else”和“endif”.其中: 1.        “ifeq”表示条件语句的开始,并指定了一个比较条件(相等).之后是用圆括号括包围的.使用逗号“, ...

  4. OpenStack kilo版(1) 部署环境

    硬件 VMware workstation虚拟机 Ubuntu14.04操作系统 虚拟机网络规划 管理网络: eth0, 桥接模式 10.0.0.0/24 外部网络: eth1, nat模式(需要关闭 ...

  5. kafka连接storm问题

    遇到缺少jar包的报错,参考https://www.jianshu.com/p/70c3a7f56386 参考上面的链接把jar包都放到storm/lib目录下后,使用localCluster的方法提 ...

  6. Linux学习之九-Linux系统定时任务

    Linux系统定时任务 在一些实际工作中需要机器在某个时间自动执行某个任务,不需要人为在此时刻参与,可以建立一个定时任务. crond 服务是linux下用来周期性的执行某种任务或等待处理某些事件的一 ...

  7. chkconfig 系统服务管理

    chkconfig --list   显示当前运行的所有服务/etc/inittabnetstat -antl   all n端口 t tcp协议 l listen状态chkconfig --add ...

  8. 使用phpstudy搭建的外网网站 运行很慢 解决办法

    将连接数据库的配置文件 localhost  修改为127.0.0.1 PHP5.3以上,如果是链接localhost,会检测是IPV4还是IPV6,所以会比较慢.解决办法是:链接数据的时候,不要填写 ...

  9. 陈硕muduo

    https://github.com/chenshuo/muduo muduo 阅读 https://www.cnblogs.com/qbits/p/11101678.html

  10. Selenium(三)webdriver的API与定位元素

    在学习定位元素之前,应该要学会: 1.打开浏览器 2.打开网页 3.定位元素及操作 ①定位元素 可只此输入框的id是kw,name是wd,class是s_ipt ②在python编辑器中找到该元素 通 ...