Browse Source

💪🏼 Improve Code

BrettonYe 2 years ago
parent
commit
b5c04f34ae

+ 2 - 2
app/Channels/Library/WeChat.php

@@ -9,7 +9,7 @@ use Str;
 
 class WeChat
 {
-    public function EncryptMsg(string $sReplyMsg, int|null $sTimeStamp, string $sNonce, string &$sEncryptMsg)
+    public function EncryptMsg(string $sReplyMsg, ?int $sTimeStamp, string $sNonce, string &$sEncryptMsg)
     { //将公众平台回复用户的消息加密打包.
         //加密
         $array = (new Prpcrypt())->encrypt($sReplyMsg);
@@ -72,7 +72,7 @@ class WeChat
         return sprintf($format, $encrypt, $signature, $timestamp, $nonce);
     }
 
-    public function DecryptMsg(string $sMsgSignature, int|null $sTimeStamp, string $sNonce, string $sPostData, string &$sMsg)
+    public function DecryptMsg(string $sMsgSignature, ?int $sTimeStamp, string $sNonce, string $sPostData, string &$sMsg)
     { // 检验消息的真实性,并且获取解密后的明文.
         //提取密文
         $array = $this->extract($sPostData);

+ 1 - 1
app/Helpers/ClientApiResponse.php

@@ -21,7 +21,7 @@ trait ClientApiResponse
         self::$client = $client;
     }
 
-    public function succeed(array|null $data = null, array|null $addition = null, array $codeResponse = ResponseEnum::HTTP_OK): JsonResponse
+    public function succeed(?array $data = null, ?array $addition = null, array $codeResponse = ResponseEnum::HTTP_OK): JsonResponse
     {
         return $this->jsonResponse(1, $codeResponse, $data, $addition);
     }

+ 1 - 1
app/Helpers/ClientConfig.php

@@ -99,7 +99,7 @@ trait ClientConfig
         return $encode ? base64_encode($uri) : $uri;
     }
 
