|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yansongda\Pay\Plugin\Wechat\Pay\App; |
|
6
|
|
|
|
|
7
|
|
|
use Yansongda\Pay\Rocket; |
|
8
|
|
|
use Yansongda\Supports\Collection; |
|
9
|
|
|
use Yansongda\Supports\Config; |
|
10
|
|
|
use Yansongda\Supports\Str; |
|
11
|
|
|
|
|
12
|
|
|
class InvokePrepayPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\InvokePrepayPlugin |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @throws \Yansongda\Pay\Exception\ContainerException |
|
16
|
|
|
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException |
|
17
|
|
|
* @throws \Exception |
|
18
|
|
|
*/ |
|
19
|
|
|
protected function getInvokeConfig(Rocket $rocket, string $prepayId): Config |
|
20
|
|
|
{ |
|
21
|
|
|
$config = new Config([ |
|
22
|
|
|
'appid' => $this->getAppId($rocket), |
|
23
|
|
|
'partnerid' => get_wechat_config($rocket->getParams())->get('mch_id'), |
|
24
|
|
|
'prepayid' => $prepayId, |
|
25
|
|
|
'package' => 'Sign=WXPay', |
|
26
|
|
|
'noncestr' => Str::random(32), |
|
27
|
|
|
'timestamp' => time().'', |
|
28
|
|
|
]); |
|
29
|
|
|
|
|
30
|
|
|
$config->set('sign', $this->getSign($config, $rocket->getParams())); |
|
31
|
|
|
|
|
32
|
|
|
return $config; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @throws \Yansongda\Pay\Exception\ContainerException |
|
37
|
|
|
* @throws \Yansongda\Pay\Exception\InvalidConfigException |
|
38
|
|
|
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException |
|
39
|
|
|
*/ |
|
40
|
|
|
protected function getSign(Collection $invokeConfig, array $params): string |
|
41
|
|
|
{ |
|
42
|
|
|
$contents = $invokeConfig->get('appid', '')."\n". |
|
43
|
|
|
$invokeConfig->get('timestamp', '')."\n". |
|
44
|
|
|
$invokeConfig->get('noncestr', '')."\n". |
|
45
|
|
|
$invokeConfig->get('prepayid', '')."\n"; |
|
46
|
|
|
|
|
47
|
|
|
return get_wechat_sign($params, $contents); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
protected function getConfigKey(): string |
|
51
|
|
|
{ |
|
52
|
|
|
return 'app_id'; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|