set_charging_action.php 6.1 KB

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