|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Application.php |
|
4
|
|
|
* |
|
5
|
|
|
* Created by PhpStorm. |
|
6
|
|
|
* |
|
7
|
|
|
* author: liuml <[email protected]> |
|
8
|
|
|
* DateTime: 2019-04-04 16:31 |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace WannanBigPig\Alipay\Payment; |
|
12
|
|
|
|
|
13
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
14
|
|
|
use WannanBigPig\Alipay\Kernel\Support\Support; |
|
15
|
|
|
use WannanBigPig\Alipay\Payment\Trade\Fund; |
|
16
|
|
|
use WannanBigPig\Alipay\Payment\Trade\Query; |
|
17
|
|
|
use WannanBigPig\Supports\AccessData; |
|
18
|
|
|
use WannanBigPig\Supports\Exceptions; |
|
19
|
|
|
use WannanBigPig\Supports\Str; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class Application. |
|
23
|
|
|
* |
|
24
|
|
|
* @method Response app(array $payload) app支付 |
|
25
|
|
|
* @method AccessData create(array $payload) 统一收单交易创建接口 小程序支付 |
|
26
|
|
|
* @method AccessData pay(array $payload) pos支付 (统一收单交易支付接口) 商户主扫 |
|
27
|
|
|
* @method AccessData precreate(array $payload) 订单预创建 |
|
28
|
|
|
* @method AccessData faceInit(array $payload) 扫脸支付 扫脸初始化 |
|
29
|
|
|
* @method Response wap(array $payload) 手机站支付 |
|
30
|
|
|
* @method Response pagePay(array $payload) pc支付 |
|
31
|
|
|
* @method AccessData refund($params) 退款 |
|
32
|
|
|
* @method AccessData cancel($params) 取消订单 |
|
33
|
|
|
* @method AccessData close($params) 关闭订单 |
|
34
|
|
|
* @method AccessData download($params) 下载对账单 |
|
35
|
|
|
* @method AccessData settle($params) 结算 |
|
36
|
|
|
* @method AccessData orderInfoSync($params) 订单信息同步 |
|
37
|
|
|
* @method Query query() 查询类 |
|
38
|
|
|
* @method Fund fund() 资金类 |
|
39
|
|
|
* |
|
40
|
|
|
* @property Fund fund 资金类 |
|
41
|
|
|
* @property Query query 查询类 |
|
42
|
|
|
*/ |
|
43
|
|
|
class Application |
|
44
|
|
|
{ |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Application constructor. |
|
48
|
|
|
*/ |
|
49
|
2 |
|
public function __construct() |
|
50
|
|
|
{ |
|
51
|
2 |
|
Support::$config->set('event.driver', 'Payment'); |
|
52
|
2 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* __get |
|
56
|
|
|
* |
|
57
|
|
|
* @param $name |
|
58
|
|
|
* |
|
59
|
|
|
* @return mixed |
|
60
|
|
|
* |
|
61
|
|
|
* @throws \WannanBigPig\Supports\Exceptions\ApplicationException |
|
62
|
|
|
* |
|
63
|
|
|
* @author liuml <[email protected]> |
|
64
|
|
|
* @DateTime 2019-04-28 12:10 |
|
65
|
|
|
*/ |
|
66
|
2 |
|
public function __get($name) |
|
67
|
|
|
{ |
|
68
|
2 |
|
return $this->getVariable($name); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* __set |
|
73
|
|
|
* |
|
74
|
|
|
* @param $name |
|
75
|
|
|
* @param $value |
|
76
|
|
|
* |
|
77
|
|
|
* @author liuml <[email protected]> |
|
78
|
|
|
* @DateTime 2019-04-28 12:10 |
|
79
|
|
|
*/ |
|
80
|
|
|
public function __set($name, $value) |
|
81
|
|
|
{ |
|
82
|
|
|
Support::$config->set($name, $value); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* getVariable |
|
87
|
|
|
* |
|
88
|
|
|
* @param $name |
|
89
|
|
|
* |
|
90
|
|
|
* @return mixed |
|
91
|
|
|
* |
|
92
|
|
|
* @throws \WannanBigPig\Supports\Exceptions\ApplicationException |
|
93
|
|
|
* |
|
94
|
|
|
* @author liuml <[email protected]> |
|
95
|
|
|
* @DateTime 2019-04-28 12:10 |
|
96
|
|
|
*/ |
|
97
|
2 |
|
public function getVariable($name) |
|
98
|
|
|
{ |
|
99
|
2 |
|
$method = Str::studly($name); |
|
100
|
|
|
// 组装命名空间 |
|
101
|
2 |
|
$gateway = __NAMESPACE__ . '\\Trade\\' . $method; |
|
102
|
|
|
|
|
103
|
2 |
|
if (class_exists($gateway)) { |
|
104
|
2 |
|
Support::$config->set('event.method', $name); |
|
105
|
2 |
|
return $this->make($gateway); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
throw new Exceptions\ApplicationException("The {$method} member variable doesn't exist"); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* get |
|
113
|
|
|
* |
|
114
|
|
|
* @param $name |
|
115
|
|
|
* |
|
116
|
|
|
* @return array|mixed|null |
|
117
|
|
|
* |
|
118
|
|
|
* @author liuml <[email protected]> |
|
119
|
|
|
* @DateTime 2019-04-28 12:10 |
|
120
|
|
|
*/ |
|
121
|
|
|
public function get($name) |
|
122
|
|
|
{ |
|
123
|
|
|
return Support::$config->get($name, ''); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* set |
|
128
|
|
|
* |
|
129
|
|
|
* @param $name |
|
130
|
|
|
* @param $value |
|
131
|
|
|
* |
|
132
|
|
|
* @author liuml <[email protected]> |
|
133
|
|
|
* @DateTime 2019-04-28 12:09 |
|
134
|
|
|
*/ |
|
135
|
|
|
public function set($name, $value) |
|
136
|
|
|
{ |
|
137
|
|
|
Support::$config->set($name, $value); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* __call |
|
142
|
|
|
* |
|
143
|
|
|
* @param $name |
|
144
|
|
|
* @param $arguments |
|
145
|
|
|
* |
|
146
|
|
|
* @return mixed |
|
147
|
|
|
* |
|
148
|
|
|
* @throws \WannanBigPig\Supports\Exceptions\ApplicationException |
|
149
|
|
|
* |
|
150
|
|
|
* @author liuml <[email protected]> |
|
151
|
|
|
* @DateTime 2019-04-28 12:09 |
|
152
|
|
|
*/ |
|
153
|
15 |
|
public function __call($name, $arguments) |
|
154
|
|
|
{ |
|
155
|
15 |
|
return $this->alipayMethod($name, ...$arguments); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* alipayMethod |
|
160
|
|
|
* |
|
161
|
|
|
* @param $method |
|
162
|
|
|
* @param array $params |
|
163
|
|
|
* |
|
164
|
|
|
* @return mixed |
|
165
|
|
|
* |
|
166
|
|
|
* @throws \WannanBigPig\Supports\Exceptions\ApplicationException |
|
167
|
|
|
* |
|
168
|
|
|
* @author liuml <[email protected]> |
|
169
|
|
|
* @DateTime 2019-04-28 12:09 |
|
170
|
|
|
*/ |
|
171
|
15 |
|
public function alipayMethod($method, $params = []) |
|
172
|
|
|
{ |
|
173
|
15 |
|
$method = Str::studly($method); |
|
174
|
|
|
// 组装命名空间 |
|
175
|
15 |
|
$gateway = __NAMESPACE__ . '\\Trade\\' . $method; |
|
176
|
|
|
|
|
177
|
15 |
|
if (class_exists($gateway)) { |
|
178
|
13 |
|
Support::$config->set('event.method', $method); |
|
179
|
13 |
|
return $this->make($gateway, $params); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
2 |
|
throw new Exceptions\ApplicationException("The {$method} method doesn't exist"); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* make |
|
187
|
|
|
* |
|
188
|
|
|
* @param string $gateway |
|
189
|
|
|
* @param array $params |
|
190
|
|
|
* |
|
191
|
|
|
* @return mixed |
|
192
|
|
|
* |
|
193
|
|
|
* @author liuml <[email protected]> |
|
194
|
|
|
* @DateTime 2019-04-28 12:09 |
|
195
|
|
|
*/ |
|
196
|
15 |
|
public function make(string $gateway, $params = []) |
|
197
|
|
|
{ |
|
198
|
15 |
|
$app = new $gateway(); |
|
199
|
|
|
|
|
200
|
15 |
|
if ($app instanceof DoctorInterface) { |
|
201
|
13 |
|
return $app->exec($params); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
2 |
|
return $app; |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* verify |
|
209
|
|
|
* |
|
210
|
|
|
* @param array|null $data |
|
211
|
|
|
* |
|
212
|
|
|
* @return bool |
|
213
|
|
|
* |
|
214
|
|
|
* @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException |
|
215
|
|
|
* |
|
216
|
|
|
* @author liuml <[email protected]> |
|
217
|
|
|
* @DateTime 2019-04-28 12:09 |
|
218
|
|
|
*/ |
|
219
|
1 |
|
public function verify($data = null) |
|
220
|
|
|
{ |
|
221
|
1 |
|
return Support::notifyVerify($data); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* execute |
|
226
|
|
|
* |
|
227
|
|
|
* @param $method |
|
228
|
|
|
* @param $params |
|
229
|
|
|
* |
|
230
|
|
|
* @return \WannanBigPig\Supports\AccessData |
|
231
|
|
|
* |
|
232
|
|
|
* @throws \WannanBigPig\Alipay\Kernel\Exceptions\SignException |
|
233
|
|
|
* @throws \WannanBigPig\Supports\Exceptions\BusinessException |
|
234
|
|
|
* @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException |
|
235
|
|
|
* |
|
236
|
|
|
* @author liuml <[email protected]> |
|
237
|
|
|
* @DateTime 2019-04-28 12:08 |
|
238
|
|
|
*/ |
|
239
|
1 |
|
public function execute($method, $params) |
|
240
|
|
|
{ |
|
241
|
1 |
|
return Support::executeApi($params, $method); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* sdkExecute |
|
246
|
|
|
* |
|
247
|
|
|
* @param $method |
|
248
|
|
|
* @param $params |
|
249
|
|
|
* |
|
250
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
251
|
|
|
* |
|
252
|
|
|
* @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException |
|
253
|
|
|
* |
|
254
|
|
|
* @author liuml <[email protected]> |
|
255
|
|
|
* @DateTime 2019-04-28 12:08 |
|
256
|
|
|
*/ |
|
257
|
|
|
public function sdkExecute($method, $params) |
|
258
|
|
|
{ |
|
259
|
|
|
return Support::executeSdk($params, $method); |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* pegeExecute |
|
264
|
|
|
* |
|
265
|
|
|
* @param $method |
|
266
|
|
|
* @param $params |
|
267
|
|
|
* |
|
268
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
269
|
|
|
* |
|
270
|
|
|
* @throws \WannanBigPig\Supports\Exceptions\InvalidArgumentException |
|
271
|
|
|
* |
|
272
|
|
|
* @author liuml <[email protected]> |
|
273
|
|
|
* @DateTime 2019-04-28 12:09 |
|
274
|
|
|
*/ |
|
275
|
|
|
public function pegeExecute($method, $params) |
|
276
|
|
|
{ |
|
277
|
|
|
return Support::executePage($params, $method); |
|
278
|
|
|
} |
|
279
|
|
|
} |
|
280
|
|
|
|