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\ProfitSharing; |
13
|
|
|
|
14
|
|
|
use EasyWeChat\Payment\Kernel\BaseClient; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class Client. |
18
|
|
|
* |
19
|
|
|
* @author ClouderSky <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class Client extends BaseClient |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc}. |
25
|
|
|
*/ |
26
|
|
|
protected function prepends() |
27
|
|
|
{ |
28
|
|
|
return [ |
29
|
|
|
'sign_type' => 'HMAC-SHA256', |
30
|
|
|
]; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Add profit sharing receiver. |
35
|
|
|
* 服务商代子商户发起添加分账接收方请求. |
36
|
|
|
* 后续可通过发起分账请求将结算后的钱分到该分账接收方. |
37
|
|
|
* |
38
|
|
|
* @param array $receiver 分账接收方对象,json格式 |
39
|
|
|
* |
40
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
41
|
|
|
* |
42
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
43
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
44
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
45
|
|
|
*/ |
46
|
1 |
|
public function addReceiver(array $receiver) |
47
|
|
|
{ |
48
|
|
|
$params = [ |
49
|
1 |
|
'appid' => $this->app['config']->app_id, |
50
|
|
|
'receiver' => json_encode( |
51
|
1 |
|
$receiver, |
52
|
1 |
|
JSON_UNESCAPED_UNICODE |
53
|
|
|
), |
54
|
|
|
]; |
55
|
|
|
|
56
|
1 |
|
return $this->request( |
57
|
1 |
|
'pay/profitsharingaddreceiver', |
58
|
|
|
$params |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Delete profit sharing receiver. |
64
|
|
|
* 服务商代子商户发起删除分账接收方请求. |
65
|
|
|
* 删除后不支持将结算后的钱分到该分账接收方. |
66
|
|
|
* |
67
|
|
|
* @param array $receiver 分账接收方对象,json格式 |
68
|
|
|
* |
69
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
70
|
|
|
* |
71
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
72
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
73
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
74
|
|
|
*/ |
75
|
1 |
|
public function deleteReceiver(array $receiver) |
76
|
|
|
{ |
77
|
|
|
$params = [ |
78
|
1 |
|
'appid' => $this->app['config']->app_id, |
79
|
|
|
'receiver' => json_encode( |
80
|
1 |
|
$receiver, |
81
|
1 |
|
JSON_UNESCAPED_UNICODE |
82
|
|
|
), |
83
|
|
|
]; |
84
|
|
|
|
85
|
1 |
|
return $this->request( |
86
|
1 |
|
'pay/profitsharingremovereceiver', |
87
|
|
|
$params |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Single profit sharing. |
93
|
|
|
* 请求单次分账. |
94
|
|
|
* |
95
|
|
|
* @param string $transactionId 微信支付订单号 |
96
|
|
|
* @param string $outOrderNo 商户系统内部的分账单号 |
97
|
|
|
* @param array $receivers 分账接收方列表 |
98
|
|
|
* |
99
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
100
|
|
|
* |
101
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
102
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
103
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
104
|
|
|
*/ |
105
|
1 |
|
public function share( |
106
|
|
|
string $transactionId, |
107
|
|
|
string $outOrderNo, |
108
|
|
|
array $receivers |
109
|
|
|
) { |
110
|
|
|
$params = [ |
111
|
1 |
|
'appid' => $this->app['config']->app_id, |
112
|
1 |
|
'transaction_id' => $transactionId, |
113
|
1 |
|
'out_order_no' => $outOrderNo, |
114
|
|
|
'receivers' => json_encode( |
115
|
1 |
|
$receivers, |
116
|
1 |
|
JSON_UNESCAPED_UNICODE |
117
|
|
|
), |
118
|
|
|
]; |
119
|
|
|
|
120
|
1 |
|
return $this->safeRequest( |
121
|
1 |
|
'secapi/pay/profitsharing', |
122
|
|
|
$params |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Multi profit sharing. |
128
|
|
|
* 请求多次分账. |
129
|
|
|
* |
130
|
|
|
* @param string $transactionId 微信支付订单号 |
131
|
|
|
* @param string $outOrderNo 商户系统内部的分账单号 |
132
|
|
|
* @param array $receivers 分账接收方列表 |
133
|
|
|
* |
134
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
135
|
|
|
* |
136
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
137
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
138
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
139
|
|
|
*/ |
140
|
1 |
|
public function multiShare( |
141
|
|
|
string $transactionId, |
142
|
|
|
string $outOrderNo, |
143
|
|
|
array $receivers |
144
|
|
|
) { |
145
|
|
|
$params = [ |
146
|
1 |
|
'appid' => $this->app['config']->app_id, |
147
|
1 |
|
'transaction_id' => $transactionId, |
148
|
1 |
|
'out_order_no' => $outOrderNo, |
149
|
|
|
'receivers' => json_encode( |
150
|
1 |
|
$receivers, |
151
|
1 |
|
JSON_UNESCAPED_UNICODE |
152
|
|
|
), |
153
|
|
|
]; |
154
|
|
|
|
155
|
1 |
|
return $this->safeRequest( |
156
|
1 |
|
'secapi/pay/multiprofitsharing', |
157
|
|
|
$params |
158
|
|
|
); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Finish profit sharing. |
163
|
|
|
* 完结分账. |
164
|
|
|
* |
165
|
|
|
* @param array $params |
166
|
|
|
* |
167
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
168
|
|
|
* |
169
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
170
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
171
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
172
|
|
|
*/ |
173
|
1 |
|
public function markOrderAsFinished(array $params) |
174
|
|
|
{ |
175
|
1 |
|
$params['appid'] = $this->app['config']->app_id; |
176
|
1 |
|
$params['sub_appid'] = null; |
177
|
|
|
|
178
|
1 |
|
return $this->safeRequest( |
179
|
1 |
|
'secapi/pay/profitsharingfinish', |
180
|
|
|
$params |
181
|
|
|
); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Query profit sharing result. |
186
|
|
|
* 查询分账结果. |
187
|
|
|
* |
188
|
|
|
* @param string $transactionId 微信支付订单号 |
189
|
|
|
* @param string $outOrderNo 商户系统内部的分账单号 |
190
|
|
|
* |
191
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
192
|
|
|
* |
193
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
194
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
195
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
196
|
|
|
*/ |
197
|
1 |
|
public function query( |
198
|
|
|
string $transactionId, |
199
|
|
|
string $outOrderNo |
200
|
|
|
) { |
201
|
|
|
$params = [ |
202
|
1 |
|
'sub_appid' => null, |
203
|
1 |
|
'transaction_id' => $transactionId, |
204
|
1 |
|
'out_order_no' => $outOrderNo, |
205
|
|
|
]; |
206
|
|
|
|
207
|
1 |
|
return $this->request( |
208
|
1 |
|
'pay/profitsharingquery', |
209
|
|
|
$params |
210
|
|
|
); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Profit sharing return. |
215
|
|
|
* 分账回退. |
216
|
|
|
* |
217
|
|
|
* @param string $outOrderNo 商户系统内部的分账单号 |
218
|
|
|
* @param string $outReturnNo 商户系统内部分账回退单号 |
219
|
|
|
* @param int $returnAmount 回退金额 |
220
|
|
|
* @param string $returnAccount 回退方账号 |
221
|
|
|
* @param string $description 回退描述 |
222
|
|
|
* |
223
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
224
|
|
|
* |
225
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
226
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
227
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
228
|
|
|
*/ |
229
|
1 |
|
public function returnShare( |
230
|
|
|
string $outOrderNo, |
231
|
|
|
string $outReturnNo, |
232
|
|
|
int $returnAmount, |
233
|
|
|
string $returnAccount, |
234
|
|
|
string $description |
235
|
|
|
) { |
236
|
|
|
$params = [ |
237
|
1 |
|
'appid' => $this->app['config']->app_id, |
238
|
1 |
|
'out_order_no' => $outOrderNo, |
239
|
1 |
|
'out_return_no' => $outReturnNo, |
240
|
1 |
|
'return_account_type' => 'MERCHANT_ID', |
241
|
1 |
|
'return_account' => $returnAccount, |
242
|
1 |
|
'return_amount' => $returnAmount, |
243
|
1 |
|
'description' => $description, |
244
|
|
|
]; |
245
|
|
|
|
246
|
1 |
|
return $this->safeRequest( |
247
|
1 |
|
'secapi/pay/profitsharingreturn', |
248
|
|
|
$params |
249
|
|
|
); |
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
|