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