From f2af816d6a4ecb0271948c573fbf26b9c2f79ea3 Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Wed, 26 Feb 2025 09:30:12 +0800 Subject: [PATCH] 1 --- application/api/controller/Order.php | 74 ++++-------------------- application/api/controller/Preaccept.php | 3 + application/config.php | 2 +- 3 files changed, 15 insertions(+), 64 deletions(-) diff --git a/application/api/controller/Order.php b/application/api/controller/Order.php index 600bbde..7427da7 100644 --- a/application/api/controller/Order.php +++ b/application/api/controller/Order.php @@ -53,69 +53,17 @@ class Order extends base{ } - public function completePaystation(Request $request){ - - // 获取请求的原始数据(Paystation 发送的 payload) - $payload = $request->getContent(); - - - $filePath = ROOT_PATH . '/payload_log.txt'; - - // 将payload写入文本文件 - file_put_contents($filePath, $payload . PHP_EOL, FILE_APPEND); - - - - // 获取请求头 -// $headers = $request->header(); -// -// // 获取HMAC签名和时间戳 -// $hmac_signature = $headers['x-signature'] ?? ''; -// $timestamp = $headers['x-timestamp'] ?? ''; -// -// // 使用HMAC密钥验证签名 -// $get_hmac = hash_hmac('sha512', $timestamp . $payload, config('paystation.HMAC_KEY')); -// -// if ($hmac_signature != $get_hmac) { -// Log::error('HMAC验证失败', ['timestamp' => $timestamp, 'hmac_signature' => $hmac_signature, 'calculated_hmac' => $get_hmac]); -// return 'HMAC verification failed'; -// } - - // 解析JSON格式的payload - $data = json_decode($payload); - - - - - // 检查result字段是否为空 - if (empty($data->result)) { - return jsonError("Paystation responds with no results"); - } else { - // 交易成功或失败的处理 - - - - - - - if ($data->result->success) { - return jsonSuccess([]); - } else { - return jsonError('Transaction failed'); - } + public function completePaystation(){ + $data = $this->request->post(); + if(!isset($data['transaction_id'])|| !$data['result']['success']){ + return jsonError("Paystation responds with no results or result fail"); } - - - - - -// $sn = $request->param("sn"); -// $order_info = $this->order_obj->where("order_sn",$sn)->find(); -// -// $this->article_obj->where("article_id",$order_info['article_id'])->update(['is_buy'=>1]); -// $this->order_obj->where("order_sn",$order_info['order_sn'])->update(['state'=>1]); -// -// return jsonSuccess([]); + $tid = $data['transaction_id']; + $paystation_info = $this->paystation_obj->where("transaction_id",$tid); + $order_info = $this->order_obj->where("ps_id",$paystation_info['ps_id'])->find(); + $this->article_obj->where("article_id",$order_info['article_id'])->update(['is_buy'=>1]); + $this->order_obj->where("order_id",$order_info['order_id'])->update(['state'=>1]); + return jsonSuccess([]); } @@ -229,7 +177,7 @@ class Order extends base{ "merchant_reference"=>$ca_sn, "amount" =>(int)((((int)$journal_info['fee'])*726/416)*100), // "currency"=>"USD",//目前paystation仅支持nzd - "return_url"=>"https://www.tmrjournals.com/", + "return_url"=>"https://submission.tmrjournals.com/success?id=".$article_info['article_id'], "response_url"=>"http://api.tmrjournals.com/public/index.php/api/Order/completePaystation" ]; $data = json_encode($data_array); diff --git a/application/api/controller/Preaccept.php b/application/api/controller/Preaccept.php index 66b0bf1..f8a0197 100644 --- a/application/api/controller/Preaccept.php +++ b/application/api/controller/Preaccept.php @@ -689,6 +689,9 @@ class Preaccept extends Base return jsonSuccess($re); } $order_info = $this->order_obj->where("article_id",$article_info['article_id'])->find(); + if($order_info['pay_type']==2){ + $order_info['paystation'] = $this->paystation_obj->where("ps_id",$order_info['ps_id'])->find(); + } $re['state'] = $order_info?$order_info['state']:0; $re['fee'] = $journal_info['fee']; $re['order'] = $order_info; diff --git a/application/config.php b/application/config.php index cb7635d..f20c5e5 100644 --- a/application/config.php +++ b/application/config.php @@ -172,7 +172,7 @@ return [ // 日志保存目录 'path' => LOG_PATH, // 日志记录级别 - 'level' => [], + 'level' => ['error'], ], // +----------------------------------------------------------------------