Skip to content

Commit

Permalink
快递鸟网关优化BUG修复
Browse files Browse the repository at this point in the history
  • Loading branch information
laishuqing committed Aug 3, 2020
1 parent 8d037ad commit c874cfc
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
18 changes: 18 additions & 0 deletions src/Exceptions/GatewayAvailableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public function __construct(array $results = [], $code = 0, Throwable $previous
parent::__construct('The gateways have failed. You can check "\Overbeck\Logistics\Interfaces\GatewayAvailableInterface" to get the results', $code, $previous);
}

/**
* 获取结果.
*
* @return array
*
* @author ShuQingZai<929024757@qq.com>
*/
public function getResults(): array
{
return $this->results;
Expand All @@ -53,13 +60,24 @@ public function getException(string $gateway)
return $this->exceptions[$gateway] ?? null;
}

/**
* 获取所有网关异常.
*
* @return array
*
* @author ShuQingZai<929024757@qq.com>
*/
public function getExceptions(): array
{
return $this->exceptions;
}

/**
* 获取以后一个异常.
*
* @return mixed
*
* @author ShuQingZai<929024757@qq.com>
*/
public function getLastException()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Gateways/KuaidiniaoGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function queryCompanyCode(string $logisticNumber): string
$response = \json_decode($response, true);
}

$code = $response['Shipper'][0]['ShipperCode'] ?? null;
$code = $response['Shippers'][0]['ShipperCode'] ?? null;

