12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?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() {
- $pattern="/^(ws|wss):\/\/((([0-9]{1,3}\.){3}[0-9]{1,3})|(([a-zA-Z0-9]+(([\-]?[a-zA-Z0-9]+)*\.)+)*[a-zA-Z]{2,}))+/";
- if(!preg_match($pattern, $_POST['OcppServerURL'])){
- $jsone['result'] = "Fail";
- $jsone['message'] = "OcppServerURL format error, fill it with 'ws://' or 'wss://'";
- echo json_encode($jsone);
- return false;
- }
- checkValue("OfflinePolicy");
- // $json = json_decode(file_get_contents("charging.txt"), true);
- // $json = string[];
- $json['BackendConnTimeout'] = (int)$_POST['BackendConnTimeout'];
- $json['OfflinePolicy'] = chr($_POST['OfflinePolicy']);
- $json['OfflineMaxChargeEnergy'] = (int)$_POST['OfflineMaxChargeEnergy'];
- $json['OfflineMaxChargeDuration'] = (int)$_POST['OfflineMaxChargeDuration'];
- // $json['OcppConnStatus'] = $_POST['OcppConnStatus'];
- $json['OcppServerURL'] = $_POST['OcppServerURL'];
- $json['ChargeBoxId'] = $_POST['ChargeBoxId'];
- // var_dump($json);echo "\n\n";
- //echo json_encode($json);
- $jsone['result'] = "Success";
- $jsone['message'] = $json;
- echo json_encode($jsone);
- ob_start();
-
- shell_exec('sync;sync;sync');
- // chdir("/home/phihong/Module_WebService");
- chdir("/root");
- $str_json=json_encode($json);//var_dump($str_json);
- exec("'./WebService' '4' '".$str_json."'",$output,$return_var);
- // copy("/var/www/html/system.dat","/home/phihong/Module_WebService/system.txt");
- ob_end_clean();
- // print_r($output);
- //echo "OK";
- }
- function checkValue($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;
- }
- }
- ?>
|