From fb45a0b5e8ae18066f37835e911a40703f83f8c7 Mon Sep 17 00:00:00 2001 From: yansongda Date: Sat, 19 Aug 2017 15:24:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9F=A5=E8=AF=A2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Contracts/GatewayInterface.php | 12 ++++++++++++ src/Gateways/Alipay/Alipay.php | 19 +++++++++++++++++++ src/Gateways/Wechat/Wechat.php | 2 +- src/Traits/HasHttpRequest.php | 19 +++++++------------ 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/Contracts/GatewayInterface.php b/src/Contracts/GatewayInterface.php index ffd368b..76c9f11 100644 --- a/src/Contracts/GatewayInterface.php +++ b/src/Contracts/GatewayInterface.php @@ -45,6 +45,18 @@ interface GatewayInterface */ public function close(array $config_biz); + /** + * 对外接口 - 订单查询 + * @author yansongda + * + * @version 2017-08-19 + * + * @param string $out_trade_no 商家订单号 + * + * @return array|boolean [description] + */ + public function find($out_trade_no); + /** * 验证消息是否官方发出 * diff --git a/src/Gateways/Alipay/Alipay.php b/src/Gateways/Alipay/Alipay.php index 1b88dd8..5a2be6e 100644 --- a/src/Gateways/Alipay/Alipay.php +++ b/src/Gateways/Alipay/Alipay.php @@ -123,6 +123,25 @@ abstract class Alipay implements GatewayInterface return $this->getResult($config_biz, 'alipay.trade.close'); } + /** + * 对外接口 - 订单查询 + * @author yansongda + * + * @version 2017-08-19 + * + * @param string $out_trade_no 商家订单号 + * + * @return array|boolean [description] + */ + public function find($out_trade_no = '') + { + $config_biz = [ + 'out_trade_no' => $out_trade_no, + ]; + + return $this->getResult($config_biz, 'alipay.trade.query'); + } + /** * 对外接口 - 验证. * diff --git a/src/Gateways/Wechat/Wechat.php b/src/Gateways/Wechat/Wechat.php index 644f0f4..fe655d2 100644 --- a/src/Gateways/Wechat/Wechat.php +++ b/src/Gateways/Wechat/Wechat.php @@ -149,7 +149,7 @@ abstract class Wechat implements GatewayInterface $this->config['total_fee'] = intval($this->config['total_fee'] * 100); $this->config['sign'] = $this->getSign($this->config); - $data = $this->fromXml($this->post($this->gateway, [], $this->toXml($this->config))); + $data = $this->fromXml($this->post($this->gateway, $this->toXml($this->config))); if (!isset($data['return_code']) || $data['return_code'] !== 'SUCCESS' || $data['result_code'] !== 'SUCCESS') { $error = 'preOrder error:' . $data['return_msg']; diff --git a/src/Traits/HasHttpRequest.php b/src/Traits/HasHttpRequest.php index bbdf81f..4ab8067 100644 --- a/src/Traits/HasHttpRequest.php +++ b/src/Traits/HasHttpRequest.php @@ -41,24 +41,19 @@ trait HasHttpRequest * Make a post request. * * @param string $endpoint - * @param array $params - * @param string $body + * @param mixed $params * @param array $headers * * @return string */ - protected function post($endpoint, $params = [], $body = null, $headers = []) + protected function post($endpoint, $params = [], $headers = []) { - $options = [ - 'headers' => $headers, - 'form_params' => $params, - ]; + $options['headers'] = $headers; - if (!is_null($body)) { - $options = [ - 'headers' => $headers, - 'body' => $body, - ]; + if (!is_array($params)) { + $options['body'] = $params; + } else { + $options['form_params'] = $params; } return $this->request('post', $endpoint, $options);