if (empty($response) || \is_null($code)) {
throw new GatewayErrorException('Could not find this company code.', 404, (array) $response);
Expand Down
31 changes: 27 additions & 4 deletions src/Supports/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Arr
/**
* Add an element to an array using "dot" notation if it doesn't exist.
*
* @param array $array
* @param string $key
* @param mixed $value
*
Expand Down Expand Up @@ -66,6 +67,7 @@ public static function crossJoin(...$arrays)
/**
* Divide an array into two arrays. One with keys and the other with values.
*
* @param array $array
* @return array
*/
public static function divide(array $array)
Expand All @@ -76,6 +78,7 @@ public static function divide(array $array)
/**
* Flatten a multi-dimensional associative array with dots.
*
* @param array $array
* @param string $prepend
*
* @return array
Expand All @@ -98,6 +101,7 @@ public static function dot(array $array, $prepend = '')
/**
* Get all of the given array except for a specified array of items.
*
* @param array $array
* @param array|string $keys
*
* @return array
Expand All @@ -112,6 +116,7 @@ public static function except(array $array, $keys)
/**
* Determine if the given key exists in the provided array.
*
* @param array $array
* @param string|int $key
*
* @return bool
Expand All @@ -124,7 +129,9 @@ public static function exists(array $array, $key)
/**
* Return the first element in an array passing a given truth test.
*
* @param mixed $default
* @param array $array
* @param callable|null $callback
* @param mixed $default
*
* @return mixed
*/
Expand Down Expand Up @@ -152,7 +159,9 @@ public static function first(array $array, callable $callback = null, $default =
/**
* Return the last element in an array passing a given truth test.
*
* @param mixed $default
* @param array $array
* @param callable|null $callback
* @param mixed $default
*
* @return mixed
*/
Expand All @@ -168,7 +177,8 @@ public static function last(array $array, callable $callback = null, $default =
/**
* Flatten a multi-dimensional array into a single level.
*
* @param int $depth
* @param array $array
* @param int $depth
*
* @return array
*/
Expand All @@ -190,6 +200,7 @@ public static function flatten(array $array, $depth = INF)
/**
* Remove one or many array items from a given array using "dot" notation.
*
* @param array $array
* @param array|string $keys
*/
public static function forget(array &$array, $keys)
Expand Down Expand Up @@ -232,6 +243,7 @@ public static function forget(array &$array, $keys)
/**
* Get an item from an array using "dot" notation.
*
* @param array $array
* @param string $key
* @param mixed $default
*
Expand Down Expand Up @@ -261,6 +273,7 @@ public static function get(array $array, $key, $default = null)
/**
* Check if an item or items exist in an array using "dot" notation.
*
* @param array $array
* @param string|array $keys
*
* @return bool
Expand Down Expand Up @@ -305,6 +318,7 @@ public static function has(array $array, $keys)
*
* An array is "associative" if it doesn't have sequential numerical keys beginning with zero.
*
* @param array $array
* @return bool
*/
public static function isAssoc(array $array)
Expand All @@ -317,6 +331,7 @@ public static function isAssoc(array $array)
/**
* Get a subset of the items from the given array.
*
* @param array $array
* @param array|string $keys
*
* @return array
Expand All @@ -329,6 +344,7 @@ public static function only(array $array, $keys)
/**
* Push an item onto the beginning of an array.
*
* @param array $array
* @param mixed $value
* @param mixed $key
*
Expand All @@ -348,6 +364,7 @@ public static function prepend(array $array, $value, $key = null)
/**
* Get a value from the array, and remove it.
*
* @param array $array
* @param string $key
* @param mixed $default
*
Expand All @@ -365,6 +382,8 @@ public static function pull(array &$array, $key, $default = null)
/**
* Get a 1 value from an array.
*
* @param array $array
* @param int|null $amount
* @return mixed
*/
public static function random(array $array, int $amount = null)
Expand All @@ -389,7 +408,9 @@ public static function random(array $array, int $amount = null)
*
* If no key is given to the method, the entire array will be replaced.
*
* @param mixed $value
* @param array $array
* @param string $key
* @param mixed $value
*
* @return array
*/
Expand Down Expand Up @@ -418,6 +439,8 @@ public static function set(array &$array, string $key, $value)
/**
* Filter the array using the given callback.
*
* @param array $array
* @param callable $callback
* @return array
*/
public static function where(array $array, callable $callback)
Expand Down
4 changes: 4 additions & 0 deletions src/Supports/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Collection implements Countable, IteratorAggregate, JsonSerializable, Seri

/**
* set data.
*
* @param array $items
*/
public function __construct(array $items = [])
{
Expand All @@ -55,6 +57,7 @@ public function all()
/**
* Return specific items.
*
* @param array $keys
* @return \Overbeck\Logistics\Supports\Collection
*/
public function only(array $keys)
Expand Down Expand Up @@ -119,6 +122,7 @@ public function has($key)
/**
* Run a filter over each of the items.
*
* @param callable|null $callback
* @return static
*/
public function filter(callable $callback = null)
Expand Down
15 changes: 14 additions & 1 deletion src/Traits/HasHttpRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ trait HasHttpRequest
/**
* Make a get request.
*
* @param string $endpoint
* @param array $query
* @param array $headers
* @return array
*/
protected function get(string $endpoint, array $query = [], array $headers = [])
Expand All @@ -37,6 +40,9 @@ protected function get(string $endpoint, array $query = [], array $headers = [])
/**
* Make a post request.
*
* @param string $endpoint
* @param array $params
* @param array $headers
* @return array
*/
protected function post(string $endpoint, array $params = [], array $headers = [])
Expand All @@ -50,6 +56,9 @@ protected function post(string $endpoint, array $params = [], array $headers = [
/**
* Make a post request with json params.
*
* @param string $endpoint
* @param array $params
* @param array $headers
* @return array
*/
protected function postJson(string $endpoint, array $params = [], array $headers = [])
Expand All @@ -63,7 +72,9 @@ protected function postJson(string $endpoint, array $params = [], array $headers
/**
* Make a http request.
*
* @param array $options http://docs.guzzlephp.org/en/latest/request-options.html
* @param string $method
* @param string $endpoint
* @param array $options http://docs.guzzlephp.org/en/latest/request-options.html
*
* @return array
*/
Expand Down Expand Up @@ -91,6 +102,7 @@ protected function getBaseOptions()
/**
* Return http client.
*
* @param array $options
* @return \GuzzleHttp\Client
*
* @codeCoverageIgnore
Expand All @@ -103,6 +115,7 @@ protected function getHttpClient(array $options = [])
/**
* Convert response contents to json.
*
* @param ResponseInterface $response
* @return ResponseInterface|array|string
*/
protected function unwrapResponse(ResponseInterface $response)
Expand Down

0 comments on commit c874cfc

Please sign in to comment.