123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- // 設置資料類型 json,編碼格式 utf-8
- header('Content-Type: application/json; charset=UTF-8');
-
- // 判斷如果是 GET 請求,則進行搜尋;如果是 POST 請求,則進行新建
- // $_SERVER['REQUEST_METHOD'] 返回訪問頁面使用的請求方法
- if ($_SERVER['REQUEST_METHOD'] == "GET") {
- create();
- } else if ($_SERVER['REQUEST_METHOD'] == "POST") {
- create();
- }
- // 新建員工
- function create() {
- checkLength("LocalWhiteCard0");
- checkLength("LocalWhiteCard1");
- checkLength("LocalWhiteCard2");
- checkLength("LocalWhiteCard3");
- checkLength("LocalWhiteCard4");
- checkLength("LocalWhiteCard5");
- checkLength("LocalWhiteCard6");
- checkLength("LocalWhiteCard7");
- checkLength("LocalWhiteCard8");
- checkLength("LocalWhiteCard9");
- checkMaxValue("MaxChargingEnergy");
- checkMaxValue("MaxChargingPower");
- checkMaxValue("MaxChargingCurrent");
- checkMaxValue("MaxChargingDuration");
- checkValue("PhaseLossPolicy");
- // $json = json_decode(file_get_contents("charging.txt"), true);
- // $json = string[];
- $json['MaxChargingEnergy'] = (int)$_POST['MaxChargingEnergy'];
- $json['MaxChargingPower'] = (int)$_POST['MaxChargingPower'];
- $json['MaxChargingCurrent'] = (int)$_POST['MaxChargingCurrent'];
- $json['MaxChargingDuration'] = (int)$_POST['MaxChargingDuration'];
- $json['PhaseLossPolicy'] = (int)$_POST['PhaseLossPolicy'];
- $json['LocalWhiteCard0'] = isset($_POST['LocalWhiteCard0'])?$_POST['LocalWhiteCard0']:"";
- $json['LocalWhiteCard1'] = isset($_POST['LocalWhiteCard1'])?$_POST['LocalWhiteCard1']:"";
- $json['LocalWhiteCard2'] = isset($_POST['LocalWhiteCard2'])?$_POST['LocalWhiteCard2']:"";
- $json['LocalWhiteCard3'] = isset($_POST['LocalWhiteCard3'])?$_POST['LocalWhiteCard3']:"";
- $json['LocalWhiteCard4'] = isset($_POST['LocalWhiteCard4'])?$_POST['LocalWhiteCard4']:"";
- $json['LocalWhiteCard5'] = isset($_POST['LocalWhiteCard5'])?$_POST['LocalWhiteCard5']:"";
- $json['LocalWhiteCard6'] = isset($_POST['LocalWhiteCard6'])?$_POST['LocalWhiteCard6']:"";
- $json['LocalWhiteCard7'] = isset($_POST['LocalWhiteCard7'])?$_POST['LocalWhiteCard7']:"";
- $json['LocalWhiteCard8'] = isset($_POST['LocalWhiteCard8'])?$_POST['LocalWhiteCard8']:"";
- $json['LocalWhiteCard9'] = isset($_POST['LocalWhiteCard9'])?$_POST['LocalWhiteCard9']:"";
- // $json['CcsAuthentication'] = $_POST['CcsAuthentication'];
- // $json['AcCcsChargingModel'] = $_POST['AcCcsChargingModel'];
-
- // ob_start();
-
- shell_exec('sync;sync;sync');
- chdir("/root");
- $str_json=json_encode($json);
- exec("'./WebService' '2' '".$str_json."'",$output,$return_var);
- if(count($output)!=0){
- $jsone['result'] = "Success";
- $jsone['message'] = $json;
- echo json_encode($jsone);
- exit;
- }
- else{
- $jsone['result'] = "Error";
- $jsone['message'] = "Something went wrong on machine";
- echo json_encode($jsone);
- return false;
- exit;
- }
- // ob_end_clean();
- }
- function checkMaxValue($id){
- if($_POST[$id] != ""){
- if(!is_numeric($_POST[$id])){
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
- echo json_encode($jsone);
- exit;
- }
- if($_POST[$id]>65535){
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered a over value on " . $id . ", it should be less than 65535";
- echo json_encode($jsone);
- exit;
- }
- if($_POST[$id]<0){
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered a over value on " . $id . ", it should be more than 0";
- echo json_encode($jsone);
- exit;
- }
- }
- }
- function checkValue($id){
- if($_POST[$id] != ""){
- if(strlen($_POST[$id])!=1){
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
- echo json_encode($jsone);
- exit;
- }
- if(!ereg("[0-9]",$_POST[$id])){
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be numeric";
- echo json_encode($jsone);
- exit;
- }
- }
- }
- function checkLength($id){
- if($_POST[$id] != ""){
- if(strlen($_POST[$id])>32){
- $jsone['result'] = "Fail";
- $jsone['message'] = "You have entered a wrong value on " . $id . ", it should be less than 32 bytes";
- echo json_encode($jsone);
- exit;
- }
- }
- }
- ?>
|