From 261487437b10d648571ed4b91fafeaf8433234e5 Mon Sep 17 00:00:00 2001 From: LinusX Date: Wed, 5 Jun 2024 07:55:49 +0800 Subject: [PATCH 01/16] =?UTF-8?q?[update]=20=E6=96=B0=E5=A2=9Estripe?= =?UTF-8?q?=E8=81=9A=E5=90=88=E6=94=AF=E4=BB=98=E6=96=B9=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E9=87=87=E7=94=A8=E5=85=A8=E6=96=B0=E7=9A=84paymentIntents=20A?= =?UTF-8?q?PI=20[fix]=20=E4=BF=AE=E6=94=B9=E6=94=AF=E4=BB=98=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E4=B8=AD=E7=9A=84=E5=B0=8Fbug=20[update]=20=E5=B0=86s?= =?UTF-8?q?tripe-php=E7=89=88=E6=9C=AC=E5=8D=87=E7=BA=A7=E8=87=B3=E6=9C=80?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Payments/BTCPay.php | 5 +- app/Payments/StripeALLInOne.php | 173 ++++++++++++++++++++++++++++++++ composer.json | 2 +- 3 files changed, 176 insertions(+), 4 deletions(-) create mode 100644 app/Payments/StripeALLInOne.php diff --git a/app/Payments/BTCPay.php b/app/Payments/BTCPay.php index f2db1d1..60ca039 100644 --- a/app/Payments/BTCPay.php +++ b/app/Payments/BTCPay.php @@ -76,14 +76,13 @@ class BTCPay //NOT BTCPay-Sig //API doc is WRONG! $headerName = 'Btcpay-Sig'; - $signraturHeader = isset($headers[$headerName]) ? $headers[$headerName] : ''; + $signatureHeader = isset($headers[$headerName]) ? $headers[$headerName] : ''; $json_param = json_decode($payload, true); $computedSignature = "sha256=" . \hash_hmac('sha256', $payload, $this->config['btcpay_webhook_key']); - if (!self::hashEqual($signraturHeader, $computedSignature)) { + if (!self::hashEqual($signatureHeader, $computedSignature)) { throw new ApiException('HMAC signature does not match', 400); - return false; } //get order id store in metadata diff --git a/app/Payments/StripeALLInOne.php b/app/Payments/StripeALLInOne.php new file mode 100644 index 0000000..9543d51 --- /dev/null +++ b/app/Payments/StripeALLInOne.php @@ -0,0 +1,173 @@ +config = $config; + } + + public function form() + { + return [ + 'currency' => [ + 'label' => '货币单位', + 'description' => '请使用符合ISO 4217标准的三位字母,例如GBP', + 'type' => 'input', + ], + 'stripe_sk_live' => [ + 'label' => 'SK_LIVE', + 'description' => '', + 'type' => 'input', + ], + 'stripe_webhook_key' => [ + 'label' => 'WebHook密钥签名', + 'description' => 'whsec_....', + 'type' => 'input', + ], + 'description' => [ + 'label' => '自定义商品介绍', + 'description' => '', + 'type' => 'input', + ], + 'payment_method' => [ + 'label' => '支付方式', + 'description' => '请输入alipay或者wechat_pay', + 'type' => 'input', + ] + ]; + } + + public function pay($order) + { + $currency = $this->config['currency']; + $exchange = $this->exchange('CNY', strtoupper($currency)); + if (!$exchange) { + throw new ApiException(__('Currency conversion has timed out, please try again later')); + } + $stripe = new \Stripe\StripeClient($this->config['stripe_sk_live']); + + + $stripePaymentMethod = $stripe->paymentMethods->create([ + 'type' => $this->config['payment_method'], + ]); + // 准备支付意图的基础参数 + $params = [ + 'amount' => floor($order['total_amount'] * $exchange), + 'currency' => $currency, + 'confirm' => true, + 'payment_method' => $stripePaymentMethod->id, + 'automatic_payment_methods' => ['enabled' => true], + 'statement_descriptor' => 'sub-' . $order['user_id'] . '-' . substr($order['trade_no'], -8), + 'description' => $this->config['description'], + 'metadata' => [ + 'user_id' => $order['user_id'], + 'out_trade_no' => $order['trade_no'], + 'identifier' => '' + ], + 'return_url' => $order['return_url'] + ]; + + // 如果支付方式为 wechat_pay,添加相应的支付方式选项 + if ($this->config['payment_method'] === 'wechat_pay') { + $params['payment_method_options'] = [ + 'wechat_pay' => [ + 'client' => 'web' + ], + ]; + } + //更新支持最新的paymentIntents方法,Sources API将在今年被彻底替 + $stripeIntents = $stripe->paymentIntents->create($params); + + $nextAction = null; + //jump url + $jumpUrl = null; + $actionType = 0; + if (!$stripeIntents['next_action']) { + throw new ApiException(__('Payment gateway request failed')); + }else { + $nextAction = $stripeIntents['next_action']; + } + + switch ($this->config['payment_method']){ + case "alipay": + if (isset($nextAction['alipay_handle_redirect'])){ + $jumpUrl = $nextAction['alipay_handle_redirect']['url']; + $actionType = 1; + }else { + throw new ApiException('unable get alipay redirect url', 500); + } + break; + case "wechat_pay": + if (isset($nextAction['wechat_pay_display_qr_code'])){ + $jumpUrl = $nextAction['wechat_pay_display_qr_code']['data']; + Log::info($jumpUrl); + }else { + throw new ApiException('unable get alipay redirect url', 500); + } + } + return [ + 'type' => $actionType, + 'data' => $jumpUrl + ]; + } + + public function notify($params) + { + try { + \Stripe\Stripe::setApiKey($this->config['stripe_sk_live']); + //Workerman不支持使用php://input, stripe同时要求验证签名的payload不能经过修改,所以使用这个方法 + $payload = $GLOBALS['HTTP_RAW_POST_DATA']; + $headers = getallheaders(); + $headerName = 'Stripe-Signature'; + $signatureHeader = $headers[$headerName] ?? ''; + $event = \Stripe\Webhook::constructEvent( + $payload, + $signatureHeader, + $this->config['stripe_webhook_key'] + ); + + } catch (\UnexpectedValueException $e){ + throw new ApiException('Error parsing payload', 400); + + } + catch (\Stripe\Exception\SignatureVerificationException $e) { + throw new ApiException('signature not match', 400); + } + switch ($event->type) { + case 'payment_intent.succeeded': + $object = $event->data->object; + if ($object->status === 'succeeded') { + if (!isset($object->metadata->out_trade_no)) { + return('order error'); + } + $metaData = $object->metadata; + $tradeNo = $metaData->out_trade_no; + return [ + 'trade_no' => $tradeNo, + 'callback_no' => $object->id + ]; + } + break; + default: + throw new ApiException('event is not support'); + } + return('success'); + } + + private function exchange($from, $to) + { + $from = strtolower($from); + $to = strtolower($to); + $result = file_get_contents("https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/" . $from . ".min.json"); + $result = json_decode($result, true); + return $result[$from][$to]; + } +} diff --git a/composer.json b/composer.json index bfccc63..70c2c94 100755 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "paragonie/sodium_compat": "^1.20", "php-curl-class/php-curl-class": "^8.6", "spatie/db-dumper": "^3.4", - "stripe/stripe-php": "^7.36.1", + "stripe/stripe-php": "^v14.9.0", "symfony/http-client": "^6.4", "symfony/mailgun-mailer": "^6.4", "symfony/yaml": "*", From 9270d94668ac9146ee9e26e0a2abd817c768d2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E5=A4=A7=E7=99=BD?= Date: Thu, 13 Jun 2024 18:40:40 +0800 Subject: [PATCH 02/16] Update StripeALLInOne.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复部分报错语句不规范 --- app/Payments/StripeALLInOne.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Payments/StripeALLInOne.php b/app/Payments/StripeALLInOne.php index 9543d51..d7aa413 100644 --- a/app/Payments/StripeALLInOne.php +++ b/app/Payments/StripeALLInOne.php @@ -102,7 +102,7 @@ class StripeALLInOne { $jumpUrl = $nextAction['alipay_handle_redirect']['url']; $actionType = 1; }else { - throw new ApiException('unable get alipay redirect url', 500); + throw new ApiException('unable get Alipay redirect url', 500); } break; case "wechat_pay": @@ -110,7 +110,7 @@ class StripeALLInOne { $jumpUrl = $nextAction['wechat_pay_display_qr_code']['data']; Log::info($jumpUrl); }else { - throw new ApiException('unable get alipay redirect url', 500); + throw new ApiException('unable get WeChat Pay redirect url', 500); } } return [ From fc283af60f526a8229e2c78b19f8814bc7f56d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E5=A4=A7=E7=99=BD?= Date: Thu, 13 Jun 2024 18:47:04 +0800 Subject: [PATCH 03/16] Update StripeALLInOne.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 删除调试冗余代码 --- app/Payments/StripeALLInOne.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/Payments/StripeALLInOne.php b/app/Payments/StripeALLInOne.php index d7aa413..b997c81 100644 --- a/app/Payments/StripeALLInOne.php +++ b/app/Payments/StripeALLInOne.php @@ -4,9 +4,7 @@ * 自己写别抄,抄NMB抄 */ namespace App\Payments; - use App\Exceptions\ApiException; -use Illuminate\Support\Facades\Log; class StripeALLInOne { public function __construct($config) @@ -108,7 +106,6 @@ class StripeALLInOne { case "wechat_pay": if (isset($nextAction['wechat_pay_display_qr_code'])){ $jumpUrl = $nextAction['wechat_pay_display_qr_code']['data']; - Log::info($jumpUrl); }else { throw new ApiException('unable get WeChat Pay redirect url', 500); } From 338aad7f6cfa6d01a2d2bfd7f68e963455ba1a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E5=A4=A7=E7=99=BD?= Date: Thu, 13 Jun 2024 23:25:23 +0800 Subject: [PATCH 04/16] Fix PaymentController.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复由Jun 8, 2024提交的2个commit产生的报错 --- app/Http/Controllers/V1/Guest/PaymentController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/V1/Guest/PaymentController.php b/app/Http/Controllers/V1/Guest/PaymentController.php index 07a8bb0..a917806 100644 --- a/app/Http/Controllers/V1/Guest/PaymentController.php +++ b/app/Http/Controllers/V1/Guest/PaymentController.php @@ -9,6 +9,7 @@ use App\Services\OrderService; use App\Services\PaymentService; use App\Services\TelegramService; use Illuminate\Http\Request; +use App\Models\Payment; class PaymentController extends Controller { From bab7ed8e97e78986989479c568244b08878bd6e7 Mon Sep 17 00:00:00 2001 From: LinusX Date: Sat, 15 Jun 2024 01:42:43 +0800 Subject: [PATCH 05/16] =?UTF-8?q?[fix]=20=E4=BF=AE=E5=A4=8Dcatch=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=E5=8F=98=E9=87=8F=E5=8F=AF=E8=83=BDundefined?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/BackupDatabase.php | 5 +++-- app/Payments/StripeALLInOne.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/BackupDatabase.php b/app/Console/Commands/BackupDatabase.php index 22a3c3c..377a6e6 100644 --- a/app/Console/Commands/BackupDatabase.php +++ b/app/Console/Commands/BackupDatabase.php @@ -26,9 +26,10 @@ class BackupDatabase extends Command } // 数据库备份逻辑 + $databaseBackupPath = storage_path('backup/' . now()->format('Y-m-d_H-i-s') . '_' . config('database.connections.mysql.database') . '_database_backup.sql'); + $compressedBackupPath = $databaseBackupPath . '.gz'; try{ if (config('database.default') === 'mysql'){ - $databaseBackupPath = storage_path('backup/' . now()->format('Y-m-d_H-i-s') . '_' . config('database.connections.mysql.database') . '_database_backup.sql'); $this->info("1️⃣:开始备份Mysql"); \Spatie\DbDumper\Databases\MySql::create() ->setHost(config('database.connections.mysql.host')) @@ -83,7 +84,7 @@ class BackupDatabase extends Command $bucket->upload(fopen($compressedBackupPath, 'r'), [ 'name' => $objectName, ]); - + // 输出文件链接 \Log::channel('backup')->info("🎉:数据库备份已上传到 Google Cloud Storage: $objectName"); $this->info("🎉:数据库备份已上传到 Google Cloud Storage: $objectName"); diff --git a/app/Payments/StripeALLInOne.php b/app/Payments/StripeALLInOne.php index b997c81..2847beb 100644 --- a/app/Payments/StripeALLInOne.php +++ b/app/Payments/StripeALLInOne.php @@ -48,7 +48,7 @@ class StripeALLInOne { $currency = $this->config['currency']; $exchange = $this->exchange('CNY', strtoupper($currency)); if (!$exchange) { - throw new ApiException(__('Currency conversion has timed out, please try again later')); + throw new ApiException('Currency conversion has timed out, please try again later', 500); } $stripe = new \Stripe\StripeClient($this->config['stripe_sk_live']); From 8cc247b65354ea18947ebca01e192d0b6b58f634 Mon Sep 17 00:00:00 2001 From: LinusX Date: Sat, 15 Jun 2024 02:16:54 +0800 Subject: [PATCH 06/16] =?UTF-8?q?[feat]=20=E6=96=B0=E5=A2=9Etelegram?= =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA/start=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Plugins/Telegram/Commands/GetLatestUrl.php | 2 +- app/Plugins/Telegram/Commands/Start.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 app/Plugins/Telegram/Commands/Start.php diff --git a/app/Plugins/Telegram/Commands/GetLatestUrl.php b/app/Plugins/Telegram/Commands/GetLatestUrl.php index 0d34b77..44afdfb 100644 --- a/app/Plugins/Telegram/Commands/GetLatestUrl.php +++ b/app/Plugins/Telegram/Commands/GetLatestUrl.php @@ -7,7 +7,7 @@ use App\Plugins\Telegram\Telegram; class GetLatestUrl extends Telegram { public $command = '/getlatesturl'; - public $description = '将Telegram账号绑定到网站'; + public $description = '获取网站最新网址'; public function handle($message, $match = []) { $telegramService = $this->telegramService; diff --git a/app/Plugins/Telegram/Commands/Start.php b/app/Plugins/Telegram/Commands/Start.php new file mode 100644 index 0000000..add3db0 --- /dev/null +++ b/app/Plugins/Telegram/Commands/Start.php @@ -0,0 +1,17 @@ +is_private) return; + $telegramService = $this->telegramService; + $text = "/start 显示所有可用指令\n /bind+空格+订阅链接,将telegram绑定至账户\n /traffic 获取当前使用流量 \n /getlatesturl 获取网站最新网址 \n /unbind 解绑telegram账户"; + $telegramService->sendMessage($message->chat_id, $text, 'markdown'); + } +} From f0c620cbc219534f05a6e4dbc6967206cbcb7d09 Mon Sep 17 00:00:00 2001 From: LinusX Date: Mon, 17 Jun 2024 22:58:53 +0800 Subject: [PATCH 07/16] =?UTF-8?q?[fix]=20=E5=88=A0=E9=99=A4=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=8C=85=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/V1/Guest/PaymentController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Http/Controllers/V1/Guest/PaymentController.php b/app/Http/Controllers/V1/Guest/PaymentController.php index 8ff1186..0f11867 100644 --- a/app/Http/Controllers/V1/Guest/PaymentController.php +++ b/app/Http/Controllers/V1/Guest/PaymentController.php @@ -10,7 +10,6 @@ use App\Services\OrderService; use App\Services\PaymentService; use App\Services\TelegramService; use Illuminate\Http\Request; -use App\Models\Payment; class PaymentController extends Controller { @@ -58,7 +57,7 @@ class PaymentController extends Controller $payment->name, $order->trade_no ); - + $telegramService->sendMessageWithAdmin($message); return true; } From acb40cc1f9de13d1816baa8bc034ba4e52068be7 Mon Sep 17 00:00:00 2001 From: LinusX Date: Tue, 2 Jul 2024 19:02:29 +0800 Subject: [PATCH 08/16] =?UTF-8?q?[update]=20=E6=96=B0=E5=A2=9Ecredit=20car?= =?UTF-8?q?d=E8=B7=B3=E8=BD=AC=E8=87=B3checkout=E9=A1=B5=E9=9D=A2=E4=BB=98?= =?UTF-8?q?=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Payments/StripeALLInOne.php | 154 ++++++++++++++++++++------------ 1 file changed, 97 insertions(+), 57 deletions(-) diff --git a/app/Payments/StripeALLInOne.php b/app/Payments/StripeALLInOne.php index 2847beb..9c7e003 100644 --- a/app/Payments/StripeALLInOne.php +++ b/app/Payments/StripeALLInOne.php @@ -37,7 +37,7 @@ class StripeALLInOne { ], 'payment_method' => [ 'label' => '支付方式', - 'description' => '请输入alipay或者wechat_pay', + 'description' => '请输入alipay, wechat_pay, cards', 'type' => 'input', ] ]; @@ -50,66 +50,91 @@ class StripeALLInOne { if (!$exchange) { throw new ApiException('Currency conversion has timed out, please try again later', 500); } - $stripe = new \Stripe\StripeClient($this->config['stripe_sk_live']); - - - $stripePaymentMethod = $stripe->paymentMethods->create([ - 'type' => $this->config['payment_method'], - ]); - // 准备支付意图的基础参数 - $params = [ - 'amount' => floor($order['total_amount'] * $exchange), - 'currency' => $currency, - 'confirm' => true, - 'payment_method' => $stripePaymentMethod->id, - 'automatic_payment_methods' => ['enabled' => true], - 'statement_descriptor' => 'sub-' . $order['user_id'] . '-' . substr($order['trade_no'], -8), - 'description' => $this->config['description'], - 'metadata' => [ - 'user_id' => $order['user_id'], - 'out_trade_no' => $order['trade_no'], - 'identifier' => '' - ], - 'return_url' => $order['return_url'] - ]; - - // 如果支付方式为 wechat_pay,添加相应的支付方式选项 - if ($this->config['payment_method'] === 'wechat_pay') { - $params['payment_method_options'] = [ - 'wechat_pay' => [ - 'client' => 'web' - ], - ]; - } - //更新支持最新的paymentIntents方法,Sources API将在今年被彻底替 - $stripeIntents = $stripe->paymentIntents->create($params); - - $nextAction = null; //jump url $jumpUrl = null; $actionType = 0; - if (!$stripeIntents['next_action']) { - throw new ApiException(__('Payment gateway request failed')); - }else { - $nextAction = $stripeIntents['next_action']; + $stripe = new \Stripe\StripeClient($this->config['stripe_sk_live']); + + if ($this->config['payment_method'] != "cards"){ + $stripePaymentMethod = $stripe->paymentMethods->create([ + 'type' => $this->config['payment_method'], + ]); + // 准备支付意图的基础参数 + $params = [ + 'amount' => floor($order['total_amount'] * $exchange), + 'currency' => $currency, + 'confirm' => true, + 'payment_method' => $stripePaymentMethod->id, + 'automatic_payment_methods' => ['enabled' => true], + 'statement_descriptor' => 'sub-' . $order['user_id'] . '-' . substr($order['trade_no'], -8), + 'description' => $this->config['description'], + 'metadata' => [ + 'user_id' => $order['user_id'], + 'out_trade_no' => $order['trade_no'], + 'identifier' => '' + ], + 'return_url' => $order['return_url'] + ]; + + // 如果支付方式为 wechat_pay,添加相应的支付方式选项 + if ($this->config['payment_method'] === 'wechat_pay') { + $params['payment_method_options'] = [ + 'wechat_pay' => [ + 'client' => 'web' + ], + ]; + } + //更新支持最新的paymentIntents方法,Sources API将在今年被彻底替 + $stripeIntents = $stripe->paymentIntents->create($params); + + $nextAction = null; + + if (!$stripeIntents['next_action']) { + throw new ApiException(__('Payment gateway request failed')); + }else { + $nextAction = $stripeIntents['next_action']; + } + + switch ($this->config['payment_method']){ + case "alipay": + if (isset($nextAction['alipay_handle_redirect'])){ + $jumpUrl = $nextAction['alipay_handle_redirect']['url']; + $actionType = 1; + }else { + throw new ApiException('unable get Alipay redirect url', 500); + } + break; + case "wechat_pay": + if (isset($nextAction['wechat_pay_display_qr_code'])){ + $jumpUrl = $nextAction['wechat_pay_display_qr_code']['data']; + }else { + throw new ApiException('unable get WeChat Pay redirect url', 500); + } + } + } else { + $creditCheckOut = $stripe->checkout->sessions->create([ + 'success_url' => $order['return_url'], + 'client_reference_id' => $order['trade_no'], + 'payment_method_types' => ['card'], + 'line_items' => [ + [ + 'price_data' => [ + 'currency' => $currency, + 'unit_amount' => floor($order['total_amount'] * $exchange), + 'product_data' => [ + 'name' => 'sub-' . $order['user_id'] . '-' . substr($order['trade_no'], -8), + 'description' => $this->config['description'], + ] + ], + 'quantity' => 1, + ], + ], + 'mode' => 'payment', + ]); + $jumpUrl = $creditCheckOut['url']; + $actionType = 1; } - switch ($this->config['payment_method']){ - case "alipay": - if (isset($nextAction['alipay_handle_redirect'])){ - $jumpUrl = $nextAction['alipay_handle_redirect']['url']; - $actionType = 1; - }else { - throw new ApiException('unable get Alipay redirect url', 500); - } - break; - case "wechat_pay": - if (isset($nextAction['wechat_pay_display_qr_code'])){ - $jumpUrl = $nextAction['wechat_pay_display_qr_code']['data']; - }else { - throw new ApiException('unable get WeChat Pay redirect url', 500); - } - } return [ 'type' => $actionType, 'data' => $jumpUrl @@ -133,7 +158,6 @@ class StripeALLInOne { } catch (\UnexpectedValueException $e){ throw new ApiException('Error parsing payload', 400); - } catch (\Stripe\Exception\SignatureVerificationException $e) { throw new ApiException('signature not match', 400); @@ -153,6 +177,22 @@ class StripeALLInOne { ]; } break; + case 'checkout.session.completed': + $object = $event->data->object; + if ($object->payment_status === 'paid') { + return [ + 'trade_no' => $object->client_reference_id, + 'callback_no' => $object->payment_intent + ]; + } + break; + case 'checkout.session.async_payment_succeeded': + $object = $event->data->object; + return [ + 'trade_no' => $object->client_reference_id, + 'callback_no' => $object->payment_intent + ]; + break; default: throw new ApiException('event is not support'); } From 6cfdd1c9b1b0ef0b0ce3264d99cd046e04f3eca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E5=A4=A7=E7=99=BD?= Date: Fri, 18 Oct 2024 12:42:51 -0400 Subject: [PATCH 09/16] Update Surge.php support surge ss2022 --- app/Protocols/Surge.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Protocols/Surge.php b/app/Protocols/Surge.php index 4e09b82..ab2dc54 100644 --- a/app/Protocols/Surge.php +++ b/app/Protocols/Surge.php @@ -32,7 +32,9 @@ class Surge 'aes-128-gcm', 'aes-192-gcm', 'aes-256-gcm', - 'chacha20-ietf-poly1305' + 'chacha20-ietf-poly1305', + '2022-blake3-aes-128-gcm', + '2022-blake3-aes-256-gcm', ]) ) { // [Proxy] From c4595bc6652d9f05543fa1f00149b24a60e86df7 Mon Sep 17 00:00:00 2001 From: Linus Xiong Date: Sun, 8 Dec 2024 00:53:43 -0500 Subject: [PATCH 10/16] use docker env on .env file --- .env.example | 69 +++++++++++++++++++++++++--------------------------- Dockerfile | 27 +++++++++++++------- 2 files changed, 51 insertions(+), 45 deletions(-) mode change 100755 => 100644 .env.example diff --git a/.env.example b/.env.example old mode 100755 new mode 100644 index 2bffe56..6211636 --- a/.env.example +++ b/.env.example @@ -1,43 +1,40 @@ -APP_NAME=XBoard -APP_ENV=local -APP_KEY=base64:PZXk5vTuTinfeEVG5FpYv2l6WEhLsyvGpiWK7IgJJ60= -APP_DEBUG=false -APP_URL=http://localhost +APP_NAME=${APP_NAME:-XBoard} +APP_ENV=${APP_ENV:-local} +APP_KEY=${APP_KEY:-base64:PZXk5vTuTinfeEVG5FpYv2l6WEhLsyvGpiWK7IgJJ60=} +APP_DEBUG=${APP_DEBUG:-false} +APP_URL=${APP_URL:-http://localhost} +ADMIN_SETTING_CACHE=${ADMIN_SETTING_CACHE:-60} +LOG_CHANNEL=${LOG_CHANNEL:-stack} -ADMIN_SETTING_CACHE=60 #设置缓存时间(单位秒) -LOG_CHANNEL=stack +DB_CONNECTION=${DB_CONNECTION:-mysql} +DB_HOST=${DB_HOST:-127.0.0.1} +DB_PORT=${DB_PORT:-3306} +DB_DATABASE=${DB_DATABASE:-xboard} +DB_USERNAME=${DB_USERNAME:-root} +DB_PASSWORD=${DB_PASSWORD:-} -DB_CONNECTION=mysql -DB_HOST=127.0.0.1 -DB_PORT=3306 -DB_DATABASE=xboard -DB_USERNAME=root -DB_PASSWORD= +REDIS_HOST=${REDIS_HOST:-127.0.0.1} +REDIS_PASSWORD=${REDIS_PASSWORD:-null} +REDIS_PORT=${REDIS_PORT:-6379} -REDIS_HOST=127.0.0.1 -REDIS_PASSWORD=null -REDIS_PORT=6379 +BROADCAST_DRIVER=${BROADCAST_DRIVER:-log} +CACHE_DRIVER=${CACHE_DRIVER:-redis} +QUEUE_CONNECTION=${QUEUE_CONNECTION:-redis} -#默认将队列驱动和缓存驱动都修改为了redis,请务必安装redis -BROADCAST_DRIVER=log -CACHE_DRIVER=redis -QUEUE_CONNECTION=redis +MAIL_DRIVER=${MAIL_DRIVER:-smtp} +MAIL_HOST=${MAIL_HOST:-smtp.mailtrap.io} +MAIL_PORT=${MAIL_PORT:-2525} +MAIL_USERNAME=${MAIL_USERNAME:-null} +MAIL_PASSWORD=${MAIL_PASSWORD:-null} +MAIL_ENCRYPTION=${MAIL_ENCRYPTION:-null} +MAIL_FROM_ADDRESS=${MAIL_FROM_ADDRESS:-null} +MAIL_FROM_NAME=${MAIL_FROM_NAME:-null} -MAIL_DRIVER=smtp -MAIL_HOST=smtp.mailtrap.io -MAIL_PORT=2525 -MAIL_USERNAME=null -MAIL_PASSWORD=null -MAIL_ENCRYPTION=null -MAIL_FROM_ADDRESS=null -MAIL_FROM_NAME=null -MAILGUN_DOMAIN= -MAILGUN_SECRET= +MAILGUN_DOMAIN=${MAILGUN_DOMAIN:-} +MAILGUN_SECRET=${MAILGUN_SECRET:-} -# google cloud stoage -ENABLE_AUTO_BACKUP_AND_UPDATE=false -GOOGLE_CLOUD_KEY_FILE=config/googleCloudStorageKey.json -GOOGLE_CLOUD_STORAGE_BUCKET= +ENABLE_AUTO_BACKUP_AND_UPDATE=${ENABLE_AUTO_BACKUP_AND_UPDATE:-false} +GOOGLE_CLOUD_KEY_FILE=${GOOGLE_CLOUD_KEY_FILE:-config/googleCloudStorageKey.json} +GOOGLE_CLOUD_STORAGE_BUCKET=${GOOGLE_CLOUD_STORAGE_BUCKET:-} -# 用于阻止重复安装 -INSTALLED=false \ No newline at end of file +INSTALLED=${INSTALLED:-false} diff --git a/Dockerfile b/Dockerfile index 3ce274a..17c777f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,16 +2,25 @@ FROM phpswoole/swoole:php8.1-alpine COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ -RUN install-php-extensions pcntl bcmath inotify \ -&& apk --no-cache add shadow supervisor nginx sqlite nginx-mod-http-brotli mysql-client git patch \ -&& addgroup -S -g 1000 www && adduser -S -G www -u 1000 www -#复制项目文件以及配置文件 +# 安装基础软件包,包括 gettext (提供 envsubst) +RUN install-php-extensions pcntl bcmath inotify \ + && apk --no-cache add shadow supervisor nginx sqlite nginx-mod-http-brotli mysql-client git patch gettext \ + && addgroup -S -g 1000 www && adduser -S -G www -u 1000 www + +# 设置工作目录 WORKDIR /www + +# 复制项目文件和配置文件 COPY .docker / COPY . /www -RUN composer install --optimize-autoloader --no-cache --no-dev \ -&& php artisan storage:link \ -&& chown -R www:www /www \ -&& chmod -R 775 /www +COPY .env.example /www/.env.example -CMD /usr/bin/supervisord --nodaemon -c /etc/supervisor/supervisord.conf \ No newline at end of file +# 生成环境变量文件并安装依赖 +RUN envsubst < /www/.env.template > /www/.env \ + && composer install --optimize-autoloader --no-cache --no-dev \ + && php artisan storage:link \ + && chown -R www:www /www \ + && chmod -R 775 /www + +# 启动 supervisor +CMD /usr/bin/supervisord --nodaemon -c /etc/supervisor/supervisord.conf From 1378fdb45bfcbd1d6fd14f06c2bbbe7237e834df Mon Sep 17 00:00:00 2001 From: Linus Xiong Date: Sun, 8 Dec 2024 00:58:58 -0500 Subject: [PATCH 11/16] fix bugs --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 17c777f..0e88d06 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ COPY . /www COPY .env.example /www/.env.example # 生成环境变量文件并安装依赖 -RUN envsubst < /www/.env.template > /www/.env \ +RUN envsubst < /www/.env.example > /www/.env \ && composer install --optimize-autoloader --no-cache --no-dev \ && php artisan storage:link \ && chown -R www:www /www \ From cfc8a05cbae238cd509efa644c9fd73acd8df3f5 Mon Sep 17 00:00:00 2001 From: Linus Xiong Date: Sun, 8 Dec 2024 01:05:38 -0500 Subject: [PATCH 12/16] fix bugs --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0e88d06..a09f9d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,6 @@ WORKDIR /www # 复制项目文件和配置文件 COPY .docker / COPY . /www -COPY .env.example /www/.env.example # 生成环境变量文件并安装依赖 RUN envsubst < /www/.env.example > /www/.env \ From dee7525bb42fea0ec16b794720094feea9cbafff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E5=A4=A7=E7=99=BD?= Date: Sun, 8 Dec 2024 01:10:00 -0500 Subject: [PATCH 13/16] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a09f9d4..d520265 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,6 @@ FROM phpswoole/swoole:php8.1-alpine COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ -# 安装基础软件包,包括 gettext (提供 envsubst) RUN install-php-extensions pcntl bcmath inotify \ && apk --no-cache add shadow supervisor nginx sqlite nginx-mod-http-brotli mysql-client git patch gettext \ && addgroup -S -g 1000 www && adduser -S -G www -u 1000 www @@ -12,6 +11,7 @@ WORKDIR /www # 复制项目文件和配置文件 COPY .docker / +COPY .env.example /www/.env.example COPY . /www # 生成环境变量文件并安装依赖 From 22ffe0dacef22adf70dc61b73f7a2f8fcd70d2ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E5=A4=A7=E7=99=BD?= Date: Sun, 8 Dec 2024 01:38:27 -0500 Subject: [PATCH 14/16] Update Dockerfile --- Dockerfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index d520265..ea86f2b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM phpswoole/swoole:php8.1-alpine COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ RUN install-php-extensions pcntl bcmath inotify \ - && apk --no-cache add shadow supervisor nginx sqlite nginx-mod-http-brotli mysql-client git patch gettext \ + && apk --no-cache add shadow supervisor nginx sqlite nginx-mod-http-brotli mysql-client git patch \ && addgroup -S -g 1000 www && adduser -S -G www -u 1000 www # 设置工作目录 @@ -11,15 +11,14 @@ WORKDIR /www # 复制项目文件和配置文件 COPY .docker / -COPY .env.example /www/.env.example COPY . /www # 生成环境变量文件并安装依赖 -RUN envsubst < /www/.env.example > /www/.env \ +RUN cp /www/.env.example /www/.env \ && composer install --optimize-autoloader --no-cache --no-dev \ && php artisan storage:link \ && chown -R www:www /www \ && chmod -R 775 /www # 启动 supervisor -CMD /usr/bin/supervisord --nodaemon -c /etc/supervisor/supervisord.conf +CMD ["/usr/bin/supervisord", "--nodaemon", "-c", "/etc/supervisor/supervisord.conf"] From aa3ff5cb663e9400a3952adee120370293eaffee Mon Sep 17 00:00:00 2001 From: Linus Xiong Date: Sun, 8 Dec 2024 01:48:49 -0500 Subject: [PATCH 15/16] fix bug --- .env.example | 69 +++++++++++++++++++++++++++------------------------- Dockerfile | 24 +++++++----------- 2 files changed, 45 insertions(+), 48 deletions(-) diff --git a/.env.example b/.env.example index 6211636..93f2d35 100644 --- a/.env.example +++ b/.env.example @@ -1,40 +1,43 @@ -APP_NAME=${APP_NAME:-XBoard} -APP_ENV=${APP_ENV:-local} -APP_KEY=${APP_KEY:-base64:PZXk5vTuTinfeEVG5FpYv2l6WEhLsyvGpiWK7IgJJ60=} -APP_DEBUG=${APP_DEBUG:-false} -APP_URL=${APP_URL:-http://localhost} -ADMIN_SETTING_CACHE=${ADMIN_SETTING_CACHE:-60} -LOG_CHANNEL=${LOG_CHANNEL:-stack} +APP_NAME=XBoard +APP_ENV=local +APP_KEY=base64:PZXk5vTuTinfeEVG5FpYv2l6WEhLsyvGpiWK7IgJJ60= +APP_DEBUG=false +APP_URL=http://localhost -DB_CONNECTION=${DB_CONNECTION:-mysql} -DB_HOST=${DB_HOST:-127.0.0.1} -DB_PORT=${DB_PORT:-3306} -DB_DATABASE=${DB_DATABASE:-xboard} -DB_USERNAME=${DB_USERNAME:-root} -DB_PASSWORD=${DB_PASSWORD:-} +ADMIN_SETTING_CACHE=60 #设置缓存时间(单位秒) +LOG_CHANNEL=stack -REDIS_HOST=${REDIS_HOST:-127.0.0.1} -REDIS_PASSWORD=${REDIS_PASSWORD:-null} -REDIS_PORT=${REDIS_PORT:-6379} +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=xboard +DB_USERNAME=root +DB_PASSWORD= -BROADCAST_DRIVER=${BROADCAST_DRIVER:-log} -CACHE_DRIVER=${CACHE_DRIVER:-redis} -QUEUE_CONNECTION=${QUEUE_CONNECTION:-redis} +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 -MAIL_DRIVER=${MAIL_DRIVER:-smtp} -MAIL_HOST=${MAIL_HOST:-smtp.mailtrap.io} -MAIL_PORT=${MAIL_PORT:-2525} -MAIL_USERNAME=${MAIL_USERNAME:-null} -MAIL_PASSWORD=${MAIL_PASSWORD:-null} -MAIL_ENCRYPTION=${MAIL_ENCRYPTION:-null} -MAIL_FROM_ADDRESS=${MAIL_FROM_ADDRESS:-null} -MAIL_FROM_NAME=${MAIL_FROM_NAME:-null} +#默认将队列驱动和缓存驱动都修改为了redis,请务必安装redis +BROADCAST_DRIVER=log +CACHE_DRIVER=redis +QUEUE_CONNECTION=redis -MAILGUN_DOMAIN=${MAILGUN_DOMAIN:-} -MAILGUN_SECRET=${MAILGUN_SECRET:-} +MAIL_DRIVER=smtp +MAIL_HOST=smtp.mailtrap.io +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null +MAIL_FROM_ADDRESS=null +MAIL_FROM_NAME=null +MAILGUN_DOMAIN= +MAILGUN_SECRET= -ENABLE_AUTO_BACKUP_AND_UPDATE=${ENABLE_AUTO_BACKUP_AND_UPDATE:-false} -GOOGLE_CLOUD_KEY_FILE=${GOOGLE_CLOUD_KEY_FILE:-config/googleCloudStorageKey.json} -GOOGLE_CLOUD_STORAGE_BUCKET=${GOOGLE_CLOUD_STORAGE_BUCKET:-} +# google cloud stoage +ENABLE_AUTO_BACKUP_AND_UPDATE=false +GOOGLE_CLOUD_KEY_FILE=config/googleCloudStorageKey.json +GOOGLE_CLOUD_STORAGE_BUCKET= -INSTALLED=${INSTALLED:-false} +# 用于阻止重复安装 +INSTALLED=false diff --git a/Dockerfile b/Dockerfile index ea86f2b..f0102c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,23 +2,17 @@ FROM phpswoole/swoole:php8.1-alpine COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ -RUN install-php-extensions pcntl bcmath inotify \ - && apk --no-cache add shadow supervisor nginx sqlite nginx-mod-http-brotli mysql-client git patch \ - && addgroup -S -g 1000 www && adduser -S -G www -u 1000 www - -# 设置工作目录 +RUN install-php-extensions pcntl bcmath inotify \ +&& apk --no-cache add shadow supervisor nginx sqlite nginx-mod-http-brotli mysql-client git patch \ +&& addgroup -S -g 1000 www && adduser -S -G www -u 1000 www +#复制项目文件以及配置文件 WORKDIR /www - -# 复制项目文件和配置文件 COPY .docker / COPY . /www +RUN composer install --optimize-autoloader --no-cache --no-dev \ +&& php artisan storage:link \ +&& cp /www/.env.example /www/.env \ +&& chown -R www:www /www \ +&& chmod -R 775 /www -# 生成环境变量文件并安装依赖 -RUN cp /www/.env.example /www/.env \ - && composer install --optimize-autoloader --no-cache --no-dev \ - && php artisan storage:link \ - && chown -R www:www /www \ - && chmod -R 775 /www - -# 启动 supervisor CMD ["/usr/bin/supervisord", "--nodaemon", "-c", "/etc/supervisor/supervisord.conf"] From 654f1f84fb455b12700885058fa11afd222e6515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E5=A4=A7=E7=99=BD?= Date: Sun, 8 Dec 2024 04:58:38 -0500 Subject: [PATCH 16/16] Update supervisord.conf --- .docker/etc/supervisor/supervisord.conf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.docker/etc/supervisor/supervisord.conf b/.docker/etc/supervisor/supervisord.conf index 018e54b..8919bd4 100644 --- a/.docker/etc/supervisor/supervisord.conf +++ b/.docker/etc/supervisor/supervisord.conf @@ -17,6 +17,7 @@ directory=/www command=sh -c "chown -R www:www /www && chmod -R 775 /www" autostart=true autorestart=false +priority=1 stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr @@ -25,6 +26,7 @@ stderr_logfile_maxbytes=0 [program:nginx] command=nginx -g 'daemon off;' user=root +priority=5 stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr @@ -36,6 +38,7 @@ startretries=10 [program:cron] command=crond -f -l 8 user=root +priority=4 stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr @@ -62,6 +65,8 @@ command=php -c php.ini webman.php start directory=/www user=www numprocs=1 +priority=2 +startsecs=3 stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr @@ -74,6 +79,7 @@ startretries=10 command=php artisan horizon directory=/www user=www +priority=3 stdout_logfile=/www/storage/logs/queue.log stdout_logfile_maxbytes=0 stderr_logfile=/www/storage/logs/queue_error.log