| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 | <?phpnamespace App\Jobs;use App\Service\ClearDataService;use Illuminate\Bus\Queueable;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Bus\Dispatchable;use Illuminate\Queue\InteractsWithQueue;use Illuminate\Queue\SerializesModels;use Illuminate\Support\Facades\Log;use Illuminate\Console\Command;use Symfony\Component\Console\Input\InputInterface;use Symfony\Component\Console\Output\ConsoleOutput;use Symfony\Component\Console\Output\OutputInterface;class SendDataJob implements ShouldQueue{    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;    protected $data;    /**     * Create a new job instance.     *     * @return void     */    public function __construct($data)    {        $this->data = $data;    }    /**     * Execute the job.     *     * @return void     */    public function handle()    {        file_put_contents('record2.txt',json_encode($this->data) .PHP_EOL,8);        //数据要发送的地址        $url = ClearDataService::getUrl($this->data);        $return = $this->sendRequest($url,$this->data);//        file_put_contents('send.txt',json_encode($return) .PHP_EOL,8);        //输出信息 测试        $this->echoMessage(new ConsoleOutput());    }    private function sendRequest($url,$data){        $data = json_encode($data);        $header[] = "Content-Type:application/json";        $ch=curl_init($url);        curl_setopt($ch,CURLOPT_POST,1);        curl_setopt($ch,CURLOPT_POSTFIELDS,$data);        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);        curl_setopt($ch,CURLOPT_HTTPHEADER,$header);        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);        $response=curl_exec($ch);        $response=json_decode($response,true);        if(curl_errno($ch) ){            sc(curl_error($ch));        }        return $response;    }    protected function echoMessage(OutputInterface $output)    {        $output->writeln('2222222');    }}
 |