set_backend_action.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. // 設置資料類型 json,編碼格式 utf-8
  3. header('Content-Type: application/json; charset=UTF-8');
  4. // 判斷如果是 GET 請求,則進行搜尋;如果是 POST 請求,則進行新建
  5. // $_SERVER['REQUEST_METHOD'] 返回訪問頁面使用的請求方法
  6. if ($_SERVER['REQUEST_METHOD'] == "GET") {
  7. create();
  8. } else if ($_SERVER['REQUEST_METHOD'] == "POST") {
  9. create();
  10. }
  11. // 新建員工
  12. function create() {
  13. // $json = json_decode(file_get_contents("charging.txt"), true);
  14. // $json = string[];
  15. $json['BackendConnTimeout'] = (int)$_POST['BackendConnTimeout'];
  16. $json['OfflinePolicy'] = $_POST['OfflinePolicy'];
  17. $json['OfflineMaxChargeEnergy'] = (int)$_POST['OfflineMaxChargeEnergy'];
  18. $json['OfflineMaxChargeDuration'] = (int)$_POST['OfflineMaxChargeDuration'];
  19. // $json['OcppConnStatus'] = $_POST['OcppConnStatus'];
  20. $json['OcppServerURL'] = $_POST['OcppServerURL'];
  21. $json['ChargeBoxId'] = $_POST['ChargeBoxId'];
  22. $pattern="/^(ws|wss):\/\/((([0-9]{1,3}\.){3}[0-9]{1,3})|(([a-zA-Z0-9]+(([\-]?[a-zA-Z0-9]+)*\.)+)*[a-zA-Z]{2,}))+/";
  23. if(!preg_match($pattern, $_POST['OcppServerURL'])){
  24. $jsone['result'] = "Fail";
  25. $jsone['message'] = "OcppServerURL format error, fill it with 'ws://' or 'wss://'";
  26. echo json_encode($jsone);
  27. return false;
  28. }
  29. // var_dump($json);echo "\n\n";
  30. //echo json_encode($json);
  31. $jsone['result'] = "Success";
  32. $jsone['message'] = $json;
  33. echo json_encode($jsone);
  34. ob_start();
  35. shell_exec('sync;sync;sync');
  36. // chdir("/home/phihong/Module_WebService");
  37. chdir("/root");
  38. $str_json=json_encode($json);//var_dump($str_json);
  39. exec("'./WebService' '4' '".$str_json."'",$output,$return_var);
  40. // copy("/var/www/html/system.dat","/home/phihong/Module_WebService/system.txt");
  41. ob_end_clean();
  42. // print_r($output);
  43. //echo "OK";
  44. }
  45. ?>