作者 竞泽

alter:优化

<?php
return [
'base_uri' => 'https://open.singlewindow.gz.cn',
'record_sn' => '',
'secret_key' => '',
'company_cert_sn' => '',
'sender_sn' => '',
'receiver_sn' => '',
'client' => [
'timeout' => 30
]
'base_uri' => '',
'timeout' => 30,
'verify' => false
],
'signature' => ''
];
... ...
... ... @@ -29,27 +29,18 @@ class Client implements ClientInterface
*/
protected $config = [];
protected function __construct(RequestInterface $request)
{
$this->guzzleHttp = new GuzzleHttp([
'base_uri' => Arr::get($this->config, 'base_uri'),
'verify' => false
]);
$this->request = $request;
$this->config = config('gz-cbec');
}
/**
* @param RequestInterface $request
* Client constructor.
*
* @return ClientInterface
* @param RequestInterface $request
*/
protected static function make(RequestInterface $request): ClientInterface
protected function __construct(RequestInterface $request)
{
return new static($request);
$this->request = $request;
$this->config = config('gz-cbec');
$this->guzzleHttp = new GuzzleHttp((array)Arr::get($this->config, 'client'));
}
/**
* @return ResponseInterface
* @throws Exception
... ... @@ -77,13 +68,12 @@ class Client implements ClientInterface
* @param RequestInterface $request
*
* @return array
* @throws Exception
*/
public static function request(RequestInterface $request): array
{
$client = self::make($request);
/**
* @var ResponseInterface $response
*/
$client = new static($request);
$response = $client->send();
$content = $response->getBody()->getContents();
... ...
... ... @@ -4,7 +4,6 @@ namespace Lackoxygen\GzCbec\Request;
use Carbon\Carbon;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Lackoxygen\GzCbec\Constant\XML;
use Lackoxygen\GzCbec\Contract\RequestInterface;
use Lackoxygen\GzCbec\Contract\XMLInterface;
... ... @@ -12,7 +11,6 @@ use Lackoxygen\GzCbec\Exception\Exception;
use Lackoxygen\GzCbec\Request\Head\Head;
use Lackoxygen\GzCbec\Request\Packet\GzReportTransfer;
use Lackoxygen\GzCbec\Request\Report\Node\Receiver;
use Lackoxygen\GzCbec\Utils\RSA;
use Lackoxygen\GzCbec\Utils\Signature;
class Packet
... ... @@ -46,7 +44,7 @@ class Packet
public function getContent(): string
{
try {
$head = new Head();
$head = new Head;
$head->setMessageId($this->request->getGuid());
$head->setMessageType($this->request->getMessageType());
$head->setSender($this->config['sender_sn']);
... ... @@ -64,7 +62,7 @@ class Packet
$xmlHead = sprintf(XML::DATA, $firstLabel, $this->request->getGuid(), $this->request->getVersion(),
$firstLabel);
$dataXml = $this->request->toXML($xmlHead);
$data = base64_encode($dataXml);
$data = base64_encode($dataXml);
$packet->setData($data);
}
$xml = $packet->toXML(XML::TRANSFER);
... ...