openDcsApiAction.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * 会议相关
  4. * 请求地址如:oa.test/api.php?m=openTest&a=dcs_door&openkey=d9302364e2a2d9fdcab2707a46fbab5a&staff_num=123456
  5. */
  6. class openDcsApiClassAction 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. public function dcs_doorAction() {
  42. $rawArr = $this->getpostarr();
  43. $groupArr = m("dcs_group")->getall("1=1 and is_show=1");
  44. $rowArr = ["nav"=>[]];
  45. $pcon = 0;
  46. for ($i = 0; $i < count($groupArr); $i++) {
  47. $row = $groupArr[$i];
  48. if ($row['pid'] == 0) {
  49. $rowArr["nav"][$pcon] = [
  50. "title"=>$row['name'],
  51. "list"=>[]
  52. ];
  53. for ($j = 0; $j <count($groupArr); $j++) {
  54. $crow = $groupArr[$j];
  55. if ($crow['pid'] == $row['id']) {
  56. $rowArr["nav"][$pcon]["list"][] = [
  57. "icon" => URL.(empty($crow['icon']) ? $row['icon'] : $crow['icon']),
  58. "module"=>$row['key'],
  59. "name"=>$crow['name'],
  60. "sys_code"=>$crow['key'],
  61. ];
  62. }
  63. }
  64. $pcon++;
  65. }
  66. }
  67. return $rowArr;
  68. }
  69. }