| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace App\Jobs;
- 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 extends Command implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- protected $data;
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct($data)
- {
- $this->data = $data;
- parent::__construct(); // 调用父类的构造函数
- }
- /**
- * Execute the job.
- *
- * @return void
- */
- public function handle()
- {
- $url = '';
- $return = $this->sendRequest($url,$this->data);
- file_put_contents('charge.txt',json_encode($this->data),8);
- $this->echoMessage(new ConsoleOutput());
- }
- private function sendRequest($url,$data){return true;
- $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);
- file_put_contents('job_send.txt',$response.PHP_EOL,8);
- $response=json_decode($response,true);
- if(curl_errno($ch) ){
- sc(curl_error($ch));
- }
- return $response;
- }
- protected function echoMessage(OutputInterface $output)
- {
- $output->writeln('2222222');
- }
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $output->write('22222222');
- $output->writeln('2222222');
- }
- }
|