Skip to content

Commit

Permalink
add test and fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
inbjo committed Apr 26, 2019
1 parent c6a0b67 commit 2bce222
Show file tree
Hide file tree
Showing 12 changed files with 462 additions and 252 deletions.
4 changes: 2 additions & 2 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
$header = <<<EOF
This file is part of the flex/express.
This file is part of the Flex/Express.
(c) flex <[email protected]>
(c) Flex <[email protected]>
This source file is subject to the MIT license that is bundled.
EOF;
Expand Down
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: php # 我们代码所需要运行的环境平台

php: # 需要测试的版本
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3

dist: trusty # 系统版本
sudo: false # 使用使用 sudo 模式

# 执行前需要运行的命令
install: travis_retry composer install --no-interaction --prefer-source

# 主要构建命令
script: vendor/bin/phpunit --verbose
158 changes: 133 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,162 @@
<h1 align="center"> express </h1>
<h1 align="center"> Express </h1>

<p align="center">支持快递鸟、快递100的快递查询SDK</p>

[![Build Status](https://travis-ci.org/inbjo/express.svg?branch=master)](https://travis-ci.org/inbjo/express)

## Installing

## 安装

```shell
$ composer require flex/express -vvv
```
## 配置

在使用本扩展之前,你需要去 [快递100](https://www.kuaidi100.com/openapi/applyapi.shtml) 或者 [快递鸟](http://www.kdniao.com/reg) 注册申请,获取到APP_id和APP_key。

## Usage
### 快递100
```php
use Flex\Express\Kuaidi100;
use Flex\Express\Express100;

//初始化类
$express = new Kuaidi100('app_id','app_key');
//查询物流 快递单号 物流公司编号 手机人手机号(顺丰必填 其他快递选填)
$info = $express->track($tracking_code, $shipping_code, $phone);
$express = new Express100('app_id','app_key');
$info = $express->track($tracking_code, $shipping_code, $phone); //快递单号 物流公司编号 收件人手机号(顺丰必填 其他快递选填)
```
示例:
```json
{
"message": "ok",
"nu": "888888888888",
"ischeck": "1",
"condition": "F00",
"com": "shunfeng",
"status": "200",
"state": "3",
"data": [
{
"time": "2019-03-08 19:11:51",
"ftime": "2019-03-08 19:11:51",
"context": "[安高广场速运营业点]快件已发车"
},
{
"time": "2019-03-08 18:56:12",
"ftime": "2019-03-08 18:56:12",
"context": "[安高广场速运营业点]快件在【合肥蜀山区安高广场营业点】已装车,准备发往 【合肥经开集散中心】"
},
{
"time": "2019-03-08 18:50:52",
"ftime": "2019-03-08 18:50:52",
"context": "[安高广场速运营业点]顺丰速运 已收取快件"
}
]
}
```

### 快递鸟
```php
use Flex\Express\Kdniao;
use Flex\Express\ExpressBird;

//初始化类
$express = new Kdniao('app_id','app_key');
//查询物流 快递单号 物流公司编号 订单编号(选填)
$info = $express->track($tracking_code, $shipping_code,$order_code);
$express = new ExpressBird('app_id','app_key');
$info = $express->track($tracking_code, $shipping_code,$order_code); //快递单号 物流公司编号 订单编号(选填)
```
示例:
```json
{
"LogisticCode": "8888888888888888",
"ShipperCode": "YTO",
"Traces": [
{
"AcceptStation": "【四川省直营市场部公司】 取件人: 四川省直营市场部41 已收件",
"AcceptTime": "2019-03-21 11:03:40"
},
{
"AcceptStation": "【四川省直营市场部公司】 已收件",
"AcceptTime": "2019-03-21 13:45:01"
},
{
"AcceptStation": "【成都转运中心】 已收入",
"AcceptTime": "2019-03-21 22:40:01"
}
],
"State": "3",
"OrderCode": "",
"EBusinessID": "100000",
"Success": true
}
```
### 通用方法
```php
use Flex\Express\Express;

//初始化类 $type支持类型'kuaidi100'、'kdniao'
$express = new Express($app_id,$app_key,$type);
//查询物流 快递单号 额外参数
//快递鸟$additional=['order_code'=>111111] 快递100 $additional=['phone'=>'18899996666']
$info = $express->track($tracking_code, $shipping_code,$additional);
```

## Contributing

You can contribute in one of three ways:
$express = new Express($app_id,$app_key,$type); //$type支持类型'express100'、'expressbird'

1. File bug reports using the [issue tracker](https://github.com/inbjo/express/issues).
2. Answer questions or fix bugs on the [issue tracker](https://github.com/inbjo/express/issues).
3. Contribute new features or update the wiki.
//快递鸟$additional=['order_code'=>111111] 快递100 $additional=['phone'=>'18899996666']
$info = $express->track($tracking_code, $shipping_code,$additional); ////查询物流 快递单号 额外参数
```

_The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable._
### 在 Laravel 中使用

在 Laravel 中使用也是同样的安装方式,配置写在 `config/services.php` 中:

```php
.
.
.
'express' => [
'id' => env('EXPRESS_ID'),
'key' => env('EXPRESS_KEY'),
'type' => env('EXPRESS_TYPE'),
],
```

然后在 `.env` 中配置 `EXPRESS_ID``EXPRESS_KEY``EXPRESS_TYPE`

```env
EXPRESS_ID=xxxxxxxxxxxxxxxxxxxxx
EXPRESS_KEY=xxxxxxxxxxxxxxxxxxxxx
EXPRESS_TYPE=express100
```

可以用两种方式来获取 `Flex\Express\Express` 实例:

#### 方法参数注入

```php
.
.
.
public function edit(Express $express)
{
$response = $express->track('888888888','YTO');
}
.
.
.
```

#### 服务名访问

```php
.
.
.
public function edit()
{
$response = app('express')->track('888888888','YTO');
}
.
.
.

```

## 参考

- [快递100接口文档](https://www.kuaidi100.com/openapi/api_post.shtml)
- [快递100快递公司编码](https://blog.csdn.net/u011816231/article/details/53063611)
- [快递鸟接口文档](http://www.kdniao.com/documents)
- [快递鸟快递公司编码](http://www.kdniao.com/documents)

## License

Expand Down
3 changes: 0 additions & 3 deletions src/Exceptions/Exception.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php


namespace Flex\Express\Exceptions;


class Exception extends \Exception
{

Expand Down
3 changes: 0 additions & 3 deletions src/Exceptions/HttpException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php


namespace Flex\Express\Exceptions;


class HttpException extends Exception
{

Expand Down
3 changes: 0 additions & 3 deletions src/Exceptions/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php


namespace Flex\Express\Exceptions;


class InvalidArgumentException extends Exception
{

Expand Down
12 changes: 6 additions & 6 deletions src/Express.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Express
* @param string $type
* @throws InvalidArgumentException
*/
public function __construct($app_id, $app_key, $type = 'kuaidi100')
public function __construct($app_id, $app_key, $type = 'express100')
{
if (empty($app_id)) {
throw new InvalidArgumentException('APP Id Can not be empty');
Expand All @@ -29,7 +29,7 @@ public function __construct($app_id, $app_key, $type = 'kuaidi100')
throw new InvalidArgumentException('APP key Can not be empty');
}

if (!in_array(strtolower($type), ['kuaidi100', 'kdniao'])) {
if (!in_array(strtolower($type), ['express100', 'expressbird'])) {
throw new InvalidArgumentException('Unsupported Type');
}

Expand All @@ -49,23 +49,23 @@ public function __construct($app_id, $app_key, $type = 'kuaidi100')
*/
public function track($tracking_code, $shipping_code, $additional = [])
{
if ($this->type == 'kuaidi100') {
if ($this->type == 'express100') {
if (isset($additional['phone'])) {
$phone = $additional['phone'];
} else {
$phone = '';
}
$express = new Kuaidi100($this->app_id, $this->app_key);
$express = new Express100($this->app_id, $this->app_key);
return $express->track($tracking_code, $shipping_code, $phone);
}

if ($this->type == 'kdniao') {
if ($this->type == 'expressbird') {
if (isset($additional['order_code'])) {
$order_code = $additional['order_code'];
} else {
$order_code = '';
}
$express = new Kdniao($this->app_id, $this->app_key);
$express = new ExpressBird($this->app_id, $this->app_key);
return $express->track($tracking_code, $shipping_code, $order_code);
}

Expand Down
Loading

0 comments on commit 2bce222

Please sign in to comment.