ZQDcsApiService.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Modules\OpcData\Services\zaoquan;
  3. use GuzzleHttp\Client;
  4. class ZQDcsApiService
  5. {
  6. protected $client;
  7. public function __construct()
  8. {
  9. $this->client = new Client();
  10. }
  11. public function getApiData($apiUrl, $queryParams)
  12. {
  13. // 发送 HTTP GET 请求
  14. $response = $this->client->get($apiUrl, [
  15. 'query' => $queryParams,
  16. // 可以添加其他选项,如 headers、auth 等
  17. ]);
  18. // 获取 API 响应的 JSON 数据
  19. $data = json_decode($response->getBody(), true);
  20. // 对数据进行重组,这里只是一个示例,具体根据实际需求调整
  21. $transformedData = $this->transformData($data);
  22. return $transformedData;
  23. }
  24. public function postPointRealData($apiUrl, $pointIds) {
  25. // 发送 HTTP POST 请求
  26. $response = $this->client->post($apiUrl, [
  27. 'PageNum'=>"-1",
  28. 'PointIds' => $pointIds,
  29. ]);
  30. // 获取 API 响应的 JSON 数据
  31. $res = json_decode($response->getBody(), true);
  32. $transformedData = $this->transformData($res);
  33. return $transformedData;
  34. }
  35. // public function postApiData($apiUrl, $postData)
  36. // {
  37. // // 发送 HTTP POST 请求
  38. // $response = $this->client->post($apiUrl, [
  39. // 'PageNum'=>"-1",
  40. // 'form_params' => $postData,
  41. // // 可以添加其他选项,如 headers、auth 等
  42. // ]);
  43. //
  44. // // 获取 API 响应的 JSON 数据
  45. // $data = json_decode($response->getBody(), true);
  46. //
  47. // // 对数据进行重组,这里只是一个示例,具体根据实际需求调整
  48. // $transformedData = $this->transformData($data);
  49. //
  50. // return $transformedData;
  51. // }
  52. protected function transformData($data)
  53. {
  54. $transformedData=[];
  55. for ($i = 0; $i < count($data); $i++) {
  56. $dic = $data[$i];
  57. $pid = $dic['ID'];
  58. $val = $dic['V'];
  59. $transformedData[$pid]=$val;
  60. }
  61. return $transformedData;
  62. }
  63. }