openDcsOpcAction.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * 会议相关
  4. * 请求地址如:http://oa.test/api.php?m=openmeet&a=test&openkey=fee5efd3a93ca5c6a85b679cde60faa2
  5. */
  6. class openDcsOpcClassAction extends openapiAction
  7. {
  8. public function testAction() {
  9. // $shell = "echo 'success' ";
  10. // $shellExec = shell_exec($shell);
  11. // // var_dump($shellExec);
  12. // if($shellExec){echo 'ok';} else {echo 'error'}
  13. $pids = [
  14. "ns=12380;s=九八零变电所80Z004照明回路_Ia",
  15. "ns=12380;s=九八零变电所5105_IA",
  16. "ns=12380;s=九八零变电所5101_UB",
  17. # 添加其他节点地址...
  18. ];
  19. $pyPath = "/home/python_proj/python_custom_script/zaoquan/dcs/";
  20. $pyFName = "test1.py";
  21. $pyKeyWord = "/usr/bin/python311";
  22. $pidsJson = json_encode($pids);
  23. $command = "$pyKeyWord {$pyPath}{$pyFName}". ' ' . escapeshellarg("{$pidsJson}");
  24. // $output = shell_exec($command);
  25. // return shell_exec($command);
  26. try {
  27. // 调用Python脚本
  28. $output = shell_exec($command);
  29. // 解析Python脚本返回的JSON数据
  30. $data = json_decode($output, true);
  31. $data['a'] = 'aaa';
  32. // 返回JSON格式的数据给前端
  33. header('Content-Type: application/json');
  34. echo json_encode($data);
  35. } catch (Exception $e) {
  36. // 返回错误消息给前端
  37. header('Content-Type: application/json');
  38. echo json_encode(array("error" => $e->getMessage()));
  39. }
  40. }
  41. }