set_charging_action.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. checkLength("LocalWhiteCard0");
  14. checkLength("LocalWhiteCard1");
  15. checkLength("LocalWhiteCard2");
  16. checkLength("LocalWhiteCard3");
  17. checkLength("LocalWhiteCard4");
  18. checkLength("LocalWhiteCard5");
  19. checkLength("LocalWhiteCard6");
  20. checkLength("LocalWhiteCard7");
  21. checkLength("LocalWhiteCard8");
  22. checkLength("LocalWhiteCard9");
  23. checkMaxValue("MaxChargingEnergy");
  24. checkMaxValue("MaxChargingPower");
  25. checkMaxValue("MaxChargingCurrent");
  26. checkMaxValue("MaxChargingDuration");
  27. checkValue("PhaseLossPolicy");
  28. // $json = json_decode(file_get_contents("charging.txt"), true);
  29. // $json = string[];
  30. $json['MaxChargingEnergy'] = (int)$_POST['MaxChargingEnergy'];
  31. $json['MaxChargingPower'] = (int)$_POST['MaxChargingPower'];
  32. $json['MaxChargingCurrent'] = (int)$_POST['MaxChargingCurrent'];
  33. $json['MaxChargingDuration'] = (int)$_POST['MaxChargingDuration'];
  34. $json['PhaseLossPolicy'] = (int)$_POST['PhaseLossPolicy'];
  35. $json['LocalWhiteCard0'] = isset($_POST['LocalWhiteCard0'])?$_POST['LocalWhiteCard0']:"";
  36. $json['LocalWhiteCard1'] = isset($_POST['LocalWhiteCard1'])?$_POST['LocalWhiteCard1']:"";
  37. $json['LocalWhiteCard2'] = isset($_POST['LocalWhiteCard2'])?$_POST['LocalWhiteCard2']:"";
  38. $json['LocalWhiteCard3'] = isset($_POST['LocalWhiteCard3'])?$_POST['LocalWhiteCard3']:"";
  39. $json['LocalWhiteCard4'] = isset($_POST['LocalWhiteCard4'])?$_POST['LocalWhiteCard4']:"";
  40. $json['LocalWhiteCard5'] = isset($_POST['LocalWhiteCard5'])?$_POST['LocalWhiteCard5']:"";
  41. $json['LocalWhiteCard6'] = isset($_POST['LocalWhiteCard6'])?$_POST['LocalWhiteCard6']:"";
  42. $json['LocalWhiteCard7'] = isset($_POST['LocalWhiteCard7'])?$_POST['LocalWhiteCard7']:"";
  43. $json['LocalWhiteCard8'] = isset($_POST['LocalWhiteCard8'])?$_POST['LocalWhiteCard8']:"";
  44. $json['LocalWhiteCard9'] = isset($_POST['LocalWhiteCard9'])?$_POST['LocalWhiteCard9']:"";
  45. // $json['CcsAuthentication'] = $_POST['CcsAuthentication'];
  46. // $json['AcCcsChargingModel'] = $_POST['AcCcsChargingModel'];
  47. // ob_start();
  48. shell_exec('sync;sync;sync');
  49. chdir("/root");
  50. $str_json=json_encode($json);
  51. exec("'./WebService' '2' '".$str_json."'",$output,$return_var);
  52. if(count($output)!=0){
  53. $jsone['result'] = "Success";
  54. $jsone['message'] = $json;
  55. echo json_encode($jsone);
  56. exit;
  57. }
  58. else{
  59. $jsone['result'] = "Error";
  60. $jsone['message'] = "Something went wrong on machine";
  61. echo json_encode($jsone);
  62. return false;
  63. exit;
  64. }
  65. // ob_end_clean();
  66. }
  67. function checkMaxValue($id){
  68. if($_POST[$id] != ""){
  69. if(!is_numeric($_POST[$id])){
  70. $jsone['result'] = "Fail";
  71. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  72. echo json_encode($jsone);
  73. exit;
  74. }
  75. if($_POST[$id]>65535){
  76. $jsone['result'] = "Fail";
  77. $jsone['message'] = "You have entered a over value on " . $id . ", it should be less than 65535";
  78. echo json_encode($jsone);
  79. exit;
  80. }
  81. if($_POST[$id]<0){
  82. $jsone['result'] = "Fail";
  83. $jsone['message'] = "You have entered a over value on " . $id . ", it should be more than 0";
  84. echo json_encode($jsone);
  85. exit;
  86. }
  87. }
  88. }
  89. function checkValue($id){
  90. if($_POST[$id] != ""){
  91. if(strlen($_POST[$id])!=1){
  92. $jsone['result'] = "Fail";
  93. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  94. echo json_encode($jsone);
  95. exit;
  96. }
  97. if(!ereg("[0-9]",$_POST[$id])){
  98. $jsone['result'] = "Fail";
  99. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  100. echo json_encode($jsone);
  101. exit;
  102. }
  103. }
  104. }
  105. function checkLength($id){
  106. if($_POST[$id] != ""){
  107. if(strlen($_POST[$id])>32){
  108. $jsone['result'] = "Fail";
  109. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be less than 32 bytes";
  110. echo json_encode($jsone);
  111. exit;
  112. }
  113. }
  114. }
  115. ?>