1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yansongda\Pay\Gateways\Wechat; |
4
|
|
|
|
5
|
|
|
use Yansongda\Pay\Events; |
6
|
|
|
use Yansongda\Pay\Exceptions\GatewayException; |
7
|
|
|
use Yansongda\Pay\Exceptions\InvalidArgumentException; |
8
|
|
|
use Yansongda\Pay\Exceptions\InvalidSignException; |
9
|
|
|
use Yansongda\Pay\Gateways\Wechat; |
10
|
|
|
use Yansongda\Supports\Collection; |
11
|
|
|
|
12
|
|
|
class GroupRedpackGateway extends Gateway |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Pay an order. |
16
|
|
|
* |
17
|
|
|
* @author yansongda <[email protected]> |
18
|
|
|
* |
19
|
|
|
* @param string $endpoint |
20
|
|
|
* |
21
|
|
|
* @throws GatewayException |
22
|
|
|
* @throws InvalidArgumentException |
23
|
|
|
* @throws InvalidSignException |
24
|
|
|
*/ |
25
|
|
|
public function pay($endpoint, array $payload): Collection |
26
|
|
|
{ |
27
|
|
|
$payload['wxappid'] = $payload['appid']; |
28
|
|
|
$payload['amt_type'] = 'ALL_RAND'; |
29
|
|
|
|
30
|
|
|
if (Wechat::MODE_SERVICE === $this->mode) { |
31
|
|
|
$payload['msgappid'] = $payload['appid']; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
unset($payload['appid'], $payload['trade_type'], |
35
|
|
|
$payload['notify_url'], $payload['spbill_create_ip']); |
36
|
|
|
|
37
|
|
|
$payload['sign'] = Support::generateSign($payload); |
38
|
|
|
|
39
|
|
|
Events::dispatch(new Events\PayStarted('Wechat', 'Group Redpack', $endpoint, $payload)); |
40
|
|
|
|
41
|
|
|
return Support::requestApi( |
42
|
|
|
'mmpaymkttransfers/sendgroupredpack', |
43
|
|
|
$payload, |
44
|
|
|
true |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Find. |
50
|
|
|
* |
51
|
|
|
* @author yansongda <[email protected]> |
52
|
|
|
* |
53
|
|
|
* @param $billno |
54
|
|
|
*/ |
55
|
|
View Code Duplication |
public function find($billno): array |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
return [ |
58
|
|
|
'endpoint' => 'mmpaymkttransfers/gethbinfo', |
59
|
|
|
'order' => ['mch_billno' => $billno, 'bill_type' => 'MCHT'], |
60
|
|
|
'cert' => true, |
61
|
|
|
]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get trade type config. |
66
|
|
|
* |
67
|
|
|
* @author yansongda <[email protected]> |
68
|
|
|
*/ |
69
|
|
|
protected function getTradeType(): string |
70
|
|
|
{ |
71
|
|
|
return ''; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.