| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace App\Http\Controllers\api\thirdPart\syrius\producer;
- use Illuminate\Http\Client\ConnectionException;
- use Illuminate\Http\Client\Response;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Http;
- use Illuminate\Support\Facades\Log;
- class Controller
- {
- protected string $method;
- protected string $url;
- protected array $data = [];
- public function response(): ?Response
- {
- $url = config("api.syrius.base_url").$this->url;
- $logInfo = [
- "param" => $this->data,
- "user" => Auth::id(),
- "ip" => request()->ip(),
- ];
- $token = "";
- try {
- $method = $this->method;
- $headers = ['Authorization' => 'Bearer '.$token];
- if ($method=='post')$headers["Content-Type"] = 'application/json';
- return Http::withHeaders($headers)->$method($url,$this->data);
- }catch (ConnectionException $e){
- Log::warning("syrius:连接异常",$logInfo);
- }catch (\Exception $e){
- Log::warning("syrius:请求异常",$logInfo);
- }
- return null;
- }
- }
|