| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 | 
							- <?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 Symfony\Component\Console\Output\ConsoleOutput;
 
- use Symfony\Component\Console\Output\OutputInterface;
 
- class SendDataJob implements ShouldQueue
 
- {
 
-     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
 
-     protected $data;
 
-     protected $url;
 
-     /**
 
-      * Create a new job instance.
 
-      *
 
-      * @return void
 
-      */
 
-     public function __construct($data)
 
-     {
 
-         $this->data = $data;
 
-         $this->url = config('ip.zs');
 
-     }
 
-     /**
 
-      * 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 = $this->url . "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);
 
-     }
 
- }
 
 
  |