| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace Modules\OpcData\Services\zaoquan;
- use GuzzleHttp\Client;
- class ZQDcsApiService
- {
- protected $client;
- public function __construct()
- {
- $this->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);
- // 对数据进行重组,这里只是一个示例,具体根据实际需求调整
- $transformedData = $this->transformData($data);
- return $transformedData;
- }
- public function postPointRealData($apiUrl, $pointIds) {
- // 发送 HTTP POST 请求
- $response = $this->client->post($apiUrl, [
- 'PageNum'=>"-1",
- 'PointIds' => $pointIds,
- ]);
- // 获取 API 响应的 JSON 数据
- $res = json_decode($response->getBody(), true);
- $transformedData = $this->transformData($res);
- return $transformedData;
- }
- // public function postApiData($apiUrl, $postData)
- // {
- // // 发送 HTTP POST 请求
- // $response = $this->client->post($apiUrl, [
- // 'PageNum'=>"-1",
- // 'form_params' => $postData,
- // // 可以添加其他选项,如 headers、auth 等
- // ]);
- //
- // // 获取 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;
- }
- }
|