Skip to content

Commit fa5ecfa

Browse files
committed
微信企业打款到银行卡
获取RSA算法公钥
1 parent 2ab811f commit fa5ecfa

File tree

5 files changed

+366
-0
lines changed

5 files changed

+366
-0
lines changed

src/BaseAbstractGateway.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,24 @@ public function downloadBill($parameters = array())
244244
{
245245
return $this->createRequest('\Omnipay\WechatPay\Message\DownloadBillRequest', $parameters);
246246
}
247+
248+
/**
249+
* @param array $parameters
250+
*
251+
* @return \Omnipay\WechatPay\Message\PayBankRequest
252+
*/
253+
public function payBank($parameters = array())
254+
{
255+
return $this->createRequest('\Omnipay\WechatPay\Message\PayBankRequest', $parameters);
256+
}
257+
258+
/**
259+
* @param array $parameters
260+
*
261+
* @return \Omnipay\WechatPay\Message\GetPublicKeyRequest
262+
*/
263+
public function getPublicKey($parameters = array())
264+
{
265+
return $this->createRequest('\Omnipay\WechatPay\Message\GetPublicKeyRequest', $parameters);
266+
}
247267
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
namespace Omnipay\WechatPay\Message;
4+
5+
use GuzzleHttp\Client;
6+
use Omnipay\Common\Exception\InvalidRequestException;
7+
use Omnipay\Common\Message\ResponseInterface;
8+
use Omnipay\WechatPay\Helper;
9+
10+
/**
11+
* Class GetPublicKeyRequest
12+
*
13+
* @package Omnipay\WechatPay\Message
14+
* @link https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=24_7
15+
* @method GetPublicKeyResponse send()
16+
*/
17+
class GetPublicKeyRequest extends BaseAbstractRequest
18+
{
19+
protected $endpoint = 'https://fraud.mch.weixin.qq.com/risk/getpublickey';
20+
21+
/**
22+
* Get the raw data array for this message. The format of this varies from gateway to
23+
* gateway, but will usually be either an associative array, or a SimpleXMLElement.
24+
* @return mixed
25+
* @throws InvalidRequestException
26+
*/
27+
public function getData()
28+
{
29+
$this->validate('mch_id', 'cert_path', 'key_path');
30+
31+
$data = array(
32+
'mch_id' => $this->getMchId(),
33+
'nonce_str' => md5(uniqid()),
34+
);
35+
36+
$data = array_filter($data);
37+
38+
$data['sign'] = Helper::sign($data, $this->getApiKey());
39+
40+
return $data;
41+
}
42+
43+
44+
/**
45+
* @return mixed
46+
*/
47+
public function getCertPath()
48+
{
49+
return $this->getParameter('cert_path');
50+
}
51+
52+
53+
/**
54+
* @param mixed $certPath
55+
*/
56+
public function setCertPath($certPath)
57+
{
58+
$this->setParameter('cert_path', $certPath);
59+
}
60+
61+
62+
/**
63+
* @return mixed
64+
*/
65+
public function getKeyPath()
66+
{
67+
return $this->getParameter('key_path');
68+
}
69+
70+
71+
/**
72+
* @param mixed $keyPath
73+
*/
74+
public function setKeyPath($keyPath)
75+
{
76+
$this->setParameter('key_path', $keyPath);
77+
}
78+
79+
80+
/**
81+
* Send the request with specified data
82+
*
83+
* @param mixed $data The data to send
84+
*
85+
* @return ResponseInterface
86+
*/
87+
public function sendData($data)
88+
{
89+
$body = Helper::array2xml($data);
90+
$client = new Client();
91+
92+
$options = [
93+
'body' => $body,
94+
'verify' => true,
95+
'cert' => $this->getCertPath(),
96+
'ssl_key' => $this->getKeyPath(),
97+
];
98+
$response = $client->request('POST', $this->endpoint, $options)->getBody();
99+
$responseData = Helper::xml2array($response);
100+
101+
return $this->response = new PayBankResponse($this, $responseData);
102+
}
103+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Omnipay\WechatPay\Message;
4+
5+
/**
6+
* Class GetPublicKeyResponse
7+
*
8+
* @package Omnipay\WechatPay\Message
9+
* @link https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=24_7
10+
*/
11+
class GetPublicKeyResponse extends BaseAbstractResponse
12+
{
13+
}

src/Message/PayBankRequest.php

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
<?php
2+
3+
namespace Omnipay\WechatPay\Message;
4+
5+
use GuzzleHttp\Client;
6+
use Omnipay\Common\Exception\InvalidRequestException;
7+
use Omnipay\Common\Message\ResponseInterface;
8+
use Omnipay\WechatPay\Helper;
9+
10+
/**
11+
* Class PayBankRequest
12+
*
13+
* @package Omnipay\WechatPay\Message
14+
* @link https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=24_2
15+
* @method PayBankResponse send()
16+
*/
17+
class PayBankRequest extends BaseAbstractRequest
18+
{
19+
protected $endpoint = 'https://api.mch.weixin.qq.com/mmpaysptrans/pay_bank';
20+
21+
/**
22+
* Get the raw data array for this message. The format of this varies from gateway to
23+
* gateway, but will usually be either an associative array, or a SimpleXMLElement.
24+
* @return mixed
25+
* @throws InvalidRequestException
26+
*/
27+
public function getData()
28+
{
29+
$this->validate('mch_id', 'partner_trade_no', 'enc_bank_no', 'enc_true_name', 'bank_code', 'amount', 'desc', 'cert_path', 'key_path');
30+
31+
$data = array(
32+
'mch_id' => $this->getMchId(),
33+
'partner_trade_no' => $this->getPartnerTradeNo(),
34+
'enc_bank_no' => $this->getEncBankNo(),
35+
'enc_true_name' => $this->getEncTrueName(),
36+
'bank_code' => $this->getBankCode(),
37+
'amount' => $this->getAmount(),
38+
'desc' => $this->getDesc(),
39+
'nonce_str' => md5(uniqid()),
40+
);
41+
42+
$data = array_filter($data);
43+
44+
$data['sign'] = Helper::sign($data, $this->getApiKey());
45+
46+
return $data;
47+
}
48+
49+
50+
/**
51+
* @return mixed
52+
*/
53+
public function getPartnerTradeNo()
54+
{
55+
return $this->getParameter('partner_trade_no');
56+
}
57+
58+
59+
/**
60+
* @param mixed $partnerTradeNo
61+
*/
62+
public function setPartnerTradeNo($partnerTradeNo)
63+
{
64+
$this->setParameter('partner_trade_no', $partnerTradeNo);
65+
}
66+
67+
68+
/**
69+
* @return mixed
70+
*/
71+
public function getEncBankNo()
72+
{
73+
return $this->getParameter('enc_bank_no');
74+
}
75+
76+
77+
/**
78+
* @param mixed $encBankNo
79+
*/
80+
public function setEncBankNo($encBankNo)
81+
{
82+
$this->setParameter('enc_bank_no', $encBankNo);
83+
}
84+
85+
86+
/**
87+
* @return mixed
88+
*/
89+
public function getEncTrueName()
90+
{
91+
return $this->getParameter('enc_true_name');
92+
}
93+
94+
95+
/**
96+
* @param mixed $encTrueName
97+
*/
98+
public function setEncTrueName($encTrueName)
99+
{
100+
$this->setParameter('enc_true_name', $encTrueName);
101+
}
102+
103+
104+
/**
105+
* @return mixed
106+
*/
107+
public function getBankCode()
108+
{
109+
return $this->getParameter('bank_code');
110+
}
111+
112+
113+
/**
114+
* @param mixed $bankCode
115+
*/
116+
public function setBankCode($bankCode)
117+
{
118+
$this->setParameter('bank_code', $bankCode);
119+
}
120+
121+
122+
/**
123+
* @return mixed
124+
*/
125+
public function getAmount()
126+
{
127+
return $this->getParameter('amount');
128+
}
129+
130+
131+
/**
132+
* @param mixed $amount
133+
*/
134+
public function setAmount($amount)
135+
{
136+
$this->setParameter('amount', $amount);
137+
}
138+
139+
140+
/**
141+
* @return mixed
142+
*/
143+
public function getDesc()
144+
{
145+
return $this->getParameter('desc');
146+
}
147+
148+
149+
/**
150+
* @param mixed $desc
151+
*/
152+
public function setDesc($desc)
153+
{
154+
$this->setParameter('desc', $desc);
155+
}
156+
157+
158+
/**
159+
* @return mixed
160+
*/
161+
public function getCertPath()
162+
{
163+
return $this->getParameter('cert_path');
164+
}
165+
166+
167+
/**
168+
* @param mixed $certPath
169+
*/
170+
public function setCertPath($certPath)
171+
{
172+
$this->setParameter('cert_path', $certPath);
173+
}
174+
175+
176+
/**
177+
* @return mixed
178+
*/
179+
public function getKeyPath()
180+
{
181+
return $this->getParameter('key_path');
182+
}
183+
184+
185+
/**
186+
* @param mixed $keyPath
187+
*/
188+
public function setKeyPath($keyPath)
189+
{
190+
$this->setParameter('key_path', $keyPath);
191+
}
192+
193+
194+
/**
195+
* Send the request with specified data
196+
*
197+
* @param mixed $data The data to send
198+
*
199+
* @return ResponseInterface
200+
*/
201+
public function sendData($data)
202+
{
203+
$body = Helper::array2xml($data);
204+
$client = new Client();
205+
206+
$options = [
207+
'body' => $body,
208+
'verify' => true,
209+
'cert' => $this->getCertPath(),
210+
'ssl_key' => $this->getKeyPath(),
211+
];
212+
$response = $client->request('POST', $this->endpoint, $options)->getBody();
213+
$responseData = Helper::xml2array($response);
214+
215+
return $this->response = new PayBankResponse($this, $responseData);
216+
}
217+
}

src/Message/PayBankResponse.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Omnipay\WechatPay\Message;
4+
5+
/**
6+
* Class PayBankResponse
7+
*
8+
* @package Omnipay\WechatPay\Message
9+
* @link https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=24_2
10+
*/
11+
class PayBankResponse extends BaseAbstractResponse
12+
{
13+
}

0 commit comments

Comments
 (0)