set_charging_action.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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['isBilling'] = (int)$_POST['isBilling'];
  46. // $json['Currency'] = (int)$_POST['Currency'];
  47. // $json['Fee0'] = isset($_POST['Fee0'])?round($_POST['Fee0'], 2):"";
  48. // $json['Fee1'] = isset($_POST['Fee1'])?round($_POST['Fee1'], 2):"";
  49. // $json['Fee2'] = isset($_POST['Fee2'])?round($_POST['Fee2'], 2):"";
  50. // $json['Fee3'] = isset($_POST['Fee3'])?round($_POST['Fee3'], 2):"";
  51. // $json['Fee4'] = isset($_POST['Fee4'])?round($_POST['Fee4'], 2):"";
  52. // $json['Fee5'] = isset($_POST['Fee5'])?round($_POST['Fee5'], 2):"";
  53. // $json['Fee6'] = isset($_POST['Fee6'])?round($_POST['Fee6'], 2):"";
  54. // $json['Fee7'] = isset($_POST['Fee7'])?round($_POST['Fee7'], 2):"";
  55. // $json['Fee8'] = isset($_POST['Fee8'])?round($_POST['Fee8'], 2):"";
  56. // $json['Fee9'] = isset($_POST['Fee9'])?round($_POST['Fee9'], 2):"";
  57. // $json['Fee10'] = isset($_POST['Fee10'])?round($_POST['Fee10'], 2):"";
  58. // $json['Fee11'] = isset($_POST['Fee11'])?round($_POST['Fee11'], 2):"";
  59. // $json['Fee12'] = isset($_POST['Fee12'])?round($_POST['Fee12'], 2):"";
  60. // $json['Fee13'] = isset($_POST['Fee13'])?round($_POST['Fee13'], 2):"";
  61. // $json['Fee14'] = isset($_POST['Fee14'])?round($_POST['Fee14'], 2):"";
  62. // $json['Fee15'] = isset($_POST['Fee15'])?round($_POST['Fee15'], 2):"";
  63. // $json['Fee16'] = isset($_POST['Fee16'])?round($_POST['Fee16'], 2):"";
  64. // $json['Fee17'] = isset($_POST['Fee17'])?round($_POST['Fee17'], 2):"";
  65. // $json['Fee18'] = isset($_POST['Fee18'])?round($_POST['Fee18'], 2):"";
  66. // $json['Fee19'] = isset($_POST['Fee19'])?round($_POST['Fee19'], 2):"";
  67. // $json['Fee20'] = isset($_POST['Fee20'])?round($_POST['Fee20'], 2):"";
  68. // $json['Fee21'] = isset($_POST['Fee21'])?round($_POST['Fee21'], 2):"";
  69. // $json['Fee22'] = isset($_POST['Fee22'])?round($_POST['Fee22'], 2):"";
  70. // $json['Fee23'] = isset($_POST['Fee23'])?round($_POST['Fee23'], 2):"";
  71. // ob_start();
  72. shell_exec('sync;sync;sync');
  73. chdir("/root");
  74. $str_json=json_encode($json);
  75. exec("'./WebService' '2' '".$str_json."'",$output,$return_var);
  76. if(count($output)!=0){
  77. $jsone['result'] = "Success";
  78. $jsone['message'] = $json;
  79. echo json_encode($jsone);
  80. exit;
  81. }
  82. else{
  83. $jsone['result'] = "Error";
  84. $jsone['message'] = "Something went wrong on machine";
  85. echo json_encode($jsone);
  86. return false;
  87. exit;
  88. }
  89. // ob_end_clean();
  90. }
  91. function checkMaxValue($id){
  92. if($_POST[$id] != ""){
  93. if(!is_numeric($_POST[$id])){
  94. $jsone['result'] = "Fail";
  95. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  96. echo json_encode($jsone);
  97. exit;
  98. }
  99. if($_POST[$id]>65535){
  100. $jsone['result'] = "Fail";
  101. $jsone['message'] = "You have entered a over value on " . $id . ", it should be less than 65535";
  102. echo json_encode($jsone);
  103. exit;
  104. }
  105. if($_POST[$id]<0){
  106. $jsone['result'] = "Fail";
  107. $jsone['message'] = "You have entered a over value on " . $id . ", it should be more than 0";
  108. echo json_encode($jsone);
  109. exit;
  110. }
  111. }
  112. }
  113. function checkValue($id){
  114. if($_POST[$id] != ""){
  115. if(strlen($_POST[$id])!=1){
  116. $jsone['result'] = "Fail";
  117. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  118. echo json_encode($jsone);
  119. exit;
  120. }
  121. if(!ereg("[0-9]",$_POST[$id])){
  122. $jsone['result'] = "Fail";
  123. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  124. echo json_encode($jsone);
  125. exit;
  126. }
  127. }
  128. }
  129. function checkLength($id){
  130. if($_POST[$id] != ""){
  131. if(strlen($_POST[$id])>32){
  132. $jsone['result'] = "Fail";
  133. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be less than 32 bytes";
  134. echo json_encode($jsone);
  135. exit;
  136. }
  137. }
  138. }
  139. ?>