set_charging_action.php 7.9 KB

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