Signature.php
1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Lackoxygen\GzCbec\Utils;
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use Psr\Http\Message\ResponseInterface;
class Signature
{
/**
* @var string
*/
protected $uri;
/**
* @var Client
*/
protected $client;
/**
* Signature constructor.
*
* @param string $uri
*/
public function __construct(string $uri)
{
$clientConfig = config('gz-cbec.client');
$this->uri = $uri;
$this->client = new Client($clientConfig);
}
/**
* @param string $signXml
*
* @return ResponseInterface
*/
protected function execute(string $signXml): ResponseInterface
{
return $this->client->post($this->uri, [
RequestOptions::FORM_PARAMS => [
'xml' => base64_encode($signXml)
]
]);
}
/**
* @param string $signXml
*
* @return string
*/
public function __invoke(string $signXml): string
{
$content = '';
try {
$response = $this->execute($signXml);
$content = $response->getBody()->getContents();
$array = \json_decode($content, true);
$data = \Arr::get($array, 'data');
if (!empty($data)) {
$content = html_entity_decode(base64_decode($data));
}
} catch (\Throwable $throwable) {
}
return $content;
}
}