client = new Client(); } public function getApiData($apiUrl, $queryParams='') { // 发送 HTTP GET 请求 $response = $this->client->get($apiUrl, [ 'query' => $queryParams, // 可以添加其他选项,如 headers、auth 等 ]); // 获取 API 响应的 JSON 数据 $data = json_decode($response->getBody(), true); return $data; } // 获取实时数据 public function postPointRealData($apiUrl, $pointIds) { // 发送 HTTP POST 请求 $response = $this->client->post($apiUrl, [ 'headers' => [ 'Authorization' => 'Bearer appkey_100100', 'Content-Type'=>'application/json; charset=utf-8', // 其他头部信息 ], 'json' =>[ 'PageNum'=>"-1", 'PointIds' => $pointIds ] ]); // 获取 API 响应的 JSON 数据 $res = json_decode($response->getBody(), true); if($res['IsSuccessful'] == 0) { return $res; } $data = isset($res['Data'])? $res['Data']: null; $transformedData['data'] = $this->transformData($data); $transformedData['IsSuccessful'] =1; $this->rawData = $data; return $transformedData; } // 获取历史数据 public function postDcsHisData($pointIds, $startTime, $endTime) { $apiUrl = "http://7.250.4.3:4200/v1/common/GetPointDataFromInfluxDB"; // 发送 HTTP POST 请求 $response = $this->client->post($apiUrl, [ 'headers' => [ 'Authorization' => 'Bearer appkey_100100', 'Content-Type'=>'application/json; charset=utf-8', // 其他头部信息 ], 'json' =>[ 'IDs' => $pointIds, 'StartTime' => $startTime, 'EndTime' => $endTime ] ]); // 获取 API 响应的 JSON 数据 $res = json_decode($response->getBody(), true); if($res['IsSuccessful'] == 0) { return $res; } $data = isset($res['Data'])? $res['Data']: null; return $data; } public function postApiData($apiUrl, $postData = '') { // 发送 HTTP POST 请求 $response = $this->client->post($apiUrl, $postData); // 发送 HTTP POST 请求 $response = $this->client->post($apiUrl, [ 'headers' => [ 'Authorization' => 'Bearer appkey_100100', 'Content-Type'=>'application/json; charset=utf-8', // 其他头部信息 ], 'json' =>[ 'PageNum'=>"-1" ] ]); // 获取 API 响应的 JSON 数据 $data = json_decode($response->getBody(), true); return $data; // 对数据进行重组,这里只是一个示例,具体根据实际需求调整 $transformedData = $this->transformData($data); return $transformedData; } protected function transformData($data) { $transformedData=[]; for ($i = 0; $i < count($data); $i++) { $dic = $data[$i]; $pid = $dic['ID']; $val = $dic['V']; $transformedData[$pid]=$val; $this->rawArr[$pid]=$dic; } return $transformedData; } }