getAuthentication(); if (!$auth)return null; $logInfo = [ "param" => $this->data, "user" => Auth::id(), "ip" => request()->ip(), ]; try { $method = $this->method; $response = Http::withToken($auth["accessToken"]); $response->baseUrl(config("api.syrius.base_url")); if ($method=='post')$response->asJson(); return $response->$method($this->url,$this->data); }catch (ConnectionException $e){ Log::warning("syrius:连接异常",$logInfo); }catch (\Exception $e){ Log::warning("syrius:请求异常",$logInfo); } return null; } public function getAuthentication():?array { return (array)Cache::remember("SYRIUS_AUTHENTICATION",86400,function (){ $url = config("api.syrius.base_url").config("api.syrius.request.auth"); try { $response = Http::withHeaders(["Content-Type"=>'application/json'])->post($url,[ "authFlow" => "AK_SK_AUTH_FLOW", "attributes" => [ "clientKey" => config("api.syrius.client_id"), "clientSecret" => config("api.syrius.client_secret") ], ]); $data = json_decode($response->body()); if ($response->status()==200){ return $data; }else{ Log::warning("syrius:token返回失败",$data); } }catch (ConnectionException $e){ Log::warning("syrius:连接异常",["token获取失败"]); }catch (RequestException $e){ Log::warning("syrius:服务端请求",["token获取失败"]); }catch (\Exception $e){ Log::warning("syrius:未知异常",["token获取失败"]); } return null; }); } }