|
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\Transfer; |
|
13
|
|
|
|
|
14
|
|
|
use EasyWeChat\Kernel\Exceptions\RuntimeException; |
|
15
|
|
|
use function EasyWeChat\Kernel\Support\get_server_ip; |
|
16
|
|
|
use function EasyWeChat\Kernel\Support\rsa_public_encrypt; |
|
17
|
|
|
use EasyWeChat\Payment\Kernel\BaseClient; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class Client. |
|
21
|
|
|
* |
|
22
|
|
|
* @author AC <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class Client extends BaseClient |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Query MerchantPay to balance. |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $partnerTradeNo |
|
30
|
|
|
* |
|
31
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
32
|
|
|
* |
|
33
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
34
|
|
|
*/ |
|
35
|
1 |
|
public function queryBalanceOrder(string $partnerTradeNo) |
|
36
|
|
|
{ |
|
37
|
|
|
$params = [ |
|
38
|
1 |
|
'appid' => $this->app['config']->app_id, |
|
39
|
1 |
|
'mch_id' => $this->app['config']->mch_id, |
|
40
|
1 |
|
'partner_trade_no' => $partnerTradeNo, |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
1 |
|
return $this->safeRequest('mmpaymkttransfers/gettransferinfo', $params); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Send MerchantPay to balance. |
|
48
|
|
|
* |
|
49
|
|
|
* @param array $params |
|
50
|
|
|
* |
|
51
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
52
|
|
|
* |
|
53
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function toBalance(array $params) |
|
56
|
|
|
{ |
|
57
|
|
|
$base = [ |
|
58
|
1 |
|
'mch_id' => null, |
|
59
|
1 |
|
'mchid' => $this->app['config']->mch_id, |
|
60
|
1 |
|
'mch_appid' => $this->app['config']->app_id, |
|
61
|
|
|
]; |
|
62
|
|
|
|
|
63
|
1 |
|
if (empty($params['spbill_create_ip'])) { |
|
64
|
1 |
|
$params['spbill_create_ip'] = get_server_ip(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
1 |
|
return $this->safeRequest('mmpaymkttransfers/promotion/transfers', array_merge($base, $params)); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Query MerchantPay order to BankCard. |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $partnerTradeNo |
|
74
|
|
|
* |
|
75
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
76
|
|
|
* |
|
77
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
78
|
|
|
*/ |
|
79
|
1 |
|
public function queryBankCardOrder(string $partnerTradeNo) |
|
80
|
|
|
{ |
|
81
|
|
|
$params = [ |
|
82
|
1 |
|
'mch_id' => $this->app['config']->mch_id, |
|
83
|
1 |
|
'partner_trade_no' => $partnerTradeNo, |
|
84
|
|
|
]; |
|
85
|
|
|
|
|
86
|
1 |
|
return $this->safeRequest('mmpaysptrans/query_bank', $params); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Send MerchantPay to BankCard. |
|
91
|
|
|
* |
|
92
|
|
|
* @param array $params |
|
93
|
|
|
* |
|
94
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
95
|
|
|
* |
|
96
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
97
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException |
|
98
|
|
|
*/ |
|
99
|
1 |
|
public function toBankCard(array $params) |
|
100
|
|
|
{ |
|
101
|
1 |
|
foreach (['bank_code', 'partner_trade_no', 'enc_bank_no', 'enc_true_name', 'amount'] as $key) { |
|
102
|
1 |
|
if (empty($params[$key])) { |
|
103
|
|
|
throw new RuntimeException(\sprintf('"%s" is required.', $key)); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
1 |
|
$publicKey = file_get_contents($this->app['config']->get('rsa_public_key_path')); |
|
108
|
|
|
|
|
109
|
1 |
|
$params['enc_bank_no'] = rsa_public_encrypt($params['enc_bank_no'], $publicKey); |
|
110
|
1 |
|
$params['enc_true_name'] = rsa_public_encrypt($params['enc_true_name'], $publicKey); |
|
111
|
|
|
|
|
112
|
1 |
|
return $this->safeRequest('mmpaysptrans/pay_bank', $params); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|