GeneralV2Plugin.php
1.1 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
<?php
declare(strict_types=1);
namespace Yansongda\Pay\Plugin\Wechat;
use Yansongda\Pay\Exception\ContainerException;
use Yansongda\Pay\Exception\ServiceNotFoundException;
use Yansongda\Pay\Packer\XmlPacker;
use Yansongda\Pay\Rocket;
use function Yansongda\Pay\get_wechat_config;
abstract class GeneralV2Plugin extends GeneralPlugin
{
protected function getHeaders(): array
{
return [
'Content-Type' => 'application/xml',
'User-Agent' => 'yansongda/pay-v3',
];
}
/**
* @throws ContainerException
* @throws ServiceNotFoundException
*/
protected function doSomething(Rocket $rocket): void
{
$config = get_wechat_config($rocket->getParams());
$configKey = $this->getConfigKey($rocket->getParams());
$rocket->setPacker(XmlPacker::class)->mergeParams(['_version' => 'v2']);
$rocket->mergePayload([
'appid' => $config[$configKey] ?? '',
'mch_id' => $config['mch_id'] ?? '',
]);
}
abstract protected function getUri(Rocket $rocket): string;
}