-    private function clash(string $client = ''): string
+    private function clash(?string $client = null): string
     {
         $user = $this->getUser();
         $webName = sysConfig('website_name');

+ 4 - 4
app/Helpers/WebApiResponse.php

@@ -6,12 +6,12 @@ use Illuminate\Http\JsonResponse;
 
 trait WebApiResponse
 {
-    public function succeed(array|null $data = null, array|null $addition = null, array $codeResponse = ResponseEnum::HTTP_OK): JsonResponse // 成功
+    public function succeed(?array $data = null, ?array $addition = null, array $codeResponse = ResponseEnum::HTTP_OK): JsonResponse // 成功
     {
         return $this->jsonResponse('success', $codeResponse, $data, $addition);
     }
 
-    private function jsonResponse(string $status, array $codeResponse, array|null $data = null, array|null $addition = null): JsonResponse // 返回数据
+    private function jsonResponse(string $status, array $codeResponse, ?array $data = null, ?array $addition = null): JsonResponse // 返回数据
     {
         [$code, $message] = $codeResponse;
         if ($status === 'success') {
@@ -26,7 +26,7 @@ trait WebApiResponse
         return response()->json($data, $code, ['ETAG' => $etag ?? '']);
     }
 
-    private static function abortIfNotModified(array|null $data): string // 检查数据是否有变动
+    private static function abortIfNotModified(?array $data): string // 检查数据是否有变动
     {
         $req = request();
 
@@ -42,7 +42,7 @@ trait WebApiResponse
         return $etag;
     }
 
-    public function failed(array $codeResponse = ResponseEnum::HTTP_ERROR, array|null $data = null): JsonResponse // 失败
+    public function failed(array $codeResponse = ResponseEnum::HTTP_ERROR, ?array $data = null): JsonResponse // 失败
     {
         return $this->jsonResponse('fail', $codeResponse, $data);
     }

+ 1 - 1
app/Http/Controllers/Admin/LogsController.php

@@ -142,7 +142,7 @@ class LogsController extends Controller
     }
 
     // 在线IP监控(实时)
-    public function onlineIPMonitor(Request $request, $id = null)
+    public function onlineIPMonitor(Request $request, ?int $id = null)
     {
         $query = NodeOnlineIp::with(['node:id,name', 'user:id,username'])->where('created_at', '>=', strtotime('-2 minutes'));
 

+ 1 - 1
app/Http/Controllers/Api/Client/ClientController.php

@@ -247,7 +247,7 @@ class ClientController extends Controller
         return $this->succeed(null, ['config' => $config]);
     }
 
-    private function clientConfig($key = '')
+    private function clientConfig(?string $key = null)
     {
         if (! config('client')) {
             Artisan::call('config:cache');

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

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

+ 1 - 1
app/Http/Controllers/User/SubscribeController.php

@@ -14,7 +14,7 @@ use Response;
 
 class SubscribeController extends Controller
 {
-    private static int|null $subType;
+    private static ?int $subType;
 
     private ProxyService $proxyServer;
 

+ 3 - 3
app/Services/OrderService.php

@@ -14,9 +14,9 @@ class OrderService
 {
     public static User $user;
 
-    public static Goods|null $goods;
+    public static ?Goods $goods;
 
-    public static Payment|null $payment;
+    public static ?Payment $payment;
 
     public function __construct(private Order $order)
     { // 获取需要的信息
@@ -100,7 +100,7 @@ class OrderService
         return false;
     }
 
-    public function resetTimeAndData(string|null $expired_at = null): array
+    public function resetTimeAndData(?string $expired_at = null): array
     { // 计算下次重置与账号过期时间
         if (! $expired_at) { // 账号有效期
             $expired_at = $this->getFinallyExpiredTime();

+ 10 - 10
app/Services/ProxyService.php

@@ -17,7 +17,7 @@ class ProxyService
 
     private static array $servers;
 
-    public function __construct(?User $user)
+    public function __construct(?User $user = null)
     {
         self::$user = $user ?? auth()->user();
     }
@@ -83,12 +83,12 @@ class ProxyService
     { // 提取节点信息
         $user = self::$user;
         $config = [
-            'id'    => $node->id,
-            'name'  => $node->name,
-            'area'  => $node->country->name,
-            'host'  => $node->host,
+            'id' => $node->id,
+            'name' => $node->name,
+            'area' => $node->country->name,
+            'host' => $node->host,
             'group' => sysConfig('website_name'),
-            'udp'   => $node->is_udp,
+            'udp' => $node->is_udp,
         ];
 
         if ($node->relay_node_id) {
@@ -102,7 +102,7 @@ class ProxyService
             switch ($node->type) {
                 case 0:
                     $config = array_merge($config, [
-                        'type'   => 'shadowsocks',
+                        'type' => 'shadowsocks',
                         'passwd' => $user->passwd,
                     ], $node->profile);
                     if ($node->port && $node->port !== 0) {
@@ -120,10 +120,10 @@ class ProxyService
                     break;
                 case 3:
                     $config = array_merge($config, [
-                        'type'   => 'trojan',
-                        'port'   => $node->port,
+                        'type' => 'trojan',
+                        'port' => $node->port,
                         'passwd' => $user->passwd,
-                        'sni'    => '',
+                        'sni' => '',
                     ], $node->profile);
                     break;
                 case 1:

+ 1 - 1
app/Services/TelegramService.php

@@ -8,7 +8,7 @@ class TelegramService
 {
     private static string $api;
 
-    public function __construct(string $token = null)
+    public function __construct(?string $token = null)
     {
         self::$api = 'https://api.telegram.org/bot'.($token ?? sysConfig('telegram_token')).'/';
     }

+ 1 - 1
app/Services/UserService.php

@@ -9,7 +9,7 @@ class UserService
 {
     private static User $user;
 
-    public function __construct(User $user = null)
+    public function __construct(?User $user = null)
     {
         self::$user = $user ?? auth()->user();
     }

+ 1 - 1
app/Utils/DDNS/CloudFlare.php

@@ -38,7 +38,7 @@ class CloudFlare implements DNS
         exit(400);
     }
 
-    private function send(string $action, array $parameters = [], string $identifier = null): array
+    private function send(string $action, array $parameters = [], ?string $identifier = null): array
     {
         $client = Http::timeout(10)->retry(3, 1000)->withHeaders($this->auth)->baseUrl($this->apiHost)->asJson();
 

+ 10 - 10
app/Utils/Helpers.php

@@ -53,7 +53,7 @@ class Helpers
      * @param  int|null  $inviter_id  邀请人
      * @param  string|null  $nickname  昵称
      */
-    public static function addUser(string $username, string $password, int $transfer_enable, string $date = null, int $inviter_id = null, string $nickname = null): User
+    public static function addUser(string $username, string $password, int $transfer_enable, ?string $date = null, ?int $inviter_id = null, ?string $nickname = null): User
     {
         return User::create([
             'nickname' => $nickname ?? $username,
@@ -133,7 +133,7 @@ class Helpers
      * @param  string|null  $msgId  对公查询ID
      * @param  string  $address  收信方
      */
-    public static function addNotificationLog(string $title, string $content, int $type, int $status = 1, string $error = null, string $msgId = null, string $address = 'admin'): int
+    public static function addNotificationLog(string $title, string $content, int $type, int $status = 1, ?string $error = null, ?string $msgId = null, string $address = 'admin'): int
     {
         $log = new NotificationLog();
         $log->type = $type;
@@ -156,7 +156,7 @@ class Helpers
      * @param  int|null  $goodsId  商品ID
      * @param  int|null  $orderId  订单ID
      */
-    public static function addCouponLog($description, $couponId, $goodsId = null, $orderId = null): bool
+    public static function addCouponLog(string $description, int $couponId, ?int $goodsId = null, ?int $orderId = null): bool
     {
         $log = new CouponLog();
         $log->coupon_id = $couponId;
@@ -175,9 +175,9 @@ class Helpers
      * @param  int  $before  记录前余额
      * @param  int  $after  记录后余额
      * @param  int  $amount  发生金额
-     * @param  string  $description  描述
+     * @param  string|null  $description  描述
      */
-    public static function addUserCreditLog($userId, $orderId, $before, $after, $amount, $description = ''): bool
+    public static function addUserCreditLog(int $userId, ?int $orderId, int $before, int $after, int $amount, ?string $description = null): bool
     {
         $log = new UserCreditLog();
         $log->user_id = $userId;
@@ -197,10 +197,10 @@ class Helpers
      * @param  int  $userId  用户ID
      * @param  int  $before  记录前的值
      * @param  int  $after  记录后的值
-     * @param  string  $description  描述
+     * @param  string|null  $description  描述
      * @param  int|null  $orderId  订单ID
      */
-    public static function addUserTrafficModifyLog(int $userId, int $before, int $after, string $description = '', $orderId = null): bool
+    public static function addUserTrafficModifyLog(int $userId, int $before, int $after, ?string $description = null, ?int $orderId = null): bool
     {
         $log = new UserDataModifyLog();
         $log->user_id = $userId;
@@ -215,14 +215,14 @@ class Helpers
     /**
      * 推销信息推送
      *
+     * @param  string  $receiver  收件人
      * @param  int  $type  渠道类型
      * @param  string  $title  标题
      * @param  string  $content  内容
      * @param  int  $status  状态
-     * @param  string  $error  报错
-     * @param  string  $receiver  收件人
+     * @param  string|null  $error  报错
      */
-    public static function addMarketing(int $type, string $title, string $content, int $status = 1, string $error = '', string $receiver = ''): bool
+    public static function addMarketing(string $receiver, int $type, string $title, string $content, int $status = 1, ?string $error = null): bool
     {
         $marketing = new Marketing();
         $marketing->type = $type;

+ 2 - 2
app/helpers.php

@@ -27,7 +27,7 @@ if (! function_exists('base64url_decode')) {
 
 // 根据流量值自动转换单位输出
 if (! function_exists('formatBytes')) {
-    function formatBytes(int $bytes, string $base = '', int $precision = 2): string
+    function formatBytes(int $bytes, ?string $base = null, int $precision = 2): string
     {
         $units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
         $bytes = max($bytes, 0);
@@ -70,7 +70,7 @@ if (! function_exists('formatTime')) {
 
 // 获取系统设置
 if (! function_exists('sysConfig')) {
-    function sysConfig(string $key = '', string $default = ''): array|string
+    function sysConfig(?string $key = null, ?string $default = null): array|string|null
     {
         return $key ? config("settings.$key", $default) : config('settings');
     }

+ 7 - 6
resources/rules/default.clash.yaml

@@ -11,12 +11,13 @@ external-controller: 127.0.0.1:9090
 
 dns:
   enable: true
-  # listen: 0.0.0.0:53
-  ipv6: false
+  listen: 0.0.0.0:53
+  ipv6: true
 
   default-nameserver:
     - 223.5.5.5
     - 119.29.29.29
+    - 8.8.8.8
   enhanced-mode: fake-ip
   fake-ip-range: 198.18.0.1/16
   use-hosts: true
@@ -27,9 +28,9 @@ dns:
     - https://doh.dns.sb/dns-query
     - https://dns.cloudflare.com/dns-query
     - https://dns.twnic.tw/dns-query
-    - tls://8.8.4.4:853
+    - https://dns.google/dns-query
   fallback-filter:
-    geoip: true
+    geoip: false
     ipcidr:
       - 240.0.0.0/4
       - 0.0.0.0/32
@@ -38,8 +39,8 @@ proxies:
 
 proxy-groups:
   - { name: "$app_name", type: select, proxies: ["自动选择", "故障转移"] }
-  - { name: "自动选择", type: url-test, proxies: [], url: "http://www.gstatic.com/generate_204", interval: 86400 }
-  - { name: "故障转移", type: fallback, proxies: [], url: "http://www.gstatic.com/generate_204", interval: 7200 }
+  - { name: "自动选择", type: url-test, proxies: [], url: "https://www.gstatic.com/generate_204", interval: 86400 }
+  - { name: "故障转移", type: fallback, proxies: [], url: "https://www.gstatic.com/generate_204", interval: 7200 }
 
 rules:
   # 自定义规则

+ 2 - 2
resources/views/admin/rule/index.blade.php

@@ -35,7 +35,7 @@
                     <thead class="thead-default">
                     <tr>
                         <th> #</th>
-                        <th> {{ trans('model.rule.type') }}</th>
+                        <th> {{ trans('model.rule.attribute') }}</th>
                         <th> {{ trans('model.rule.name') }}</th>
                         <th> {{ trans('model.rule.pattern') }}</th>
                         <th> {{trans('common.action')}}</th>
@@ -101,7 +101,7 @@
                         <div class="form-row">
                             <div class="col-12">
                                 <div class="form-group row">
-                                    <label class="col-md-2 col-sm-3 col-form-label" for="add_type">{{ trans('model.rule.type') }}</label>
+                                    <label class="col-md-2 col-sm-3 col-form-label" for="add_type">{{ trans('model.rule.attribute') }}</label>
                                     <div class="col-xl-4 col-sm-8">
                                         <select class="form-control" name="add_type" id="add_type" data-plugin="selectpicker" data-style="btn-outline btn-primary">
                                             <option value="1">{{ trans('admin.rule.type.reg') }}</option>