diff --git a/src/Payment/API.php b/src/Payment/API.php index a3b5a7805..fbe4825a2 100644 --- a/src/Payment/API.php +++ b/src/Payment/API.php @@ -159,7 +159,7 @@ public function reverse($orderNo, $type = self::OUT_TRADE_NO) $type => $orderNo, ]; - return $this->request(self::API_REVERSE, $params); + return $this->safeRequest(self::API_REVERSE, $params); } /** @@ -202,7 +202,7 @@ public function refund( 'op_user_id' => $opUserId ?: $this->merchant->merchant_id, ]; - return $this->request(self::API_REFUND, $params); + return $this->safeRequest(self::API_REFUND, $params); } /** @@ -374,10 +374,11 @@ public function getMerchant() * @param string $api * @param array $params * @param string $method + * @param array $options * * @return \EasyWeChat\Support\Collection */ - protected function request($api, array $params, $method = 'post') + protected function request($api, array $params, $method = 'post', array $options = []) { $params['appid'] = $this->merchant->app_id; $params['mch_id'] = $this->merchant->merchant_id; @@ -385,13 +386,30 @@ protected function request($api, array $params, $method = 'post') $params['nonce_str'] = uniqid(); $params['sign'] = generate_sign($params, $this->merchant->key, 'md5'); - $options = [ + $options = array_merge([ 'body' => XML::build($params), + ], $options); + + return $this->parseResponse($this->getHttp()->request($api, $method, $options)); + } + + /** + * Request with SSL. + * + * @param string $api + * @param array $params + * @param string $method + * + * @return \EasyWeChat\Support\Collection + */ + protected function safeRequest($api, array $params, $method = 'post') + { + $options = [ 'cert' => $this->merchant->get('cert_path'), 'ssl_key' => $this->merchant->get('key_path'), ]; - return $this->parseResponse($this->getHttp()->request($api, $method, $options)); + return $this->request($api, $params, $method, $options); } /**