- 🕹 China ShenZhen
- 🔨 Work at Unknown
- 🐱 Life is short
uuk020 / logistics Goto Github PK
View Code? Open in Web Editor NEWPHP 多接口获取快递物流信息包
PHP 多接口获取快递物流信息包
怎么设置配置呢?
要用软链接将Config类替换吗?
文件:wythe\logistics\src\Query\Kuaidi100Query.php
行数:return $this->response;
错误:"Return value of Wythe\Logistics\Query\Kuaidi100Query::callInterface() must be of the type array, null returned"
/**
* 转为数组.
*
* @param array|string $response
*/
protected function toArray($response)
{
$jsonToArray = \json_decode($response, true);
if (empty($jsonToArray)) {
$this->response = [
'status' => 0,
'message' => '请求发生不知名错误, 查询不到物流信息',
'error_code' => 0,
'data' => [],
'logistics_company' => '',
];
} else {
if (0 === $jsonToArray['state']) {
$this->response = [
'status' => 1,
'message' => 'ok',
'error_code' => 0,
'data' => $jsonToArray['data'],
'logistics_company' => $jsonToArray['com'],
];
} else {
$this->response = [
'status' => 0,
'message' => $jsonToArray['message'],
'error_code' => $jsonToArray['state'],
'data' => [],
'logistics_company' => '',
];
}
}
$jsonToArray['state']这个状态有很多种你怎么只能判断等于0?
作者的包 ,还是可以的。但是配置文件这一点做的不好,正常情况下。vendor 目录包是不允许修改的。强烈建议配置类。做成public属性。快递参数外部可以配置
因为从逻辑上来看,输入只有两个参数:1. 单号,2. 渠道。所以变化是第二个参数,但是第二个参数的变化没有必要体现在方法名上,所以可以考虑简化一下:
array query(string $code, $gateway = ['kuaidi100'])
这样就够了,第二个你在内部实现的时候都当成数组处理就好了,用户可选,或者传字符串,内部强制转数组。
感觉有必要统一返回值格式,就像我的 easy-sms 一样,在每一个渠道自己的实现逻辑里,格式化为统一的数组模型,这样用户在调用时只需要修改渠道配置即可,不必关注修改渠道导致的返回值格式不一样需要单独写代码去处理。
请问一天能调用几次快递接口?有没有限制?
如图,这是一个我自己这两天在淘宝买的快递,快递查询的结果却是没有,或是其他的快递的???这很奇怪了。没有查到还可以理解,因为快递100首页的那个搜索框也查不到,但是居然会查询到错误的结果,这个 快递单号 多查几次,查询的结果会很不同。75155689993986
,上面这个正确的快递信息 我是用这个接口查的 实时查询
$logistics = new Logistics();
$result = $logistics->query('75155689993986'); // 第二参数不设,则默认快递100接口
print_r($result);
单号:820182839908 圆通快递
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.