1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yansongda\Pay\Plugin\Wechat\V3\Pay\Combine; |
6
|
|
|
|
7
|
|
|
use Closure; |
8
|
|
|
use Yansongda\Artful\Contract\PluginInterface; |
9
|
|
|
use Yansongda\Artful\Exception\ContainerException; |
10
|
|
|
use Yansongda\Artful\Exception\InvalidParamsException; |
11
|
|
|
use Yansongda\Artful\Exception\ServiceNotFoundException; |
12
|
|
|
use Yansongda\Artful\Logger; |
13
|
|
|
use Yansongda\Artful\Rocket; |
14
|
|
|
use Yansongda\Pay\Exception\Exception; |
15
|
|
|
|
16
|
|
|
use function Yansongda\Pay\get_provider_config; |
17
|
|
|
use function Yansongda\Pay\get_wechat_type_key; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @see https://pay.weixin.qq.com/docs/merchant/apis/combine-payment/orders/h5-prepay.html |
21
|
|
|
* @see https://pay.weixin.qq.com/docs/partner/apis/combine-payment/orders/h5-prepay.html |
22
|
|
|
*/ |
23
|
|
|
class H5PayPlugin implements PluginInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @throws ContainerException |
27
|
|
|
* @throws InvalidParamsException |
28
|
|
|
* @throws ServiceNotFoundException |
29
|
|
|
*/ |
30
|
|
|
public function assembly(Rocket $rocket, Closure $next): Rocket |
31
|
|
|
{ |
32
|
|
|
Logger::debug('[Wechat][Pay][Combine][H5PayPlugin] 插件开始装载', ['rocket' => $rocket]); |
33
|
|
|
|
34
|
|
|
$params = $rocket->getParams(); |
35
|
|
|
$config = get_provider_config('wechat', $params); |
36
|
|
|
$payload = $rocket->getPayload(); |
37
|
|
|
|
38
|
|
|
if (is_null($payload)) { |
39
|
|
|
throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: H5合单 下单,参数为空'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$rocket->mergePayload([ |
43
|
|
|
'_method' => 'POST', |
44
|
|
|
'_url' => 'v3/combine-transactions/h5', |
45
|
|
|
'_service_url' => 'v3/combine-transactions/h5', |
46
|
|
|
'notify_url' => $payload->get('notify_url', $config['notify_url'] ?? ''), |
47
|
|
|
'combine_appid' => $payload->get('combine_appid', $config[get_wechat_type_key($params)] ?? ''), |
48
|
|
|
'combine_mchid' => $payload->get('combine_mchid', $config['mch_id'] ?? ''), |
49
|
|
|
]); |
50
|
|
|
|
51
|
|
|
Logger::info('[Wechat][Pay][Combine][H5PayPlugin] 插件装载完毕', ['rocket' => $rocket]); |
52
|
|
|
|
53
|
|
|
return $next($rocket); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|