1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yansongda\Pay\Shortcut\Wechat; |
6
|
|
|
|
7
|
|
|
use Yansongda\Artful\Contract\ShortcutInterface; |
8
|
|
|
use Yansongda\Artful\Exception\InvalidParamsException; |
9
|
|
|
use Yansongda\Artful\Plugin\AddPayloadBodyPlugin; |
10
|
|
|
use Yansongda\Artful\Plugin\ParserPlugin; |
11
|
|
|
use Yansongda\Artful\Plugin\StartPlugin; |
12
|
|
|
use Yansongda\Pay\Exception\Exception; |
13
|
|
|
use Yansongda\Pay\Plugin\Wechat\AddRadarPlugin; |
14
|
|
|
use Yansongda\Pay\Plugin\Wechat\ResponsePlugin; |
15
|
|
|
use Yansongda\Pay\Plugin\Wechat\V3\AddPayloadSignaturePlugin; |
16
|
|
|
use Yansongda\Pay\Plugin\Wechat\V3\Marketing\MchTransfer\QueryPlugin as MchTransferQueryPlugin; |
17
|
|
|
use Yansongda\Pay\Plugin\Wechat\V3\Marketing\Transfer\Detail\QueryPlugin as TransferQueryPlugin; |
18
|
|
|
use Yansongda\Pay\Plugin\Wechat\V3\Pay\App\QueryPlugin as AppQueryPlugin; |
19
|
|
|
use Yansongda\Pay\Plugin\Wechat\V3\Pay\App\QueryRefundPlugin as AppQueryRefundPlugin; |
20
|
|
|
use Yansongda\Pay\Plugin\Wechat\V3\Pay\Combine\QueryPlugin as CombineQueryPlugin; |
21
|
|
|
use Yansongda\Pay\Plugin\Wechat\V3\Pay\Combine\QueryRefundPlugin as CombineQueryRefundPlugin; |
22
|
|
|
use Yansongda\Pay\Plugin\Wechat\V3\Pay\H5\QueryPlugin as H5QueryPlugin; |
23
|
|
|
use Yansongda\Pay\Plugin\Wechat\V3\Pay\H5\QueryRefundPlugin as H5QueryRefundPlugin; |
24
|
|
|
use Yansongda\Pay\Plugin\Wechat\V3\Pay\Jsapi\QueryPlugin as JsapiQueryPlugin; |
25
|
|
|
use Yansongda\Pay\Plugin\Wechat\V3\Pay\Jsapi\QueryRefundPlugin as JsapiQueryRefundPlugin; |
26
|
|
|
use Yansongda\Pay\Plugin\Wechat\V3\Pay\Mini\QueryPlugin as MiniQueryPlugin; |
27
|
|
|
use Yansongda\Pay\Plugin\Wechat\V3\Pay\Mini\QueryRefundPlugin as MiniQueryRefundPlugin; |
28
|
|
|
use Yansongda\Pay\Plugin\Wechat\V3\Pay\Native\QueryPlugin as NativeQueryPlugin; |
29
|
|
|
use Yansongda\Pay\Plugin\Wechat\V3\Pay\Native\QueryRefundPlugin as NativeQueryRefundPlugin; |
30
|
|
|
use Yansongda\Pay\Plugin\Wechat\V3\VerifySignaturePlugin; |
31
|
|
|
use Yansongda\Supports\Str; |
32
|
|
|
|
33
|
|
|
class QueryShortcut implements ShortcutInterface |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @throws InvalidParamsException |
37
|
|
|
*/ |
38
|
|
|
public function getPlugins(array $params): array |
39
|
|
|
{ |
40
|
|
|
if (isset($params['combine_out_trade_no'])) { |
41
|
|
|
return $this->combinePlugins(); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$method = Str::camel($params['_action'] ?? 'default').'Plugins'; |
45
|
|
|
|
46
|
|
|
if (method_exists($this, $method)) { |
47
|
|
|
return $this->{$method}(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
throw new InvalidParamsException(Exception::PARAMS_SHORTCUT_ACTION_INVALID, "您所提供的 action 方法 [{$method}] 不支持,请参考文档或源码确认"); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function defaultPlugins(): array |
54
|
|
|
{ |
55
|
|
|
return $this->jsapiPlugins(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function appPlugins(): array |
59
|
|
|
{ |
60
|
|
|
return [ |
61
|
|
|
StartPlugin::class, |
62
|
|
|
AppQueryPlugin::class, |
63
|
|
|
AddPayloadBodyPlugin::class, |
64
|
|
|
AddPayloadSignaturePlugin::class, |
65
|
|
|
AddRadarPlugin::class, |
66
|
|
|
VerifySignaturePlugin::class, |
67
|
|
|
ResponsePlugin::class, |
68
|
|
|
ParserPlugin::class, |
69
|
|
|
]; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
protected function combinePlugins(): array |
73
|
|
|
{ |
74
|
|
|
return [ |
75
|
|
|
StartPlugin::class, |
76
|
|
|
CombineQueryPlugin::class, |
77
|
|
|
AddPayloadBodyPlugin::class, |
78
|
|
|
AddPayloadSignaturePlugin::class, |
79
|
|
|
AddRadarPlugin::class, |
80
|
|
|
VerifySignaturePlugin::class, |
81
|
|
|
ResponsePlugin::class, |
82
|
|
|
ParserPlugin::class, |
83
|
|
|
]; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
protected function h5Plugins(): array |
87
|
|
|
{ |
88
|
|
|
return [ |
89
|
|
|
StartPlugin::class, |
90
|
|
|
H5QueryPlugin::class, |
91
|
|
|
AddPayloadBodyPlugin::class, |
92
|
|
|
AddPayloadSignaturePlugin::class, |
93
|
|
|
AddRadarPlugin::class, |
94
|
|
|
VerifySignaturePlugin::class, |
95
|
|
|
ResponsePlugin::class, |
96
|
|
|
ParserPlugin::class, |
97
|
|
|
]; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
protected function jsapiPlugins(): array |
101
|
|
|
{ |
102
|
|
|
return [ |
103
|
|
|
StartPlugin::class, |
104
|
|
|
JsapiQueryPlugin::class, |
105
|
|
|
AddPayloadBodyPlugin::class, |
106
|
|
|
AddPayloadSignaturePlugin::class, |
107
|
|
|
AddRadarPlugin::class, |
108
|
|
|
VerifySignaturePlugin::class, |
109
|
|
|
ResponsePlugin::class, |
110
|
|
|
ParserPlugin::class, |
111
|
|
|
]; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
protected function miniPlugins(): array |
115
|
|
|
{ |
116
|
|
|
return [ |
117
|
|
|
StartPlugin::class, |
118
|
|
|
MiniQueryPlugin::class, |
119
|
|
|
AddPayloadBodyPlugin::class, |
120
|
|
|
AddPayloadSignaturePlugin::class, |
121
|
|
|
AddRadarPlugin::class, |
122
|
|
|
VerifySignaturePlugin::class, |
123
|
|
|
ResponsePlugin::class, |
124
|
|
|
ParserPlugin::class, |
125
|
|
|
]; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
protected function nativePlugins(): array |
129
|
|
|
{ |
130
|
|
|
return [ |
131
|
|
|
StartPlugin::class, |
132
|
|
|
NativeQueryPlugin::class, |
133
|
|
|
AddPayloadBodyPlugin::class, |
134
|
|
|
AddPayloadSignaturePlugin::class, |
135
|
|
|
AddRadarPlugin::class, |
136
|
|
|
VerifySignaturePlugin::class, |
137
|
|
|
ResponsePlugin::class, |
138
|
|
|
ParserPlugin::class, |
139
|
|
|
]; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
protected function mchTransferPlugins(): array |
143
|
|
|
{ |
144
|
|
|
return [ |
145
|
|
|
StartPlugin::class, |
146
|
|
|
MchTransferQueryPlugin::class, |
147
|
|
|
AddPayloadBodyPlugin::class, |
148
|
|
|
AddPayloadSignaturePlugin::class, |
149
|
|
|
AddRadarPlugin::class, |
150
|
|
|
VerifySignaturePlugin::class, |
151
|
|
|
ResponsePlugin::class, |
152
|
|
|
ParserPlugin::class, |
153
|
|
|
]; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
protected function refundPlugins(): array |
157
|
|
|
{ |
158
|
|
|
return $this->refundJsapiPlugins(); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
protected function refundAppPlugins(): array |
162
|
|
|
{ |
163
|
|
|
return [ |
164
|
|
|
StartPlugin::class, |
165
|
|
|
AppQueryRefundPlugin::class, |
166
|
|
|
AddPayloadBodyPlugin::class, |
167
|
|
|
AddPayloadSignaturePlugin::class, |
168
|
|
|
AddRadarPlugin::class, |
169
|
|
|
VerifySignaturePlugin::class, |
170
|
|
|
ResponsePlugin::class, |
171
|
|
|
ParserPlugin::class, |
172
|
|
|
]; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
protected function refundCombinePlugins(): array |
176
|
|
|
{ |
177
|
|
|
return [ |
178
|
|
|
StartPlugin::class, |
179
|
|
|
CombineQueryRefundPlugin::class, |
180
|
|
|
AddPayloadBodyPlugin::class, |
181
|
|
|
AddPayloadSignaturePlugin::class, |
182
|
|
|
AddRadarPlugin::class, |
183
|
|
|
VerifySignaturePlugin::class, |
184
|
|
|
ResponsePlugin::class, |
185
|
|
|
ParserPlugin::class, |
186
|
|
|
]; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
protected function refundH5Plugins(): array |
190
|
|
|
{ |
191
|
|
|
return [ |
192
|
|
|
StartPlugin::class, |
193
|
|
|
H5QueryRefundPlugin::class, |
194
|
|
|
AddPayloadBodyPlugin::class, |
195
|
|
|
AddPayloadSignaturePlugin::class, |
196
|
|
|
AddRadarPlugin::class, |
197
|
|
|
VerifySignaturePlugin::class, |
198
|
|
|
ResponsePlugin::class, |
199
|
|
|
ParserPlugin::class, |
200
|
|
|
]; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
protected function refundJsapiPlugins(): array |
204
|
|
|
{ |
205
|
|
|
return [ |
206
|
|
|
StartPlugin::class, |
207
|
|
|
JsapiQueryRefundPlugin::class, |
208
|
|
|
AddPayloadBodyPlugin::class, |
209
|
|
|
AddPayloadSignaturePlugin::class, |
210
|
|
|
AddRadarPlugin::class, |
211
|
|
|
VerifySignaturePlugin::class, |
212
|
|
|
ResponsePlugin::class, |
213
|
|
|
ParserPlugin::class, |
214
|
|
|
]; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
protected function refundMiniPlugins(): array |
218
|
|
|
{ |
219
|
|
|
return [ |
220
|
|
|
StartPlugin::class, |
221
|
|
|
MiniQueryRefundPlugin::class, |
222
|
|
|
AddPayloadBodyPlugin::class, |
223
|
|
|
AddPayloadSignaturePlugin::class, |
224
|
|
|
AddRadarPlugin::class, |
225
|
|
|
VerifySignaturePlugin::class, |
226
|
|
|
ResponsePlugin::class, |
227
|
|
|
ParserPlugin::class, |
228
|
|
|
]; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
protected function refundNativePlugins(): array |
232
|
|
|
{ |
233
|
|
|
return [ |
234
|
|
|
StartPlugin::class, |
235
|
|
|
NativeQueryRefundPlugin::class, |
236
|
|
|
AddPayloadBodyPlugin::class, |
237
|
|
|
AddPayloadSignaturePlugin::class, |
238
|
|
|
AddRadarPlugin::class, |
239
|
|
|
VerifySignaturePlugin::class, |
240
|
|
|
ResponsePlugin::class, |
241
|
|
|
ParserPlugin::class, |
242
|
|
|
]; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
protected function transferPlugins(): array |
246
|
|
|
{ |
247
|
|
|
return [ |
248
|
|
|
StartPlugin::class, |
249
|
|
|
TransferQueryPlugin::class, |
250
|
|
|
AddPayloadBodyPlugin::class, |
251
|
|
|
AddPayloadSignaturePlugin::class, |
252
|
|
|
AddRadarPlugin::class, |
253
|
|
|
VerifySignaturePlugin::class, |
254
|
|
|
ResponsePlugin::class, |
255
|
|
|
ParserPlugin::class, |
256
|
|
|
]; |
257
|
|
|
} |
258
|
|
|
} |
259
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: