From a38b143c9f9bf9f02ee5cdf2cc0f8c15c2020e60 Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Tue, 18 Feb 2025 11:00:38 +0800 Subject: [PATCH] 1 --- .env | 5 + application/api/controller/Article.php | 16 +-- application/api/controller/Preaccept.php | 142 +++++++++++++++++++++++ application/api/controller/Publish.php | 1 + 4 files changed, 157 insertions(+), 7 deletions(-) diff --git a/.env b/.env index 73f3bca..56cbb74 100644 --- a/.env +++ b/.env @@ -9,6 +9,11 @@ editor_email = publisher@tmrjournals.com ;读取的企业邮箱 mail_server = imap.qq.com +[paystation] +api_url = https://api.paystation.co.nz +client_id = 616562 +client_secret = CfMDrllyqBTFKrUkO2XaE7OmWTYqP3yd + [journal] ;官网服务器地址 diff --git a/application/api/controller/Article.php b/application/api/controller/Article.php index c552641..68492fe 100644 --- a/application/api/controller/Article.php +++ b/application/api/controller/Article.php @@ -1907,7 +1907,9 @@ class Article extends Base $tt .= 'Email:' . $journal_info['email'] . '
'; $tt .= 'Website:' . $journal_info['website']; - sendEmail($reviewer_info['email'], $journal_info['title'], $journal_info['title'], $tt, $journal_info['email'], $journal_info['epassword']); + + $email_title = "Invitation to review manuscript for ".$journal_info['title']."-[".$article_info['accept_sn']."]"; + sendEmail($reviewer_info['email'], $email_title, $journal_info['title'], $tt, $journal_info['email'], $journal_info['epassword']); //记录userlog $log_data['user_id'] = $article_info['editor_id']; @@ -2936,12 +2938,12 @@ class Article extends Base $article_id = $this->article_obj->insertGetId($inset_data); } else { - $checkArticle = $this->article_obj->where("article_id", "<>", $article_id)->where("title", trim($data['title']))->select(); - foreach ($checkArticle as $v) { - if ($v['state'] != 3) { - return json(['code' => 1, 'msg' => 'Warning: you are re-submitting the article!']); - } - } +// $checkArticle = $this->article_obj->where("article_id", "<>", $article_id)->where("title", trim($data['title']))->select(); +// foreach ($checkArticle as $v) { +// if ($v['state'] != 3) { +// return json(['code' => 1, 'msg' => 'Warning: you are re-submitting the article!']); +// } +// } $up['user_id'] = $user_info['user_id']; $up['journal_id'] = $data['journal']; $up['editor_id'] = $journal_info['editor_id']; diff --git a/application/api/controller/Preaccept.php b/application/api/controller/Preaccept.php index 7a03ad6..e713e19 100644 --- a/application/api/controller/Preaccept.php +++ b/application/api/controller/Preaccept.php @@ -3,6 +3,7 @@ namespace app\api\controller; use think\Db; +use think\Env; use think\Queue; use think\Validate; @@ -1125,6 +1126,147 @@ class Preaccept extends Base return jsonSuccess([]); } + public function payStationTest(){ + $accessToken = $this->payStationAccessToken(); + $data_array = [ + 'paystation_id' => Env::get("paystation.client_id"), + 'gateway_id' => "v1",//GATEWAY_ID, + 'merchant_session' => "myTestSN001", +// 'merchant_reference' => 'testReference', + 'amount' => 2000, //$20 in cents value + "test_mode"=>true + ]; +// OPTIONAL, ideally should be set on your Paystation account + $data_array += [ + 'return_url' => "http://192.168.110.110/tougao/public/index.php/api/Preaccept/patStationReturn",//'http://localhost:8002/3party/return.php', + // Webhook receipt page. This should be publicly accessible (see example post-response.php) + 'response_url' => "https://www.tmrjournals.com"//'https://webhook.site/sample-code-webhook' + ]; + $data = json_encode($data_array); + +// Purchase initiate request + $purchase = $this->postRequest('v1/hosted/purchases', $accessToken, $data); + return jsonSuccess($purchase); + if ($purchase) { + $result = json_decode($purchase); + if ($result && isset($result->payment_url)) { + header("Location: {$result->payment_url}"); + } else { + //@todo: Replace with your own error handling + print_r($result); + return null; + } + } + } + + + + public function payStationTest1(){ + $accessToken = $this->payStationAccessToken(); + $data_array = [ + 'paystation_id' => Env::get("paystation.client_id"), + 'gateway_id' => "v1",//GATEWAY_ID, + "order_name" => "mytestOrderSn", + "amount" =>200, + "test_mode"=>true + ]; + $data = json_encode($data_array); + + $purchase = $this->postRequest('v1/payme/purchases', $accessToken, $data); + + return jsonSuccess($purchase); + } + + + + + public function patStationReturn(){ + $query_string = $_SERVER['QUERY_STRING']; + parse_str($query_string, $data); + + if (isset($data['code'])) { + // Add code here to display result + // Do not update transaction status here because query strings can be manipulated + // Do a transaction lookup instead to verify the results. Check documentation for more details. + if ($data['code'] == '0') { + echo 'Transaction ok: ' . $data['message']; + } else { + echo 'Transaction failed: ' . $data['message']; + } + } + } + + private function payStationAccessToken(){ + $bodyParams = [ + 'client_id' => Env::get("paystation.client_id"), + 'client_secret' => Env::get("paystation.client_secret"), + 'grant_type' => 'client_credentials', + 'scope' => "mytest" + ]; + $accessTokenUrl = Env::get("paystation.api_url") . '/oauth/token'; + $curlHandle = curl_init($accessTokenUrl); + $options = [ + CURLOPT_RETURNTRANSFER => true, + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_HTTPHEADER => [ + "cache-control: no-cache", + "content-type: application/x-www-form-urlencoded", + "accept: *", + "accept-encoding: gzip, deflate", + ], + CURLOPT_POSTFIELDS => http_build_query($bodyParams) + ]; + curl_setopt_array($curlHandle, $options); + curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false); + $curlResponse = curl_exec($curlHandle); + $error = curl_error($curlHandle); + curl_close($curlHandle); + + if ($error) { + echo "cURL error: " . $error; + } else { + $response = json_decode($curlResponse); + if (array_key_exists('access_token', $response)) { + return $response->access_token; + } + if (array_key_exists('error', $response)) { + echo $response->error_description; + } + } + } + + public function postRequest($endpoint, $token, $body) +{ + $curlHandle = curl_init(Env::get("paystation.api_url") . '/' . $endpoint); + $options = [ + CURLOPT_RETURNTRANSFER => true, + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_SSL_VERIFYPEER=>false, + CURLOPT_HTTPHEADER => [ + "cache-control: no-cache", + "content-type: application/json", + "accept: *", + "accept-encoding: gzip, deflate", + "Authorization: Bearer " . $token + ], + CURLOPT_POSTFIELDS => $body + ]; + curl_setopt_array($curlHandle, $options); + $response = curl_exec($curlHandle); + $error = curl_error($curlHandle); + curl_close($curlHandle); + if ($error) { + echo "cURL error: " . $error; + } else { + return $response ?: null; +} +return null; +} + // public function getArticleMains(){ // $data = $this->request->post(); diff --git a/application/api/controller/Publish.php b/application/api/controller/Publish.php index edc5291..c08e16e 100644 --- a/application/api/controller/Publish.php +++ b/application/api/controller/Publish.php @@ -48,6 +48,7 @@ class Publish extends Base continue; } $stages[$k]['articles'][$key]['tg_article_id'] = $pro_info['article_id']; + $stages[$k]['articles'][$key]['p_article_id'] = $pro_info['p_article_id']; } }