2
2
3
3
namespace Omnipay \WechatPay \Message ;
4
4
5
- use Guzzle \ Http \Client ;
5
+ use GuzzleHttp \Client ;
6
6
use Omnipay \Common \Exception \InvalidRequestException ;
7
7
use Omnipay \Common \Message \ResponseInterface ;
8
8
use Omnipay \WechatPay \Helper ;
@@ -29,7 +29,7 @@ public function getData()
29
29
{
30
30
$ this ->validate ('app_id ' , 'mch_id ' , 'out_trade_no ' , 'cert_path ' , 'key_path ' );
31
31
32
- $ data = array (
32
+ $ data = [
33
33
'appid ' => $ this ->getAppId (),
34
34
'mch_id ' => $ this ->getMchId (),
35
35
'sub_appid ' => $ this ->getSubAppId (),
@@ -43,7 +43,7 @@ public function getData()
43
43
'refund_fee_type ' => $ this ->getRefundFee (),//<>
44
44
'op_user_id ' => $ this ->getOpUserId () ?: $ this ->getMchId (),
45
45
'nonce_str ' => md5 (uniqid ()),
46
- ) ;
46
+ ] ;
47
47
48
48
$ data = array_filter ($ data );
49
49
@@ -239,20 +239,15 @@ public function setKeyPath($keyPath)
239
239
*/
240
240
public function sendData ($ data )
241
241
{
242
- $ options = array (
243
- CURLOPT_SSL_VERIFYPEER => true ,
244
- CURLOPT_SSL_VERIFYHOST => 2 ,
245
- CURLOPT_SSLCERTTYPE => 'PEM ' ,
246
- CURLOPT_SSLKEYTYPE => 'PEM ' ,
247
- CURLOPT_SSLCERT => $ this ->getCertPath (),
248
- CURLOPT_SSLKEY => $ this ->getKeyPath (),
249
- );
250
-
251
- $ body = Helper::array2xml ($ data );
252
- $ request = $ this ->httpClient ->post ($ this ->endpoint , null , $ data )->setBody ($ body );
253
- $ request ->getCurlOptions ()->overwriteWith ($ options );
254
- $ response = $ request ->send ()->getBody ();
255
- $ responseData = Helper::xml2array ($ response );
242
+ $ body = Helper::array2xml ($ data );
243
+ $ client = new Client ();
244
+ $ result = $ client ->request ('POST ' , $ this ->endpoint , [
245
+ 'body ' => $ body ,
246
+ 'verify ' => true ,
247
+ 'cert ' => $ this ->getCertPath (),
248
+ 'ssl_key ' => $ this ->getKeyPath (),
249
+ ])->getBody ()->getContents ();
250
+ $ responseData = Helper::xml2array ($ result );
256
251
257
252
return $ this ->response = new RefundOrderResponse ($ this , $ responseData );
258
253
}
0 commit comments