set_charging_action.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. checkMaxValue("MaxChargingSoc");
  29. checkValue("StopChargingByButton");
  30. if(substr($_POST['ModelName'],0,1)=="A" && $_POST['MaxChargingCurrent']<6 && $_POST['MaxChargingCurrent']!=0){
  31. $jsone['result'] = "Fail";
  32. $jsone['message'] = "MaxChargingCurrent must > 6";
  33. echo json_encode($jsone);
  34. exit;
  35. }
  36. if(isset($_POST['MaxChargingEnergy'])){
  37. $json['MaxChargingEnergy'] = (int)$_POST['MaxChargingEnergy'];
  38. }
  39. if(isset($_POST['MaxChargingPower'])){
  40. $json['MaxChargingPower'] = (int)$_POST['MaxChargingPower'];
  41. }
  42. if(isset($_POST['MaxChargingCurrent'])){
  43. $json['MaxChargingCurrent'] = (int)$_POST['MaxChargingCurrent'];
  44. }
  45. if(isset($_POST['AcMaxChargingCurrent'])){
  46. $json['AcMaxChargingCurrent'] = (int)$_POST['AcMaxChargingCurrent'];
  47. }
  48. if(isset($_POST['MaxChargingDuration'])){
  49. $json['MaxChargingDuration'] = (int)$_POST['MaxChargingDuration'];
  50. }
  51. if(isset($_POST['MaxChargingSoc'])){
  52. $json['MaxChargingSoc'] = (int)$_POST['MaxChargingSoc'];
  53. }
  54. if(isset($_POST['StopChargingByButton'])){
  55. $json['StopChargingByButton'] = (int)$_POST['StopChargingByButton'];
  56. }
  57. if(isset($_POST['LocalWhiteCard0'])){
  58. $json['LocalWhiteCard0'] = isset($_POST['LocalWhiteCard0'])?$_POST['LocalWhiteCard0']:"";
  59. }
  60. if(isset($_POST['LocalWhiteCard1'])){
  61. $json['LocalWhiteCard1'] = isset($_POST['LocalWhiteCard1'])?$_POST['LocalWhiteCard1']:"";
  62. }
  63. if(isset($_POST['LocalWhiteCard2'])){
  64. $json['LocalWhiteCard2'] = isset($_POST['LocalWhiteCard2'])?$_POST['LocalWhiteCard2']:"";
  65. }
  66. if(isset($_POST['LocalWhiteCard3'])){
  67. $json['LocalWhiteCard3'] = isset($_POST['LocalWhiteCard3'])?$_POST['LocalWhiteCard3']:"";
  68. }
  69. if(isset($_POST['LocalWhiteCard4'])){
  70. $json['LocalWhiteCard4'] = isset($_POST['LocalWhiteCard4'])?$_POST['LocalWhiteCard4']:"";
  71. }
  72. if(isset($_POST['LocalWhiteCard5'])){
  73. $json['LocalWhiteCard5'] = isset($_POST['LocalWhiteCard5'])?$_POST['LocalWhiteCard5']:"";
  74. }
  75. if(isset($_POST['LocalWhiteCard6'])){
  76. $json['LocalWhiteCard6'] = isset($_POST['LocalWhiteCard6'])?$_POST['LocalWhiteCard6']:"";
  77. }
  78. if(isset($_POST['LocalWhiteCard7'])){
  79. $json['LocalWhiteCard7'] = isset($_POST['LocalWhiteCard7'])?$_POST['LocalWhiteCard7']:"";
  80. }
  81. if(isset($_POST['LocalWhiteCard8'])){
  82. $json['LocalWhiteCard8'] = isset($_POST['LocalWhiteCard8'])?$_POST['LocalWhiteCard8']:"";
  83. }
  84. if(isset($_POST['LocalWhiteCard9'])){
  85. $json['LocalWhiteCard9'] = isset($_POST['LocalWhiteCard9'])?$_POST['LocalWhiteCard9']:"";
  86. }
  87. if(isset($_POST['isBilling'])){
  88. $json['isBilling'] = (int)$_POST['isBilling'];
  89. }
  90. if(isset($_POST['Currency'])){
  91. $json['Currency'] = (int)$_POST['Currency'];
  92. }
  93. if(isset($_POST['Fee0'])){
  94. $json['Fee0'] = isset($_POST['Fee0'])?round($_POST['Fee0'], 2):"";
  95. }
  96. if(isset($_POST['Fee1'])){
  97. $json['Fee1'] = isset($_POST['Fee1'])?round($_POST['Fee1'], 2):"";
  98. }
  99. if(isset($_POST['Fee2'])){
  100. $json['Fee2'] = isset($_POST['Fee2'])?round($_POST['Fee2'], 2):"";
  101. }
  102. if(isset($_POST['Fee3'])){
  103. $json['Fee3'] = isset($_POST['Fee3'])?round($_POST['Fee3'], 2):"";
  104. }
  105. if(isset($_POST['Fee4'])){
  106. $json['Fee4'] = isset($_POST['Fee4'])?round($_POST['Fee4'], 2):"";
  107. }
  108. if(isset($_POST['Fee5'])){
  109. $json['Fee5'] = isset($_POST['Fee5'])?round($_POST['Fee5'], 2):"";
  110. }
  111. if(isset($_POST['Fee6'])){
  112. $json['Fee6'] = isset($_POST['Fee6'])?round($_POST['Fee6'], 2):"";
  113. }
  114. if(isset($_POST['Fee7'])){
  115. $json['Fee7'] = isset($_POST['Fee7'])?round($_POST['Fee7'], 2):"";
  116. }
  117. if(isset($_POST['Fee8'])){
  118. $json['Fee8'] = isset($_POST['Fee8'])?round($_POST['Fee8'], 2):"";
  119. }
  120. if(isset($_POST['Fee9'])){
  121. $json['Fee9'] = isset($_POST['Fee9'])?round($_POST['Fee9'], 2):"";
  122. }
  123. if(isset($_POST['Fee10'])){
  124. $json['Fee10'] = isset($_POST['Fee10'])?round($_POST['Fee10'], 2):"";
  125. }
  126. if(isset($_POST['Fee11'])){
  127. $json['Fee11'] = isset($_POST['Fee11'])?round($_POST['Fee11'], 2):"";
  128. }
  129. if(isset($_POST['Fee12'])){
  130. $json['Fee12'] = isset($_POST['Fee12'])?round($_POST['Fee12'], 2):"";
  131. }
  132. if(isset($_POST['Fee13'])){
  133. $json['Fee13'] = isset($_POST['Fee13'])?round($_POST['Fee13'], 2):"";
  134. }
  135. if(isset($_POST['Fee14'])){
  136. $json['Fee14'] = isset($_POST['Fee14'])?round($_POST['Fee14'], 2):"";
  137. }
  138. if(isset($_POST['Fee15'])){
  139. $json['Fee15'] = isset($_POST['Fee15'])?round($_POST['Fee15'], 2):"";
  140. }
  141. if(isset($_POST['Fee16'])){
  142. $json['Fee16'] = isset($_POST['Fee16'])?round($_POST['Fee16'], 2):"";
  143. }
  144. if(isset($_POST['Fee17'])){
  145. $json['Fee17'] = isset($_POST['Fee17'])?round($_POST['Fee17'], 2):"";
  146. }
  147. if(isset($_POST['Fee18'])){
  148. $json['Fee18'] = isset($_POST['Fee18'])?round($_POST['Fee18'], 2):"";
  149. }
  150. if(isset($_POST['Fee19'])){
  151. $json['Fee19'] = isset($_POST['Fee19'])?round($_POST['Fee19'], 2):"";
  152. }
  153. if(isset($_POST['Fee20'])){
  154. $json['Fee20'] = isset($_POST['Fee20'])?round($_POST['Fee20'], 2):"";
  155. }
  156. if(isset($_POST['Fee21'])){
  157. $json['Fee21'] = isset($_POST['Fee21'])?round($_POST['Fee21'], 2):"";
  158. }
  159. if(isset($_POST['Fee22'])){
  160. $json['Fee22'] = isset($_POST['Fee22'])?round($_POST['Fee22'], 2):"";
  161. }
  162. if(isset($_POST['Fee23'])){
  163. $json['Fee23'] = isset($_POST['Fee23'])?round($_POST['Fee23'], 2):"";
  164. }
  165. // ob_start();
  166. shell_exec('sync;sync;sync');
  167. chdir("/root");
  168. $str_json=json_encode($json);
  169. exec("'./WebService' '2' '".$str_json."'",$output,$return_var);
  170. if(count($output)!=0){
  171. $jsone['result'] = "Success";
  172. $jsone['message'] = $json;
  173. echo json_encode($jsone);
  174. exit;
  175. }
  176. else{
  177. $jsone['result'] = "Error";
  178. $jsone['message'] = "Something went wrong on machine";
  179. echo json_encode($jsone);
  180. return false;
  181. exit;
  182. }
  183. // ob_end_clean();
  184. }
  185. function checkMaxValue($id){
  186. if($_POST[$id] != ""){
  187. if(!is_numeric($_POST[$id])){
  188. $jsone['result'] = "Fail";
  189. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  190. echo json_encode($jsone);
  191. exit;
  192. }
  193. if($_POST[$id]>65535){
  194. $jsone['result'] = "Fail";
  195. $jsone['message'] = "You have entered a over value on " . $id . ", it should be less than 65535";
  196. echo json_encode($jsone);
  197. exit;
  198. }
  199. if($_POST[$id]<0){
  200. $jsone['result'] = "Fail";
  201. $jsone['message'] = "You have entered a over value on " . $id . ", it should be more than 0";
  202. echo json_encode($jsone);
  203. exit;
  204. }
  205. }
  206. }
  207. function checkValue($id){
  208. if($_POST[$id] != ""){
  209. if(strlen($_POST[$id])!=1){
  210. $jsone['result'] = "Fail";
  211. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  212. echo json_encode($jsone);
  213. exit;
  214. }
  215. if(!is_numeric($_POST[$id])){
  216. $jsone['result'] = "Fail";
  217. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
  218. echo json_encode($jsone);
  219. exit;
  220. }
  221. }
  222. }
  223. function checkLength($id){
  224. if($_POST[$id] != ""){
  225. if(strlen($_POST[$id])>32){
  226. $jsone['result'] = "Fail";
  227. $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be less than 32 bytes";
  228. echo json_encode($jsone);
  229. exit;
  230. }
  231. }
  232. }
  233. ?>