| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?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);
- 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 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"
- ]
- ]);
- 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;
- }
- }
|