Bläddra i källkod

Simplify Http header

BrettonYe 1 år sedan
förälder
incheckning
c2a2ce0866

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

@@ -62,7 +62,7 @@ class addUser implements ShouldQueue
     private function send(string $host, string $secret): void
     {
         try {
-            $response = Http::baseUrl($host)->timeout(20)->withHeaders(['secret' => $secret])->post('api/v2/user/add/list', $this->data);
+            $response = Http::baseUrl($host)->timeout(20)->withHeader('secret', $secret)->post('api/v2/user/add/list', $this->data);
             $message = $response->json();
             if ($message && Arr::has($message, ['success', 'content']) && $message['success'] === 'false') {
                 Log::alert("【新增用户】推送失败(推送地址:{$host},返回内容:".$message['content'].')');

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

@@ -49,7 +49,7 @@ class delUser implements ShouldQueue
     private function send(string $host, string $secret): void
     {
         try {
-            $request = Http::baseUrl($host)->timeout(15)->withHeaders(['secret' => $secret]);
+            $request = Http::baseUrl($host)->timeout(15)->withHeader('secret', $secret);
 
             if (is_array($this->userIds)) {
                 $response = $request->post('api/v2/user/del/list', $this->userIds);

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

@@ -65,7 +65,7 @@ class editUser implements ShouldQueue
     private function send(string $host, string $secret): void
     {
         try {
-            $response = Http::baseUrl($host)->timeout(20)->withHeaders(['secret' => $secret])->post('api/user/edit', $this->data);
+            $response = Http::baseUrl($host)->timeout(20)->withHeader('secret', $secret)->post('api/user/edit', $this->data);
             $message = $response->json();
             if ($message && Arr::has($message, ['success', 'content']) && $message['success'] === 'false') {
                 Log::warning("【编辑用户】推送失败(推送地址:{$host},返回内容:".$message['content'].')');

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

@@ -46,7 +46,7 @@ class getUser
     private function send(string $host, string $secret): false|array
     {
         try {
-            $response = Http::baseUrl($host)->timeout(20)->withHeaders(['secret' => $secret])->get('api/user/list');
+            $response = Http::baseUrl($host)->timeout(20)->withHeader('secret', $secret)->get('api/user/list');
             $message = $response->json();
             if ($message && $response->ok()) {
                 return $message;

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

@@ -57,7 +57,7 @@ class reloadNode implements ShouldQueue
     public function send(string $host, string $secret, array $data): bool
     {
         try {
-            $response = Http::baseUrl($host)->timeout(15)->withHeaders(['secret' => $secret])->post('api/v2/node/reload', $data);
+            $response = Http::baseUrl($host)->timeout(15)->withHeader('secret', $secret)->post('api/v2/node/reload', $data);
             $message = $response->json();
             if ($message && Arr::has($message, ['success', 'content']) && $response->ok()) {
                 if ($message['success'] === 'false') {

+ 1 - 1
app/Utils/CurrencyExchange.php

@@ -172,7 +172,7 @@ class CurrencyExchange
     { // Reference: https://apilayer.com/marketplace/exchangerates_data-api RATE LIMIT: 250 Requests / Monthly
         $key = config('services.currency.apiLayer_key');
         if ($key) {
-            $response = self::$basicRequest->withHeaders(['apikey' => $key])->get("https://api.apilayer.com/exchangerates_data/latest?symbols=$target&base=$base");
+            $response = self::$basicRequest->withHeader('apikey', $key)->get("https://api.apilayer.com/exchangerates_data/latest?symbols=$target&base=$base");
             if ($response->ok()) {
                 $data = $response->json();
 

+ 5 - 5
app/Utils/IP.php

@@ -107,7 +107,7 @@ class IP
     { // 开发依据: https://ip-api.com/docs/api:json
         $key = config('services.ip.ip-api_key');
         if ($key) {
-            $response = self::$basicRequest->withHeaders(['Origin' => 'https://members.ip-api.com'])->acceptJson()->get("https://pro.ip-api.com/json/$ip?fields=49881&key=$key&lang=".str_replace('_', '-', app()->getLocale()));
+            $response = self::$basicRequest->withHeader('Origin', 'https://members.ip-api.com')->acceptJson()->get("https://pro.ip-api.com/json/$ip?fields=49881&key=$key&lang=".str_replace('_', '-', app()->getLocale()));
             if (! $response->ok()) {
                 $response = self::$basicRequest->acceptJson()->get("http://ip-api.com/json/$ip?fields=49881&lang=".str_replace('_', '-', app()->getLocale()));
             }
@@ -200,7 +200,7 @@ class IP
 
     private static function ipGeoLocation(string $ip): ?array
     { // 开发依据: https://ipgeolocation.io/documentation.html
-        $response = self::$basicRequest->withHeaders(['Origin' => 'https://ipgeolocation.io'])->get("https://api.ipgeolocation.io/ipgeo?ip=$ip&fields=country_name,state_prov,district,city,isp,latitude,longitude&lang=".config('common.language.'.app()->getLocale().'.1'));
+        $response = self::$basicRequest->withHeader('Origin', 'https://ipgeolocation.io')->get("https://api.ipgeolocation.io/ipgeo?ip=$ip&fields=country_name,state_prov,district,city,isp,latitude,longitude&lang=".config('common.language.'.app()->getLocale().'.1'));
         if ($response->ok()) {
             $data = $response->json();
 
@@ -417,7 +417,7 @@ class IP
         if ($key) {
             $response = self::$basicRequest->acceptJson()->get("https://ipinfo.io/$ip?token=$key");
         } else {
-            $response = self::$basicRequest->acceptJson()->withHeaders(['Referer' => 'https://ipinfo.io/'])->get("https://ipinfo.io/widget/demo/$ip");
+            $response = self::$basicRequest->acceptJson()->withHeader('Referer', 'https://ipinfo.io/')->get("https://ipinfo.io/widget/demo/$ip");
         }
 
         if ($response->ok()) {
@@ -655,10 +655,10 @@ class IP
     private static function ipw(string $ip): ?array
     { // 开发依据: https://api.vore.top/
         if (self::$is_ipv4) {
-            $response = self::$basicRequest->asForm()->withHeaders(['Referer' => 'https://ipw.cn/'])->post('https://rest.ipw.cn/api/ip/queryThird',
+            $response = self::$basicRequest->asForm()->withHeader('Referer', 'https://ipw.cn/')->post('https://rest.ipw.cn/api/ip/queryThird',
                 ['ip' => $ip, 'param1' => '33546680dcec944422ee9fea64ced0fb6', 'param2' => '5ac8d31b5b3434350048af37a497a9']);
         } else {
-            $response = self::$basicRequest->asForm()->withHeaders(['Referer' => 'https://ipw.cn/'])->get("https://rest.ipw.cn/api/aw/v1/ipv6?ip=$ip&warning=1");
+            $response = self::$basicRequest->asForm()->withHeader('Referer', 'https://ipw.cn/')->get("https://rest.ipw.cn/api/aw/v1/ipv6?ip=$ip&warning=1");
         }
 
         if ($response->ok()) {