浏览代码

Fixed Bugs

BrettonYe 2 年之前
父节点
当前提交
bca9be70a3

+ 1 - 1
app/Channels/iYuuChannel.php

@@ -9,7 +9,7 @@ use Log;
 
 class iYuuChannel
 {
-    private $token;
+    private ?string $token;
 
     public function __construct()
     {

+ 1 - 1
app/Console/Kernel.php

@@ -16,7 +16,7 @@ class Kernel extends ConsoleKernel
         $schedule->command('nodeStatusDetection')->everyTenMinutes();
         $schedule->command('autoClearLogs')->everyThirtyMinutes();
         $schedule->command('task:hourly')->hourly();
-        $schedule->command('task:daily')->dailyAt('02:30');
+        $schedule->command('task:daily')->dailyAt('00:05');
         $schedule->command('dailyNodeReport')->dailyAt('09:30');
         $schedule->command('userTrafficWarning')->dailyAt('10:30');
         $schedule->command('userExpireWarning')->dailyAt('20:30');

+ 1 - 0
app/Helpers/ClientConfig.php

@@ -37,6 +37,7 @@ trait ClientConfig
         if (str_contains($target, 'v2rayn') || str_contains($target, 'v2rayng') || str_contains($target, 'v2rayu')) {
             return $this->v2rayN();
         }
+
         //        if (str_contains($target, 'shadowsocks')) {
         //            exit($this->shaodowsocksSIP008());
         //        }

+ 0 - 2
app/Http/Controllers/Api/Client/AuthController.php

@@ -18,8 +18,6 @@ class AuthController extends Controller
 {
     use ClientApiResponse;
 
-    private static $method;
-
     public function __construct(Request $request)
     {
         if (str_contains($request->userAgent(), 'bob_vpn')) {

+ 0 - 2
app/Http/Controllers/Api/Client/ClientController.php

@@ -26,8 +26,6 @@ class ClientController extends Controller
 {
     use ClientApiResponse;
 
-    private static $method;
-
     public function __construct(Request $request)
     {
         if (str_contains($request->userAgent(), 'bob_vpn')) {

+ 1 - 1
app/Http/Controllers/AuthController.php

@@ -326,7 +326,7 @@ class AuthController extends Controller
         return false;
     }
 
-    private function getAff(?string $code, ?int $aff): array
+    private function getAff(?string $code, string|int|null $aff): array
     { // 获取AFF
         $data = ['inviter_id' => null, 'code_id' => 0]; // 邀请人ID 与 邀请码ID
 

+ 1 - 1
app/Http/Controllers/PaymentController.php

@@ -33,7 +33,7 @@ class PaymentController extends Controller
     {
         self::$method = $request->query('method') ?: $request->input('method');
 
-        Log::notice(self::$method.'回调接口:'.self::$method.var_export($request->all(), true));
+        Log::notice('[{method}] 回调接口:{body}', ['method' => self::$method, 'body' => var_export($request->all(), true)]);
 
         return self::getClient()->notify($request);
     }

+ 0 - 1
app/Http/Middleware/Permission.php

@@ -12,7 +12,6 @@ class Permission
      * Handle an incoming request.
      *
      * @param  Request  $request
-     * @param  null  $guard
      * @return mixed
      */
     public function handle($request, Closure $next, $guard = null)

+ 1 - 1
app/Http/Middleware/isForbidden.php

@@ -17,7 +17,7 @@ class isForbidden
      * @return mixed
      */
     public function handle(Request $request, Closure $next)
-    {
+    { // 限制机器人、指定IP访问.
         // 拒绝机器人访问
         if (sysConfig('is_forbid_robot') && Agent::isRobot()) {
             Log::warning('识别到机器人('.IP::getClientIp().')访问');

+ 8 - 2
app/Jobs/VNet/addUser.php

@@ -2,6 +2,7 @@
 
 namespace App\Jobs\VNet;
 
+use App\Models\Node;
 use App\Models\User;
 use Arr;
 use Exception;
@@ -26,9 +27,14 @@ class addUser implements ShouldQueue
 
     private Collection $nodes;
 
-    public function __construct(array $userIds, Collection $nodes)
+    public function __construct(array|int $userIds, Collection|Node $nodes)
     {
-        $this->nodes = $nodes;
+        if ($nodes instanceof Collection) {
+            $this->nodes = $nodes;
+        } else {
+            $this->nodes = new Collection([$nodes]);
+        }
+
         foreach (User::findMany($userIds) as $user) {
             $this->data[] = [
                 'uid' => $user->id,

+ 7 - 5
app/Jobs/VNet/delUser.php

@@ -2,6 +2,7 @@
 
 namespace App\Jobs\VNet;
 
+use App\Models\Node;
 use Arr;
 use Exception;
 use Http;
@@ -21,14 +22,15 @@ class delUser implements ShouldQueue
     use Queueable;
     use SerializesModels;
 
-    private array|int $userIds;
-
     private Collection $nodes;
 
-    public function __construct(array|int $userIds, Collection $nodes)
+    public function __construct(private readonly array|int $userIds, Collection|Node $nodes)
     {
-        $this->userIds = $userIds;
-        $this->nodes = $nodes;
+        if ($nodes instanceof Collection) {
+            $this->nodes = $nodes;
+        } else {
+            $this->nodes = new Collection([$nodes]);
+        }
     }
 
     public function handle(): void

+ 8 - 2
app/Jobs/VNet/editUser.php

@@ -2,6 +2,7 @@
 
 namespace App\Jobs\VNet;
 
+use App\Models\Node;
 use App\Models\User;
 use Arr;
 use Exception;
@@ -26,9 +27,14 @@ class editUser implements ShouldQueue
 
     private Collection $nodes;
 
-    public function __construct(User $user, Collection $nodes)
+    public function __construct(User $user, Collection|Node $nodes)
     {
-        $this->nodes = $nodes;
+        if ($nodes instanceof Collection) {
+            $this->nodes = $nodes;
+        } else {
+            $this->nodes = new Collection([$nodes]);
+        }
+
         $this->data = [
             'uid' => $user->id,
             'port' => (int) $user->port,

+ 1 - 1
app/Jobs/VNet/reloadNode.php

@@ -29,7 +29,7 @@ class reloadNode implements ShouldQueue
         if ($nodes instanceof Collection) {
             $this->nodes = $nodes;
         } else {
-            $this->nodes = $nodes->get();
+            $this->nodes = new Collection([$nodes]);
         }
     }
 

+ 1 - 1
app/Models/Payment.php

@@ -33,7 +33,7 @@ class Payment extends Model
 
     public function failed(): bool
     { // 关闭支付单
-        return $this->close() && $this->order()->close();
+        return $this->close() && $this->order->close();
     }
 
     public function close(): bool

+ 1 - 1
app/Models/User.php

@@ -26,7 +26,7 @@ use Spatie\Permission\Traits\HasRoles;
  */
 class User extends Authenticatable
 {
-    use HasApiTokens, HasFactory, Notifiable, HasRoles, Sortable;
+    use HasApiTokens, HasFactory, HasRoles, Notifiable, Sortable;
 
     public array $sortable = ['id', 'credit', 'port', 't', 'expired_at'];
 

+ 5 - 16
app/Notifications/PaymentReceived.php

@@ -12,14 +12,8 @@ class PaymentReceived extends Notification implements ShouldQueue
 {
     use Queueable;
 
-    private string $amount;
-
-    private string $sn;
-
-    public function __construct(string $sn, string $amount)
+    public function __construct(private readonly string $sn, private readonly string $amountWithSign)
     {
-        $this->amount = $amount;
-        $this->sn = $sn;
     }
 
     public function via($notifiable)
@@ -29,26 +23,21 @@ class PaymentReceived extends Notification implements ShouldQueue
 
     public function toMail($notifiable): MailMessage
     {
-        return (new MailMessage)
-            ->subject(__('Payment Received'))
-            ->line(__('Payment for #:sn has been received! Total amount: :amount.', ['sn' => $this->sn, 'amount' => $this->amount]))
-            ->action(__('Invoice Detail'), route('invoiceInfo', $this->sn));
+        return (new MailMessage)->subject(__('Payment Received'))->line(__('Payment for #:sn has been received! Total amount: :amount.', ['sn' => $this->sn, 'amount' => $this->amountWithSign]))->action(__('Invoice Detail'),
+            route('invoiceInfo', $this->sn));
     }
 
     public function toDataBase($notifiable): array
     {
         return [
             'sn' => $this->sn,
-            'amount' => $this->amount,
+            'amount' => $this->amountWithSign,
         ];
     }
 
     // todo: 需要重新审视发送对象
     public function toTelegram($notifiable): TelegramMessage
     {
-        return TelegramMessage::create()
-            ->to($notifiable->telegram_user_id)
-            ->token(sysConfig('telegram_token'))
-            ->content('💰'.__('Payment for #:sn has been received! Total amount: :amount.', ['sn' => $this->sn, 'amount' => $this->amount]));
+        return TelegramMessage::create()->to($notifiable->telegram_user_id)->token(sysConfig('telegram_token'))->content('💰'.__('Payment for #:sn has been received! Total amount: :amount.', ['sn' => $this->sn, 'amount' => $this->amountWithSign]));
     }
 }

+ 1 - 16
app/Notifications/TicketClosed.php

@@ -12,23 +12,8 @@ class TicketClosed extends Notification implements ShouldQueue
 {
     use Queueable;
 
-    private int $ticketId;
-
-    private string $title;
-
-    private string $url;
-
-    private string $reason;
-
-    private bool $is_user;
-
-    public function __construct(int $ticketId, string $title, string $url, string $reason, bool $is_user = false)
+    public function __construct(private readonly int $ticketId, private readonly string $title, private readonly string $url, private readonly ?string $reason, private readonly bool $is_user = false)
     {
-        $this->ticketId = $ticketId;
-        $this->title = $title;
-        $this->url = $url;
-        $this->reason = $reason;
-        $this->is_user = $is_user;
     }
 
     public function via($notifiable)

+ 3 - 3
app/Services/OrderService.php

@@ -18,7 +18,7 @@ class OrderService
 
     public static ?Payment $payment;
 
-    public function __construct(private Order $order)
+    public function __construct(private readonly Order $order)
     { // 获取需要的信息
         self::$user = $order->user;
         self::$goods = $order->goods;
@@ -79,7 +79,7 @@ class OrderService
 
     public function activatePlan(): bool
     { // 激活套餐
-        $this->order->update(['expired_at' => date('Y-m-d H:i:s', strtotime(self::$goods->days.' days'))]);
+        $this->order->refresh()->update(['expired_at' => date('Y-m-d H:i:s', strtotime(self::$goods->days.' days'))]);
         $oldData = self::$user->transfer_enable;
         $updateData = [
             'invite_num' => self::$user->invite_num + (self::$goods->invite_num ?: 0),
@@ -129,7 +129,7 @@ class OrderService
         return ($current->expired_at ?? now())->addDays($orders->except($current->id ?? 0)->sum('goods.days'))->format('Y-m-d');
     }
 
-    private function setCommissionExpense(User $user)
+    private function setCommissionExpense(User $user): void
     { // 佣金计算
         $referralType = sysConfig('referral_type');
 

+ 3 - 3
app/Services/PaymentService.php

@@ -9,7 +9,7 @@ use Str;
 
 class PaymentService
 {
-    final public function createPayment(int $uid, int $oid, int $amount): Payment
+    final public function createPayment(int $uid, int $oid, float|int $amount): Payment
     {
         $payment = new Payment();
         $payment->trade_no = Str::random(8);
@@ -24,9 +24,9 @@ class PaymentService
     /**
      * @param  string  $trade_no  本地订单号
      * @param  string  $out_trade_no  外部订单号
-     * @param  int  $amount  交易金额
+     * @param  float|int  $amount  交易金额
      */
-    final protected function createPaymentCallback(string $trade_no, string $out_trade_no, int $amount): int
+    final protected function createPaymentCallback(string $trade_no, string $out_trade_no, float|int $amount): int
     {
         $log = new PaymentCallback();
         $log->trade_no = $trade_no;

+ 1 - 1
app/Services/ProxyService.php

@@ -13,7 +13,7 @@ class ProxyService
 {
     use ClientConfig;
 
-    private static User $user;
+    private static ?User $user;
 
     private static array $servers;
 

+ 4 - 4
app/Utils/Helpers.php

@@ -172,12 +172,12 @@ class Helpers
      *
      * @param  int  $userId  用户ID
      * @param  int|null  $orderId  订单ID
-     * @param  int  $before  记录前余额
-     * @param  int  $after  记录后余额
-     * @param  int  $amount  发生金额
+     * @param  float|int  $before  记录前余额
+     * @param  float|int  $after  记录后余额
+     * @param  float|int  $amount  发生金额
      * @param  string|null  $description  描述
      */
-    public static function addUserCreditLog(int $userId, ?int $orderId, int $before, int $after, int $amount, string $description = null): bool
+    public static function addUserCreditLog(int $userId, ?int $orderId, float|int $before, float|int $after, float|int $amount, string $description = null): bool
     {
         $log = new UserCreditLog();
         $log->user_id = $userId;

+ 5 - 5
app/Utils/IP.php

@@ -247,11 +247,11 @@ class IP
             $data = $message['data'];
             if ($message['code'] === 0 && $data['ip'] === $ip) {
                 return [
-                    'country' => 'xx' !== strtolower($data['country']) ?: null,
-                    'region' => 'xx' !== strtolower($data['region']) ?: null,
-                    'city' => 'xx' !== strtolower($data['city']) ?: null,
-                    'isp' => 'xx' !== strtolower($data['isp']) ?: null,
-                    'area' => 'xx' !== strtolower($data['area']) ?: null,
+                    'country' => strtolower($data['country']) !== 'xx' ?: null,
+                    'region' => strtolower($data['region']) !== 'xx' ?: null,
+                    'city' => strtolower($data['city']) !== 'xx' ?: null,
+                    'isp' => strtolower($data['isp']) !== 'xx' ?: null,
+                    'area' => strtolower($data['area']) !== 'xx' ?: null,
                 ];
             }
 

+ 1 - 1
app/Utils/Library/AlipayF2F.php

@@ -92,7 +92,7 @@ class AlipayF2F
 
     private function send(): array
     {
-        $response = Http::get(self::$gatewayUrl, $this->buildParams())->json();
+        $response = Http::timeout(15)->get(self::$gatewayUrl, $this->buildParams())->json();
         $resKey = str_replace('.', '_', $this->config['method']).'_response';
         if (! isset($response[$resKey])) {
             throw new RuntimeException('请求错误-看起来是请求失败');

+ 2 - 2
app/Utils/NetworkDetection.php

@@ -14,7 +14,7 @@ class NetworkDetection
     public function ping(string $ip): ?string
     { // 用外部API进行Ping检测. TODO: 无权威外部API,功能缺失
         $testers = ['oiowebPing', 'xiaoapiPing', 'yum6Ping'];
-        self::$basicRequest = Http::timeout(15)->withOptions(['http_errors' => false])->withUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36');
+        self::$basicRequest = Http::timeout(20)->withOptions(['http_errors' => false])->withUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36');
 
         foreach ($testers as $tester) {
             try {
@@ -127,7 +127,7 @@ class NetworkDetection
     private function networkCheck(string $ip, int $port): ?array
     { // 通过众多API进行节点阻断检测.
         $checkers = ['toolsdaquan', 'flyzy2005', 'idcoffer', 'ip112', 'upx8', 'vps234', 'rss', 'gd', 'vps1352'];
-        self::$basicRequest = Http::timeout(10)->withOptions(['http_errors' => false])->withoutVerifying()->withUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36');
+        self::$basicRequest = Http::timeout(15)->retry(2)->withOptions(['http_errors' => false])->withoutVerifying()->withUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36');
 
         foreach ($checkers as $checker) {
             try {

+ 2 - 2
app/Utils/Payments/F2Fpay.php

@@ -41,8 +41,8 @@ class F2Fpay extends PaymentService implements Gateway
             $result = $gateWay->qrCharge($data);
             $payment->update(['qr_code' => 1, 'url' => $result['qr_code']]);
         } catch (Exception $e) {
-            $payment->failed();
             Log::alert('【支付宝当面付】支付错误: '.$e->getMessage());
+            $payment->failed();
             exit;
         }
 
@@ -53,7 +53,7 @@ class F2Fpay extends PaymentService implements Gateway
     {
         try {
             $result = (new AlipayF2F(self::$aliConfig))->tradeQuery($request->only('out_trade_no', 'trade_no'));
-            Log::notice('【支付宝当面付】回调验证查询:'.var_export($result, true));
+            Log::notice('【支付宝当面付】回调验证验证:'.var_export($result, true));
         } catch (Exception $e) {
             Log::alert('【支付宝当面付】回调信息错误: '.$e->getMessage());
             exit;

+ 1 - 1
app/Utils/Payments/PayPal.php

@@ -77,7 +77,7 @@ class PayPal extends PaymentService implements Gateway
         exit;
     }
 
-    protected function getCheckoutData($trade_no, $amount): array
+    protected function getCheckoutData(string $trade_no, float|int $amount): array
     {
         $converted = CurrencyExchange::convert('USD', $amount);
         if ($converted === false) {

+ 1 - 1
app/Utils/Payments/Stripe.php

@@ -82,7 +82,7 @@ class Stripe extends PaymentService implements Gateway
         }
     }
 
-    protected function getCheckoutSessionData(string $tradeNo, int $amount, int $type): array
+    protected function getCheckoutSessionData(string $tradeNo, float|int $amount, int $type): array
     {
         $unitAmount = $amount * 100;
 

+ 11 - 7
app/Utils/QQInfo.php

@@ -3,19 +3,23 @@
 namespace App\Utils;
 
 use Http;
+use Illuminate\Http\Client\PendingRequest;
 
 class QQInfo
 {
+    private static PendingRequest $basicRequest;
+
     public static function getQQAvatar(string $qq): ?string
     {
+        self::$basicRequest = Http::timeout(15)->withOptions(['http_errors' => false])->withUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36')->replaceHeaders(['Referer' => null]);
+
         $ret = null;
-        $source = 0;
+        $source = 1;
 
         while ($source <= 4 && $ret === null) {
             $ret = match ($source) {
-                0 => self::qZonePortrait("https://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?get_nick=1&uins=$qq", $qq),
-                1 => self::qZonePortrait("https://users.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?uins=$qq", $qq),
-                2 => self::qLogo("https://q.qlogo.cn/g?b=qq&nk=$qq&s=100"),
+                1 => self::qLogo("https://q.qlogo.cn/g?b=qq&nk=$qq&s=100"),
+                2 => self::qZonePortrait("https://users.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?uins=$qq", $qq),
                 3 => self::qLogo("https://thirdqq.qlogo.cn/g?b=qq&nk=$qq&s=100"),
                 4 => self::qqLogin($qq),
             };
@@ -27,7 +31,7 @@ class QQInfo
 
     private static function qZonePortrait(string $url, string $qq): ?string
     { //向接口发起请求获取json数据
-        $response = Http::timeout(15)->get($url);
+        $response = self::$basicRequest->get($url);
         if ($response->ok()) {
             $message = mb_convert_encoding($response->body(), 'UTF-8', 'GBK');
             if (str_contains($message, $qq)) { // 接口是否异常
@@ -42,7 +46,7 @@ class QQInfo
 
     private static function qLogo(string $url): ?string
     {
-        $response = Http::timeout(15)->get($url);
+        $response = self::$basicRequest->get($url);
         if ($response->ok()) {
             return $url;
         }
@@ -52,7 +56,7 @@ class QQInfo
 
     private static function qqLogin(string $qq): ?string
     {
-        $response = Http::timeout(15)->get("https://ptlogin.qq.com/getface?imgtype=3&uin=$qq");
+        $response = self::$basicRequest->get("https://ptlogin.qq.com/getface?imgtype=3&uin=$qq");
         if ($response->ok()) {
             $data = $response->body();
             if ($data) {

+ 17 - 15
resources/views/user/components/purchase.blade.php

@@ -13,21 +13,23 @@
         <img src="/assets/images/payment/wechatpay.svg" height="36px" alt="{{ trans('common.payment.wechat') }}"/>
     </button>
 @endif
-@if(str_contains(sysConfig('is_otherPay'), 'bitpayx'))
-    <button class="btn btn-round btn-outline-default mt-2" onclick="pay('bitpayx','4')">
-        <img src="/assets/images/payment/btc.svg" height="36px" alt="{{ trans('common.payment.crypto') }}"/>
-        <span class="font-size-24 black"> {{ trans('common.payment.crypto') }} </span>
-    </button>
-@endif
-@if(str_contains(sysConfig('is_otherPay'), 'paypal'))
-    <button class="btn btn-round btn-outline-default mt-2" onclick="pay('paypal','5')">
-        <img src="https://www.paypalobjects.com/webstatic/mktg/Logo/pp-logo-150px.png" height="32px" alt="PayPal"/>
-    </button>
-@endif
-@if(str_contains(sysConfig('is_otherPay'), 'stripe'))
-    <button class="btn btn-round btn-outline-default mt-2" onclick="pay('stripe','6')">
-        <img src="/assets/images/payment/stripe.svg" height="40px" alt="Stripe"/>
-    </button>
+@if(sysConfig('is_otherPay'))
+    @if(str_contains(sysConfig('is_otherPay'), 'bitpayx'))
+        <button class="btn btn-round btn-outline-default mt-2" onclick="pay('bitpayx','4')">
+            <img src="/assets/images/payment/btc.svg" height="36px" alt="{{ trans('common.payment.crypto') }}"/>
+            <span class="font-size-24 black"> {{ trans('common.payment.crypto') }} </span>
+        </button>
+    @endif
+    @if(str_contains(sysConfig('is_otherPay'), 'paypal'))
+        <button class="btn btn-round btn-outline-default mt-2" onclick="pay('paypal','5')">
+            <img src="https://www.paypalobjects.com/webstatic/mktg/Logo/pp-logo-150px.png" height="32px" alt="PayPal"/>
+        </button>
+    @endif
+    @if(str_contains(sysConfig('is_otherPay'), 'stripe'))
+        <button class="btn btn-round btn-outline-default mt-2" onclick="pay('stripe','6')">
+            <img src="/assets/images/payment/stripe.svg" height="40px" alt="Stripe"/>
+        </button>
+    @endif
 @endif
 @if(sysConfig('alipay_qrcode') || sysConfig('wechat_qrcode'))
     <button class="btn btn-round btn-outline-default mt-2" onclick="pay('manual','7')">