2

如何在作业队列中传递 curl 资源?但现在 curl 不支持队列,不响应

在此处输入代码

          $fields = json_encode($fields);
         $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, 'https://onesignal.com/api/v1/notifications');
          curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json; charset=utf-8']);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($ch, CURLOPT_HEADER, false);
          curl_setopt($ch, CURLOPT_POST, true);
          curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
          $response = curl_exec($ch);

我也用过 laravel guzzlehttp

 $client = new \GuzzleHttp\Client();

        $response = $client->request('POST', 'https://onesignal.com/api/v1/notifications', [
                        'json' => $fields
                    ]);

class OneSignalJobs implements ShouldQueue
{  public function handle()
    {  $files=[]

        $fields = json_encode($fields);
        $url = "https://onesignal.com/api/v1/notifications";
        $response = $client->createRequest("POST", $url, $fields);
        $response = $client->send($response);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://onesignal.com/api/v1/notifications');
        curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json; charset=utf-8']);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $files);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $response = curl_exec($ch); }
4

0 回答 0