|
| 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 QueryBankRequest |
| 12 | + * |
| 13 | + * @package Omnipay\WechatPay\Message |
| 14 | + * @link https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=24_3 |
| 15 | + * @method QueryBankResponse send() |
| 16 | + */ |
| 17 | +class QueryBankRequest extends BaseAbstractRequest |
| 18 | +{ |
| 19 | + protected $endpoint = 'https://api.mch.weixin.qq.com/mmpaysptrans/query_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', 'cert_path', 'key_path'); |
| 30 | + |
| 31 | + $data = array( |
| 32 | + 'mch_id' => $this->getMchId(), |
| 33 | + 'partner_trade_no' => $this->getPartnerTradeNo(), |
| 34 | + 'nonce_str' => md5(uniqid()), |
| 35 | + ); |
| 36 | + |
| 37 | + $data = array_filter($data); |
| 38 | + |
| 39 | + $data['sign'] = Helper::sign($data, $this->getApiKey()); |
| 40 | + |
| 41 | + return $data; |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | + /** |
| 46 | + * @return mixed |
| 47 | + */ |
| 48 | + public function getPartnerTradeNo() |
| 49 | + { |
| 50 | + return $this->getParameter('partner_trade_no'); |
| 51 | + } |
| 52 | + |
| 53 | + |
| 54 | + /** |
| 55 | + * @param mixed $partnerTradeNo |
| 56 | + */ |
| 57 | + public function setPartnerTradeNo($partnerTradeNo) |
| 58 | + { |
| 59 | + $this->setParameter('partner_trade_no', $partnerTradeNo); |
| 60 | + } |
| 61 | + |
| 62 | + |
| 63 | + /** |
| 64 | + * @return mixed |
| 65 | + */ |
| 66 | + public function getCertPath() |
| 67 | + { |
| 68 | + return $this->getParameter('cert_path'); |
| 69 | + } |
| 70 | + |
| 71 | + |
| 72 | + /** |
| 73 | + * @param mixed $certPath |
| 74 | + */ |
| 75 | + public function setCertPath($certPath) |
| 76 | + { |
| 77 | + $this->setParameter('cert_path', $certPath); |
| 78 | + } |
| 79 | + |
| 80 | + |
| 81 | + /** |
| 82 | + * @return mixed |
| 83 | + */ |
| 84 | + public function getKeyPath() |
| 85 | + { |
| 86 | + return $this->getParameter('key_path'); |
| 87 | + } |
| 88 | + |
| 89 | + |
| 90 | + /** |
| 91 | + * @param mixed $keyPath |
| 92 | + */ |
| 93 | + public function setKeyPath($keyPath) |
| 94 | + { |
| 95 | + $this->setParameter('key_path', $keyPath); |
| 96 | + } |
| 97 | + |
| 98 | + |
| 99 | + /** |
| 100 | + * Send the request with specified data |
| 101 | + * |
| 102 | + * @param mixed $data The data to send |
| 103 | + * |
| 104 | + * @return ResponseInterface |
| 105 | + */ |
| 106 | + public function sendData($data) |
| 107 | + { |
| 108 | + $body = Helper::array2xml($data); |
| 109 | + $client = new Client(); |
| 110 | + |
| 111 | + $options = [ |
| 112 | + 'body' => $body, |
| 113 | + 'verify' => true, |
| 114 | + 'cert' => $this->getCertPath(), |
| 115 | + 'ssl_key' => $this->getKeyPath(), |
| 116 | + ]; |
| 117 | + $response = $client->request('POST', $this->endpoint, $options)->getBody(); |
| 118 | + $responseData = Helper::xml2array($response); |
| 119 | + |
| 120 | + return $this->response = new QueryBankResponse($this, $responseData); |
| 121 | + } |
| 122 | +} |
0 commit comments