diff --git a/src/Action/Init.php b/src/Action/Init.php index d97cf03..b25a932 100644 --- a/src/Action/Init.php +++ b/src/Action/Init.php @@ -301,7 +301,6 @@ class Init } $client = new Client(); - try { $response = $client->request('POST', $url, [ 'form_params' => $paramArray, @@ -312,26 +311,27 @@ class Init if ($response->getStatusCode() == 200) { $body = $response->getBody(); $content = str_replace(["\r\n", "\n", "\r", '/n', "\\n",], '&', $body->getContents()); - parse_str($content, $data); $this->data = $data; - if ($data['transRet'] != 'SUCCESS') { - $this->code = false; - $this->message = $data['resultDis']; + if (isset($data['queryResult']) && $data['queryResult'] != 'SUCCESS') { + throw new \Exception('返回的数据错误'); + } + + if (isset($data['transRet']) && $data['transRet'] != 'SUCCESS') { + throw new \Exception($data['resultDis']); } $this->code = true; } else { - $this->code = false; - $this->message = '接口错误 Post'; + throw new \Exception('未正常返回数据'); } } catch (\Exception $exception) { $this->code = false; - $this->message = '接口错误 Post' . $exception->getMessage(); + $this->message = '接口错误 ' . $exception->getMessage(); } } diff --git a/src/Action/Query.php b/src/Action/Query.php index b49aea7..4851d8d 100644 --- a/src/Action/Query.php +++ b/src/Action/Query.php @@ -13,6 +13,28 @@ class Query extends Init public function start() { + $this->setIsLower(false); + $this->addData(); + $this->setSignData(); + $url = config('wounicom.uri.unicom.query'); + $this->sendPost($this->params, $url); + + return $this->respond(); + } + + public function addData() + { + $order = $this->params; + + $data = [ + 'merNo' => $this->merNo, + 'orderNo' => $order->orderid, + 'orderDate' => $order->created_at->format('Ymd'), + 'charSet' => 'UTF-8', + 'signType' => config('wounicom.signType'), + ]; + + $this->params = $data; } diff --git a/src/Action/Refund.php b/src/Action/Refund.php index fe323f5..c7b4781 100644 --- a/src/Action/Refund.php +++ b/src/Action/Refund.php @@ -35,7 +35,7 @@ class Refund extends Init 'orderDate' => $order->created_at->format('Ymd'), 'payJournl' => $order->payment->out_trade_no, 'merReqTime' => Carbon::now()->format('YmdHis'), - 'amount' => -1, + 'amount' => $order->payment->amount * 100, 'reason' => '退款', 'signType' => 'RSA_SHA256', ]; diff --git a/src/WoUnicom.php b/src/WoUnicom.php index d098d61..8f40ab2 100644 --- a/src/WoUnicom.php +++ b/src/WoUnicom.php @@ -45,7 +45,10 @@ class WoUnicom */ public function query() { - return (new Query()); + $action = new Query(); + $action->setConfig(); + + return $action; } /**