openDcsApiAction.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. "id" => $crow['id'],
  58. "icon" => URL.(empty($crow['icon']) ? $row['icon'] : $crow['icon']),
  59. "module"=>$row['key'],
  60. "name"=>$crow['name'],
  61. "sys_code"=>$crow['key'],
  62. ];
  63. }
  64. }
  65. $pcon++;
  66. }
  67. }
  68. return $rowArr;
  69. }
  70. public function dcs_auth_checkAction() {
  71. $staffNum = $this->get('staff_num');
  72. $sys_id = $this->get('sys_id');
  73. if (empty($staffNum) || empty($sys_id)) {
  74. $this->showreturn('', '参数错误!', 201);
  75. }
  76. $uInfo = m("admin")->getone("user='{$staffNum}'");
  77. $checkAuth = m("dcs_auth")->getall("FIND_IN_SET($sys_id, `range`) and FIND_IN_SET({$uInfo['id']}, `user_ids`) ");
  78. // 找到权限
  79. if (!empty($checkAuth) && count($checkAuth) > 0) {
  80. $urlInfo = m("dcs_group")->getone("id={$sys_id}");
  81. $this->showreturn([url=>trim($urlInfo['url'])], '成功!', 200);
  82. } else {
  83. $this->showreturn('', '暂无权限访问,请联系管理员!', 202);
  84. }
  85. }
  86. }