1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the overtrue/wechat. |
5
|
|
|
* |
6
|
|
|
* (c) overtrue <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace EasyWeChat\Payment; |
13
|
|
|
|
14
|
|
|
use EasyWeChat\BasicService; |
15
|
|
|
use EasyWeChat\Kernel\ServiceContainer; |
16
|
|
|
use EasyWeChat\Kernel\Support; |
17
|
|
|
use EasyWeChat\OfficialAccount; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class Application. |
21
|
|
|
* |
22
|
|
|
* @property \EasyWeChat\Payment\Bill\Client $bill |
23
|
|
|
* @property \EasyWeChat\Payment\Jssdk\Client $jssdk |
24
|
|
|
* @property \EasyWeChat\Payment\Order\Client $order |
25
|
|
|
* @property \EasyWeChat\Payment\Refund\Client $refund |
26
|
|
|
* @property \EasyWeChat\Payment\Coupon\Client $coupon |
27
|
|
|
* @property \EasyWeChat\Payment\Reverse\Client $reverse |
28
|
|
|
* @property \EasyWeChat\Payment\Redpack\Client $redpack |
29
|
|
|
* @property \EasyWeChat\BasicService\Url\Client $url |
30
|
|
|
* @property \EasyWeChat\Payment\Transfer\Client $transfer |
31
|
|
|
* @property \EasyWeChat\OfficialAccount\Auth\AccessToken $access_token |
32
|
|
|
* |
33
|
|
|
* @method mixed pay(array $attributes) |
34
|
|
|
* @method mixed authCodeToOpenId(string $authCode) |
35
|
|
|
*/ |
36
|
|
|
class Application extends ServiceContainer |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* @var array |
40
|
|
|
*/ |
41
|
|
|
protected $providers = [ |
42
|
|
|
OfficialAccount\Auth\ServiceProvider::class, |
43
|
|
|
BasicService\Url\ServiceProvider::class, |
44
|
|
|
Base\ServiceProvider::class, |
45
|
|
|
Bill\ServiceProvider::class, |
46
|
|
|
Coupon\ServiceProvider::class, |
47
|
|
|
Jssdk\ServiceProvider::class, |
48
|
|
|
Order\ServiceProvider::class, |
49
|
|
|
Redpack\ServiceProvider::class, |
50
|
|
|
Refund\ServiceProvider::class, |
51
|
|
|
Reverse\ServiceProvider::class, |
52
|
|
|
Sandbox\ServiceProvider::class, |
53
|
|
|
Transfer\ServiceProvider::class, |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var array |
58
|
|
|
*/ |
59
|
|
|
protected $defaultConfig = [ |
60
|
|
|
'http' => [ |
61
|
|
|
'base_uri' => 'https://api.mch.weixin.qq.com/', |
62
|
|
|
], |
63
|
|
|
]; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Build payment scheme for product. |
67
|
|
|
* |
68
|
|
|
* @param string $productId |
69
|
|
|
* |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
public function scheme(string $productId): string |
73
|
|
|
{ |
74
|
|
|
$params = [ |
75
|
|
|
'appid' => $this['config']->app_id, |
76
|
|
|
'mch_id' => $this['config']->mch_id, |
77
|
|
|
'time_stamp' => time(), |
78
|
|
|
'nonce_str' => uniqid(), |
79
|
|
|
'product_id' => $productId, |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
$params['sign'] = Support\generate_sign($params, $this['config']->key); |
83
|
|
|
|
84
|
|
|
return 'weixin://wxpay/bizpayurl?'.http_build_query($params); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param callable $callback |
89
|
|
|
* |
90
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
91
|
|
|
*/ |
92
|
|
|
public function handlePaidNotify(callable $callback) |
93
|
|
|
{ |
94
|
|
|
return (new Notify\Paid($this))->handle($callback); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param callable $callback |
99
|
|
|
* |
100
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
101
|
|
|
*/ |
102
|
|
|
public function handleRefundedNotify(callable $callback) |
103
|
|
|
{ |
104
|
|
|
return (new Notify\Refunded($this))->handle($callback); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param callable $callback |
109
|
|
|
* |
110
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
111
|
|
|
*/ |
112
|
|
|
public function handleScannedNotify(callable $callback) |
113
|
|
|
{ |
114
|
|
|
return (new Notify\Scanned($this))->handle($callback); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return bool |
119
|
|
|
*/ |
120
|
|
|
public function inSandbox(): bool |
121
|
|
|
{ |
122
|
|
|
return (bool) $this['config']->get('sandbox'); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param string $name |
127
|
|
|
* @param array $arguments |
128
|
|
|
* |
129
|
|
|
* @return mixed |
130
|
|
|
*/ |
131
|
|
|
public function __call($name, $arguments) |
132
|
|
|
{ |
133
|
|
|
return call_user_func_array([$this['base'], $name], $arguments); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|