1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yansongda\Pay\Plugin\Wechat\V3\Extend\ProfitSharing; |
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
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @see https://pay.weixin.qq.com/docs/merchant/apis/profit-sharing/orders/query-order.html |
20
|
|
|
* @see https://pay.weixin.qq.com/docs/partner/apis/profit-sharing/orders/query-order.html |
21
|
|
|
*/ |
22
|
|
|
class QueryPlugin implements PluginInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @throws ContainerException |
26
|
|
|
* @throws InvalidParamsException |
27
|
|
|
* @throws ServiceNotFoundException |
28
|
|
|
*/ |
29
|
|
|
public function assembly(Rocket $rocket, Closure $next): Rocket |
30
|
|
|
{ |
31
|
|
|
Logger::debug('[Wechat][Extend][ProfitSharing][QueryPlugin] 插件开始装载', ['rocket' => $rocket]); |
32
|
|
|
|
33
|
|
|
$config = get_provider_config('wechat', $rocket->getParams()); |
34
|
|
|
$payload = $rocket->getPayload(); |
35
|
|
|
$outOrderNo = $payload?->get('out_order_no') ?? null; |
36
|
|
|
$transactionId = $payload?->get('transaction_id') ?? null; |
37
|
|
|
$subMchId = $payload?->get('sub_mchid') ?? $config['sub_mch_id'] ?? 'null'; |
38
|
|
|
|
39
|
|
|
if (empty($outOrderNo) || empty($transactionId)) { |
40
|
|
|
throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 查询分账结果, 缺少必要参数 `out_order_no`, `transaction_id`'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$rocket->setPayload([ |
44
|
|
|
'_method' => 'GET', |
45
|
|
|
'_url' => 'v3/profitsharing/orders/'.$outOrderNo.'?transaction_id='.$transactionId, |
46
|
|
|
'_service_url' => 'v3/profitsharing/orders/'.$outOrderNo.'?sub_mchid='.$subMchId.'&transaction_id='.$transactionId, |
47
|
|
|
]); |
48
|
|
|
|
49
|
|
|
Logger::info('[Wechat][Extend][ProfitSharing][QueryPlugin] 插件装载完毕', ['rocket' => $rocket]); |
50
|
|
|
|
51
|
|
|
return $next($rocket); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|