cqpCow 1 년 전
부모
커밋
5e44e17e9b
2개의 변경된 파일47개의 추가작업 그리고 13개의 파일을 삭제
  1. 37 9
      app/Jobs/SendDataJob.php
  2. 10 4
      app/Service/ClearDataService.php

+ 37 - 9
app/Jobs/SendDataJob.php

@@ -2,7 +2,6 @@
 
 namespace App\Jobs;
 
-use App\Service\ClearDataService;
 use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Foundation\Bus\Dispatchable;
@@ -37,16 +36,10 @@ class SendDataJob implements ShouldQueue
      */
     public function handle()
     {
-        file_put_contents('record2.txt',json_encode($this->data) .PHP_EOL,8);
-
-        //数据要发送的地址
-        $url = ClearDataService::getUrl($this->data);
-        if(! empty($url)){
-            $return = $this->sendRequest($url,$this->data);
+        if(isset($data['is_clear_data'])){
+            $this->sendToDevice($this->data);
         }
 
-//        file_put_contents('send.txt',json_encode($return) .PHP_EOL,8);
-
         //输出信息 测试
         $this->echoMessage(new ConsoleOutput());
     }
@@ -70,6 +63,41 @@ class SendDataJob implements ShouldQueue
         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('发送结束');

+ 10 - 4
app/Service/ClearDataService.php

@@ -101,11 +101,17 @@ class ClearDataService extends Service
     }
 
     public static function clearData($data){
-        if(empty($data)) return $data;
-
-        //具体处理数据的业务 TODO
+        $return['is_clear_data'] = 1;
+        $return['dev_eui'] = $data['obj']['devEUI'] ?? '';
+        if(isset($data['temperature'])){
+            $return['value'] = $data['temperature'];
+        }elseif (isset($data['pressure'])){
+            $return['value'] = $data['pressure'];
+        }else{
+            $return['value'] = 0;
+        }
 
-        return $data;
+        return $return;
     }
 
     public static function getUrl($data){