| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 | <?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 Symfony\Component\Console\Output\ConsoleOutput;use Symfony\Component\Console\Output\OutputInterface;class ProcessDataJob 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('record.txt',json_encode($this->data) . PHP_EOL,8);        //保存数据到自己服务器        ClearDataService::saveData($this->data);        //处理数据        $return = ClearDataService::clearData($this->data);        $this->sendToDevice($return);        //传递数据给下一个队列//        dispatch(new SendDataJob($return))->onQueue('cloud_device');        file_put_contents('record2.txt',json_encode($return) . PHP_EOL,8);        //输出信息        $this->echoMessage(new ConsoleOutput());    }    public function sendToDevice($data){        $url = "http://121.36.142.167:7774/api/module-data/device_machine_record/device_machine_record";        $post = [            'bizId' => -1,            'bizTypeEk' => 'LOWCODE',            'data' => [                'device_machine_record' => [                    'machine_code' => $data['dev_eui'],                    'param_value' => $data['value']                ]            ],            'dynamicFormId' => '477743923368955904',            'showModelId' => '477745421456904192'        ];        $header = ['Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwiYXV0aCI6IlJPTEVfSU5ORVJfVVNFUixST0xFX0FETUlOLFJPTEVfSU5URVJGQUNFIiwidG9rZW5JZCI6IjM1IiwiZXhwIjoxNjk0Njc0MTE0fQ.L3Di3K_cpF0rWSgvzbcLufLm8bkCxd3Y-xudfKzSm4F-qdpDr0hYWWQP5K5BYTNuZnu4tWpGmSW2KRHU0pjt-A','Content-Type:application/json'];        $curl = curl_init();        curl_setopt_array($curl, array(            CURLOPT_URL => $url,            CURLOPT_RETURNTRANSFER => true,            CURLOPT_ENCODING => '',            CURLOPT_MAXREDIRS => 10,            CURLOPT_TIMEOUT => 0,            CURLOPT_FOLLOWLOCATION => true,            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,            CURLOPT_CUSTOMREQUEST => 'POST',            CURLOPT_POSTFIELDS => json_encode($post),            CURLOPT_HTTPHEADER => $header,        ));        $response = curl_exec($curl);        curl_close($curl);        file_put_contents('record2.txt',date('Y-m-d H:i:s'). PHP_EOL . $response .PHP_EOL,8);    }    protected function echoMessage(OutputInterface $output)    {        $output->writeln(json_encode($this->data));    }}
 |