data = $data; } /** * Execute the job. * * @return void */ public function handle() { //暂时不用 file_put_contents('record2.txt',json_encode($this->data) . PHP_EOL,8); if(isset($data['is_clear_data'])){ $this->sendToDevice($this->data); } //输出信息 测试 $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; } 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($this->data); } }