Skip to content

Commit

Permalink
将guzzle库升级至7.0以上 (#10)
Browse files Browse the repository at this point in the history
* 将guzzle库升级至7.0以上
添加crawler.php至composer可执行脚本
在crawler.php添加OUTPUT_DIR可自定义输出目录

* a

* a
  • Loading branch information
qq958691165 authored May 6, 2022
1 parent 34d753b commit 2517bf2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "library",
"require": {
"php": "^7.1|^8.0",
"guzzlehttp/guzzle": "^6.0",
"guzzlehttp/guzzle": "^7.0",
"spatie/array-to-xml": "^2.7"
},
"license": "MIT",
Expand All @@ -21,5 +21,8 @@
},
"require-dev": {
"phpunit/phpunit": "^9.0"
}
},
"bin": [
"scripts/crawler.php"
]
}
10 changes: 8 additions & 2 deletions scripts/crawler.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
use GuzzleHttp\Exception\BadResponseException;
use ChinaDivisions\Exceptions\ResponseException;

require __DIR__ . '/../vendor/autoload.php';
if ($GLOBALS['_composer_autoload_path']){
require $GLOBALS['_composer_autoload_path'];
}else {
require __DIR__ . '/../vendor/autoload.php';
}

define('MAX_LEVEL', getenv('MAX_LEVEL') ?: 4); // 1.国家 -> 2.省 -> 3.市 -> 4.区县 -> 5.街道乡镇
define('CHILDREN_KEY', getenv('CHILDREN_KEY') ?: 'children'); // 子节点键名
define('OUTPUT_DIR', getenv('OUTPUT_DIR') ?: __DIR__.'/output');

const DIVISION_FILTER = 'division_filter';

function division_filter(array $data): ?array
Expand Down Expand Up @@ -69,6 +75,6 @@ function division_filter(array $data): ?array
}

file_put_contents(
sprintf('%s/output/level%s.json', __DIR__, MAX_LEVEL),
sprintf('%s/level%s.json', OUTPUT_DIR, MAX_LEVEL),
json_encode($collection, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
);
3 changes: 1 addition & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\BadResponseException;
use function GuzzleHttp\Psr7\build_query;
use GuzzleHttp\Psr7\Request;
use Psr\Http\Message\RequestInterface;
use Spatie\ArrayToXml\ArrayToXml;
Expand Down Expand Up @@ -53,7 +52,7 @@ public function build($msgType, $logisticProviderId, $logisticsInterface, $salt)

$dataDigest = $this->signer->make($logisticsInterface, $salt);

$body = build_query([
$body = http_build_query([
'msg_type' => $msgType,
'logistic_provider_id' => $logisticProviderId,
'logistics_interface' => $logisticsInterface,
Expand Down

0 comments on commit 2517bf2

Please sign in to comment.