'baz001', # 分馆代码 'name' => '图书馆', # 单位名称 'cameraId' => '9,7,6,4,2,1,67,3,135,144,145', # 客流系统内分馆摄像头 ], [ 'groupId' => 'BAF055', 'name' => '文化馆', 'cameraId' => '134,141,142', ] ]; public function run() { $config = $this->config('api_config'); $requestData = []; $allData = $this->getBaoAnLibData(); $tempAllArr = [ 'group_id' => 'lib001', 'group_name' => base64_encode('文化') ]; /*foreach ($allData as $allKey => $allValue) { foreach ($allValue as $aKey => $aValue) { $tempAllArr[$allKey."_".$aKey] = $aValue; } }*/ $libData = $this->getBaoAnLibData(true); foreach ($libData as $row) { $tempArr = [ 'group_id' => $row['groupId'], 'group_name' => base64_encode($row['name']) ]; foreach ($row['data'] as $key => $value) { foreach ($value as $k => $v) { $field = $key."_".$k; $tempArr[$field] = $v ?: 0; if (!isset($tempAllArr[$field])) $tempAllArr[$field] = 0; $tempAllArr[$field] += $tempArr[$field]; } } $requestData[] = $tempArr; } $requestData[] = $tempAllArr; $requestRes = $this->request_create_data($requestData,'/api/library.pass/create',$config['host_path'],true); if (!$requestRes['status']) { return $requestRes['msg']; } return true; } // 获取图书馆借阅,办证数据 public function runService() { $url = 'http://10.99.57.79:9999/SSBusiness/monitor/getLibraryService?library=044007'; $result = $this->curl_post($url); $result_data = json_decode($result,true); var_dump($result);die; } /** * @param $is_group * @return array|mixed */ public function getBaoAnLibData($is_group = false) { if ($is_group) { $data = []; foreach ($this->libCameraId as $value) { $url = $this->libUrl . '&cameraid=' . $value['cameraId']; $result = $this->curl_post($url); var_dump($result); $result = json_decode($result,true); $data[] = [ 'data' => $result, 'groupId' => $value['groupId'], 'name' => $value['name'] ]; } return $data; } else { $result = $this->curl_post($this->libUrl); return json_decode($result,true); } } } $lib = new Lib(); echo $lib->run();