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; return $transformedData; } 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" ] ]); return $response; // 获取 API 响应的 JSON 数据 $data = json_decode($response->getBody(), true); // 对数据进行重组,这里只是一个示例,具体根据实际需求调整 $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; } return $transformedData; } }