1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Yansongda\Pay\Plugin\Jsb; |
||
6 | |||
7 | use Closure; |
||
8 | use GuzzleHttp\Psr7\Request; |
||
9 | use Yansongda\Artful\Contract\PluginInterface; |
||
10 | use Yansongda\Artful\Exception\ContainerException; |
||
11 | use Yansongda\Artful\Exception\ServiceNotFoundException; |
||
12 | use Yansongda\Artful\Logger; |
||
13 | use Yansongda\Artful\Rocket; |
||
14 | use Yansongda\Supports\Collection; |
||
15 | |||
16 | use function Yansongda\Pay\get_jsb_url; |
||
17 | use function Yansongda\Pay\get_provider_config; |
||
18 | |||
19 | class AddRadarPlugin implements PluginInterface |
||
20 | { |
||
21 | /** |
||
22 | * @throws ServiceNotFoundException |
||
23 | * @throws ContainerException |
||
24 | */ |
||
25 | public function assembly(Rocket $rocket, Closure $next): Rocket |
||
26 | { |
||
27 | Logger::info('[Jsb][AddRadarPlugin] 插件开始装载', ['rocket' => $rocket]); |
||
28 | |||
29 | $params = $rocket->getParams(); |
||
30 | $config = get_provider_config('jsb', $params); |
||
31 | $payload = $rocket->getPayload(); |
||
32 | |||
33 | $rocket->setRadar(new Request( |
||
34 | strtoupper($params['_method'] ?? 'POST'), |
||
35 | get_jsb_url($config, $payload), |
||
36 | $this->getHeaders(), |
||
37 | $this->getBody($payload), |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
38 | )); |
||
39 | |||
40 | Logger::info('[Jsb][AddRadarPlugin] 插件装载完毕', ['rocket' => $rocket]); |
||
41 | |||
42 | return $next($rocket); |
||
43 | } |
||
44 | |||
45 | protected function getHeaders(): array |
||
46 | { |
||
47 | return [ |
||
48 | 'Content-Type' => 'text/html', |
||
49 | 'User-Agent' => 'yansongda/pay-v3', |
||
50 | ]; |
||
51 | } |
||
52 | |||
53 | protected function getBody(Collection $payload): string |
||
54 | { |
||
55 | $sign = $payload->get('sign'); |
||
56 | $signType = $payload->get('signType'); |
||
57 | |||
58 | $payload->forget('sign'); |
||
59 | $payload->forget('signType'); |
||
60 | |||
61 | $payload = $payload->sortKeys(); |
||
62 | |||
63 | $payload->set('sign', $sign); |
||
64 | $payload->set('signType', $signType); |
||
65 | |||
66 | return $payload->toString(); |
||
67 | } |
||
68 | } |
||
69 |