Kaynağa Gözat

化工人员定位煤制油部门信息接口

任敬轩 5 ay önce
ebeveyn
işleme
6a94f9014c
1 değiştirilmiş dosya ile 68 ekleme ve 0 silme
  1. 68 0
      app/Http/Controllers/TestsController.php

+ 68 - 0
app/Http/Controllers/TestsController.php

@@ -53,6 +53,9 @@ class TestsController {
 
         //区域下(包含子区域)摄像头接口测试
         // $this->camera_all_list();
+
+        //化工人员定位煤制油部门信息录入
+//        $this->mzyBmxxInsert();
     }
 
     //区域列表接口测试
@@ -334,6 +337,42 @@ class TestsController {
         $repeat_arr = array_diff_assoc ( $aa, $unique_arr );
         return $repeat_arr;
     }
+
+    //化工人员定位煤制油部门信息录入
+    public function mzyBmxxInsert(){
+        //获取token
+        $url = 'http://10.186.64.30:8091/chem/api/getToken?username=super&password=meizhiyou';
+
+        $result = $this->httpRequest($url,'post');
+
+        if($result['data']){
+            //获取部门列表
+            $url = 'http://10.186.64.30:8091/chem/api/getOrgans?token='.$result['data'];
+
+            $result2 = $this->httpRequest($url);
+
+            if($result2['data'] && count($result2['data']) > 0){
+                $list = $result2['data'];
+
+                DB::connection('mysql_fwe10')->table('uf_mzy_bmxx')->where('id','!=',null)->delete();
+                // dd($list);
+                for($i=0;$i<count($list);$i++){
+                    $data['id'] = $list[$i]['id'];
+                    $data['token'] = $list[$i]['token'];
+                    $data['organName'] = $list[$i]['organName'];
+                    $data['parentId'] = $list[$i]['parentId'];
+                    $data['manager'] = $list[$i]['manager'];
+                    $data['phone'] = $list[$i]['phone'];
+                    $data['address'] = $list[$i]['address'];
+
+                    DB::connection('mysql_fwe10')->table('uf_mzy_bmxx')->insert($data);
+
+                }
+            }
+        }
+
+        dd('success');
+    }
     
     public function getDcsApiData() {
         $apiUrl = "http://7.250.4.3:4300/v1/common/GetPointRealDataByPageV3";
@@ -438,4 +477,33 @@ class TestsController {
         }
 
     }
+
+    //接口第三方调用
+    public function httpRequest($url, $format = 'get', $data = null, $token = null){
+        //设置头信息
+        $headerArray =array("Content-type:application/json;","Accept:application/json");
+
+        if ($token) {
+            $headerArray[] = "Authorization:bearer " . $token;
+        }
+
+        $curl=curl_init();
+        curl_setopt($curl, CURLOPT_URL, $url);
+        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
+        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
+        if ($format == 'post') {
+            //post传值设置post传参
+            curl_setopt($curl, CURLOPT_POST, 1);
+            if ($data) {
+                $data = json_encode($data);
+                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
+            }
+        }
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
+        $data=json_decode(curl_exec($curl), true);
+        curl_close($curl);
+        //返回接口返回数据
+        return $data;
+    }
 }