|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yansongda\Pay\Plugin\Wechat\Fund\Profitsharing; |
|
6
|
|
|
|
|
7
|
|
|
use Yansongda\Pay\Pay; |
|
8
|
|
|
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin; |
|
9
|
|
|
use Yansongda\Pay\Rocket; |
|
10
|
|
|
use Yansongda\Pay\Traits\HasWechatEncryption; |
|
11
|
|
|
use Yansongda\Supports\Collection; |
|
12
|
|
|
|
|
13
|
|
|
class AddReceiverPlugin extends GeneralPlugin |
|
14
|
|
|
{ |
|
15
|
|
|
use HasWechatEncryption; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @throws \Yansongda\Pay\Exception\ContainerDependencyException |
|
19
|
|
|
* @throws \Yansongda\Pay\Exception\ContainerException |
|
20
|
|
|
* @throws \Yansongda\Pay\Exception\InvalidConfigException |
|
21
|
|
|
* @throws \Yansongda\Pay\Exception\InvalidParamsException |
|
22
|
|
|
* @throws \Yansongda\Pay\Exception\InvalidResponseException |
|
23
|
|
|
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException |
|
24
|
|
|
*/ |
|
25
|
|
|
protected function doSomething(Rocket $rocket): void |
|
26
|
|
|
{ |
|
27
|
|
|
$params = $rocket->getParams(); |
|
28
|
|
|
$config = get_wechat_config($rocket->getParams()); |
|
29
|
|
|
$extra = $this->getWechatId($config, $rocket->getPayload()); |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
if (!empty($params['receivers'][0]['name'] ?? '')) { |
|
32
|
|
|
$params = $this->loadSerialNo($params); |
|
33
|
|
|
|
|
34
|
|
|
$rocket->setParams($params); |
|
35
|
|
|
|
|
36
|
|
|
$extra['receivers'] = $this->getEncryptUserName($params); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$rocket->mergePayload($extra); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function getUri(Rocket $rocket): string |
|
43
|
|
|
{ |
|
44
|
|
|
return 'v3/profitsharing/receivers/add'; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
protected function getWechatId(Collection $config, Collection $payload): array |
|
48
|
|
|
{ |
|
49
|
|
|
$wechatId = [ |
|
50
|
|
|
'appid' => $config->get('mp_app_id'), |
|
51
|
|
|
]; |
|
52
|
|
|
|
|
53
|
|
|
if (Pay::MODE_SERVICE == $config->get('mode')) { |
|
54
|
|
|
$wechatId['sub_mchid'] = $payload->get('sub_mchid', $config->get('sub_mch_id', '')); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return $wechatId; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @throws \Yansongda\Pay\Exception\ContainerDependencyException |
|
62
|
|
|
* @throws \Yansongda\Pay\Exception\ContainerException |
|
63
|
|
|
* @throws \Yansongda\Pay\Exception\InvalidParamsException |
|
64
|
|
|
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function getEncryptUserName(array $params): array |
|
67
|
|
|
{ |
|
68
|
|
|
$lists = $params['receivers'] ?? []; |
|
69
|
|
|
$publicKey = $this->getPublicKey($params, $params['_serial_no'] ?? ''); |
|
70
|
|
|
|
|
71
|
|
|
foreach ($lists as $key => $list) { |
|
72
|
|
|
$lists[$key]['name'] = encrypt_wechat_contents($list['name'], $publicKey); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $lists; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|