From 32b76b30d93a63db8e6ca76e0befa59df718464b Mon Sep 17 00:00:00 2001 From: xuanchen <122383162@qq.com> Date: Fri, 23 Jul 2021 14:32:06 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Action/Init.php | 2 +- src/Action/Sign.php | 1 + src/Model/Wounicom.php | 17 ++++++++++++++++ src/Traits/Log.php | 46 ++++++++++++++++++++++++++++++++++++++++++ src/WoUnicom.php | 33 ++++++++---------------------- 5 files changed, 73 insertions(+), 26 deletions(-) create mode 100644 src/Model/Wounicom.php create mode 100644 src/Traits/Log.php diff --git a/src/Action/Init.php b/src/Action/Init.php index 5e77792..d97cf03 100644 --- a/src/Action/Init.php +++ b/src/Action/Init.php @@ -139,7 +139,7 @@ class Init $result = (bool) openssl_verify($signStr, $sign, $pub_key_id, 'SHA256'); openssl_free_key($pub_key_id); } else { - throw new \Exception('私钥格式有误'); + throw new \Exception('公钥格式有误'); } return $result; diff --git a/src/Action/Sign.php b/src/Action/Sign.php index 6e34f8e..79f3333 100644 --- a/src/Action/Sign.php +++ b/src/Action/Sign.php @@ -17,6 +17,7 @@ class Sign extends Init // $signMsg = str_replace('\\', '', $signMsg); $signMsg = str_replace(' ', '+', $signMsg); $this->sign = $signMsg; + info($this->sign); return $this->checkSign(); diff --git a/src/Model/Wounicom.php b/src/Model/Wounicom.php new file mode 100644 index 0000000..c12c0ff --- /dev/null +++ b/src/Model/Wounicom.php @@ -0,0 +1,17 @@ + 'json', + 'outsource' => 'json', + ]; + +} diff --git a/src/Traits/Log.php b/src/Traits/Log.php new file mode 100644 index 0000000..e25d96e --- /dev/null +++ b/src/Traits/Log.php @@ -0,0 +1,46 @@ +log = LogModel::create([ + 'orderId' => $data['orderid'], + 'payFloodId' => $data['payfloodid'], + 'payResult' => $data['payresult'], + 'payBalance' => $data['paybalance'], + 'paymentBalanceDetail' => $data['paymentbalancedetail'], + 'respTime' => $data['resptime'], + 'source' => [ + 'data' => $data, + 'check_sign' => $str, + ], + ]); + } + + /** + * Notes: 更新 + * @Author: 玄尘 + * @Date : 2021/7/23 11:03 + * @param $data + */ + public function updateLog($data) + { + $this->log->outsource = $data; + $this->log->save(); + } + +} \ No newline at end of file diff --git a/src/WoUnicom.php b/src/WoUnicom.php index 0cc1d01..d098d61 100644 --- a/src/WoUnicom.php +++ b/src/WoUnicom.php @@ -12,6 +12,7 @@ use XuanChen\WoUnicom\Action\Order; use XuanChen\WoUnicom\Action\Query; use XuanChen\WoUnicom\Action\Refund; use XuanChen\WoUnicom\Action\Sign; +use XuanChen\WoUnicom\Traits\Log; /** * 沃钱包支付 @@ -19,6 +20,8 @@ use XuanChen\WoUnicom\Action\Sign; class WoUnicom { + use Log; + /** * Notes: 下单 * @Author: 玄尘 @@ -92,7 +95,7 @@ class WoUnicom $res = $this->sign()->setParams($data)->start(); //日志 - $this->unicomLog($data, $res); + $this->createLog($data, $res); //验签成功 if ($res === true) { @@ -112,6 +115,7 @@ class WoUnicom } else { $order = \App\Models\Order::where('orderid', $data['orderid'])->first(); + if ($order && $order->state == 'UNPAY') { $payment = \App\Models\Payment::where('orderable_type', get_class($order)) ->where('orderable_id', $order->id) @@ -127,35 +131,14 @@ class WoUnicom } } + $this->updateLog(['SUCCESS']); return 'SUCCESS'; } else { + $this->updateLog(['验签失败']); + return '验签失败'; } } - /** - * Notes: 输入日志 - * @Author: 玄尘 - * @Date : 2021/5/11 15:58 - * @param $data - */ - public function unicomLog($data, $str) - { - $inputData = [ - 'orderId' => $data['orderid'], - 'payFloodId' => $data['payfloodid'], - 'payResult' => $data['payresult'], - 'payBalance' => $data['paybalance'], - 'paymentBalanceDetail' => $data['paymentbalancedetail'], - 'respTime' => $data['resptime'], - 'source' => [ - 'data' => $data, - 'check_sign' => $str, - ], - ]; - - return \App\Models\Wounicom::create($inputData); - } - }