You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

280 lines
11 KiB

<?php
date_default_timezone_set("Asia/Taipei");
function save_log_response($source_flag, $key, $pid, $account, $response_result){
# 儲存紀錄並輸出
#echo date("Y-m-d");
$file_path = "account_log/" . $account . "-" . date("Y-m-d") . ".ini";
$data = $key . ";" . $pid . ";" . date("H:i:s") . "\n";
$fp = fopen($file_path,"a"); # 如果檔案不存在擇嘗試建立再寫入
fwrite($fp, $data);
fclose($fp);
if ($source_flag == "web"){
header("Location: api-account-reply-functions.php?function_list=" . serialize($response_result) .
"&token=" . $response_result["token"]); #請輸入使用者名稱密碼
exit();
}else{
echo json_encode($response_result, JSON_UNESCAPED_UNICODE);
}
/*
if ($source_flag == "app"){
echo json_encode($response_result, JSON_UNESCAPED_UNICODE);
}elseif ($source_flag == "web"){
header("Location: api-account-reply-functions.php?function_list=" . serialize($response_result) .
"&token=" . $response_result["token"]); #請輸入使用者名稱密碼
exit();
}
*/
}
//生成token
function CreateToken($user_id) {
date_default_timezone_set("Asia/Taipei");
$start_time = date("Y-m-d H:i:s");
$end_time = date('Y-m-d H:i:s',strtotime('+24 hour')); #設定24小時
$info = $user_id . '.' . $start_time . '.' . $end_time; //设置token过期时间为一天
$encryption_code = "MASADA!^***";
//根据以上信息信息生成签名(密钥为 SIGNATURE 自定义全局常量)
$signature = hash_hmac('md5', $info, $encryption_code);
//最后将这两部分拼接起来,得到最终的Token字符串
return $token = $info . '.' . $signature;
}
header('Content-type:text/json');
/*
if (isset($_POST["key"])) {
$key = $_POST["key"];
}
if (isset($_POST["pid"])) {
$pid = $_POST["pid"];
}
if (isset($_POST["account"])) {
$account = $_POST["account"];
}
if (isset($_POST["password"])) {
$password = $_POST["password"];
}
*/
/*
$key = $_POST["key"];
$pid = $_POST["pid"];
$account = $_POST["account"];
$password = $_POST["password"];
*/
$key = $_REQUEST["key"];
$pid = $_REQUEST["pid"];
$account = $_REQUEST["account"];
$password = $_REQUEST["password"];
if (isset($_REQUEST["source_flag"])) {
$source_flag = $_REQUEST["source_flag"];
}else{
$source_flag = "app";
}
/*
if (($key == "032580295e2d320b3a258bef473e8w32e0b24431") and ($pid =="pid12345")){
$source_flag="web";
}elseif ($key == "032580295e2d320b3a258bef473e8d32a0c24431"){
$source_flag="app";
}
*/
/*
echo "account: " . $account . "<br>";
echo "password: " . $password . "<br>";
echo "pid: " . $pid . "<br>";
echo "pid: " . $pid . "<br>";
*/
$function_type = array(
"tw" => array(
# 客戶功能
"customer" => array(
"language" => "tw",
"type" => "customer",
"list" => array(
array("name" => "運行狀況", "path" => "https://www.masada.com.tw/app/app-owner-status.php"),
array("name" => "我的帳單", "path" => "https://www.masada.com.tw/app/app-finance-paymentlog.php"),
array("name" => "維修進度", "path" => "https://www.masada.com.tw/app/app-owner-repaircall-list.php"),
array("name" => "故障報修", "path" => "https://www.masada.com.tw/app/app-owner-repaircall.php"),
array("name" => "訊息通知", "path" => "https://www.masada.com.tw/app/app-owner-message.php"),
array("name" => "生產進度", "path" => "https://www.masada.com.tw/app/app-wipproduction.php"),
array("name" => "安裝進度", "path" => "https://www.masada.com.tw/app/app-wipinstallation.php"),
array("name" => "變更密碼", "path" => "https://www.masada.com.tw/app/app-change-pwd.php"),
array("name" => "公司首頁", "path" => "https://www.masada.com.tw/index.html")
),
"note" => "none",
"token" => ""
),
# 保養員功能
"repairer" => array(
"language" => "tw",
"type" => "repairer",
"list" => array(
array("name" => "保養輸入", "path" => "https://www.masada.com.tw/app/app-maintenance.php"),
array("name" => "維修進度", "path" => "https://www.masada.com.tw/app/app-owner-repaircall-list.php"),
array("name" => "配件訂購", "path" => "https://www.masada.com.tw/app/app-products.php"),
array("name" => "發貨進度", "path" => "https://www.masada.com.tw/app/app-productsshipping.php"),
array("name" => "技術專家", "path" => "https://www.masada.com.tw/app/app-support.php"),
array("name" => "即時位置", "path" => "https://www.masada.com.tw/app/app-map-multilocation.php"),
array("name" => "行動打卡", "path" => "https://www.masada.com.tw/app/app-browser_gpslocation.php"),
array("name" => "變更密碼", "path" => "https://www.masada.com.tw/app/app-change-pwd.php"),
array("name" => "公司首頁", "path" => "https://www.masada.com.tw/index.html")
),
"note" => "none",
"token" => ""
),
# 工勘人員功能
"investigation" => array(
"language" => "tw",
"type" => "investigation",
"list" => array(
array("name" => "工勘回報", "path" => "https://www.masada.com.tw/app/app-investigation.php"),
array("name" => "變更密碼", "path" => "https://www.masada.com.tw/app/app-change-pwd.php"),
array("name" => "公司首頁", "path" => "https://www.masada.com.tw/index.html")
),
"note" => "none",
"token" => ""
)
),
"cn" => array(
# 客户功能
"customer" => array(
"language" => "cn",
"type" => "customer",
"list" => array(
array("name" => "运行状况", "path" => "https://www.masada.com.tw/app/app-owner-status.php"),
array("name" => "我的账单", "path" => "https://www.masada.com.tw/app/app-finance-payment.php"),
array("name" => "维修进度", "path" => "https://www.masada.com.tw/app/app-owner-repaircall-list.php"),
array("name" => "故障报修", "path" => "https://www.masada.com.tw/app/app-owner-repaircall.php"),
array("name" => "讯息通知", "path" => "https://www.masada.com.tw/app/app-owner-message.php"),
array("name" => "生产进度", "path" => "https://www.masada.com.tw/app/app-wipproduction.php"),
array("name" => "安装进度", "path" => "https://www.masada.com.tw/app/app-wipinstallation.php"),
array("name" => "变更密码", "path" => "https://www.masada.com.tw/app/app-change-pwd.php"),
array("name" => "公司首页", "path" => "https://www.masada.com.tw/index.html")
),
"note" => "none",
"token" => ""
),
# 保养员功能
"repairer" => array(
"language" => "cn",
"type" => "repairer",
"list" => array(
array("name" => "保养输入", "path" => "https://www.masada.com.tw/app/app-maintenance.php"),
array("name" => "维修进度", "path" => "https://www.masada.com.tw/app/app-owner-repaircall-list.php"),
array("name" => "配件订购", "path" => "https://www.masada.com.tw/app/app-products.php"),
array("name" => "发货进度", "path" => "https://www.masada.com.tw/app/app-productsshipping.php"),
array("name" => "技术专家", "path" => "https://www.masada.com.tw/app/app-support.php"),
array("name" => "实时位置", "path" => "https://www.masada.com.tw/app/app-map-multilocation.php"),
array("name" => "行动打卡", "path" => "https://www.masada.com.tw/app/app-browser_gpslocation.php"),
array("name" => "变更密码", "path" => "https://www.masada.com.tw/app/app-change-pwd.php"),
array("name" => "公司首页", "path" => "https://www.masada.com.tw/index.html")
),
"note" => "none",
"token" => ""
)
)
);
#$response_result = $function_type["tw"]["customer"];
#echo json_encode($response_result, JSON_UNESCAPED_UNICODE);
if (($key != NULL) and ($pid != NULL) and ($account != NULL) and ($password != NULL)) {
#if (($key != NULL) and ($pid != NULL) and ($account != NULL) and ($source_flag != NULL)) {
# 依據帳號判斷權限
require_once "db/database.php"; # 載入db.php來連結資料庫
$data = array(); # 設置一個空陣列來放資料is
$sql = "SELECT * FROM account where ((accountid = '$account') and (pwd = '$password'))"; # sql語法存在變數中
$data = mysqli_query($link,$sql); # 用mysqli_query方法執行(sql語法)將結果存在變數中
foreach($data as $data){
$accounttype = $data['accounttype'];
}
if (strlen($accounttype) != 0){
switch (true){
case ($accounttype == "A"):
$token = CreateToken($account);
$response_result = $function_type["tw"]["customer"];
for ($i=0; $i<count($response_result["list"]); $i++ ) {
$response_result["list"][$i]["path"] = $response_result["list"][$i]["path"] . "?token=" . $token;
}
$response_result["note"] = "success";
$response_result["token"] = $token;
#session_start();//開啟session
#$_SESSION['user_id'] = $account;//將登入名儲存到session中
// 保存并关闭会话
#session_write_close();
#session_commit();
save_log_response($source_flag, $key, $pid, $account, $response_result);
break;
case ($accounttype == "W"):
$token = CreateToken($account);
$response_result = $function_type["tw"]["investigation"];
for ($i=0; $i<count($response_result["list"]); $i++ ) {
$response_result["list"][$i]["path"] = $response_result["list"][$i]["path"] . "?token=" . $token;
}
$response_result["note"] = "success";
$response_result["token"] = $token;
#session_start();//開啟session
#$_SESSION['user_id'] = $account;//將登入名儲存到session中
// 保存并关闭会话
#session_write_close();
#session_commit();
save_log_response($source_flag, $key, $pid, $account,$response_result);
break;
case ($accounttype[0] == "B" || $accounttype == "C" || $accounttype == "D" || $accounttype == "E"):
$token = CreateToken($account);
$response_result = $function_type["tw"]["repairer"];
for ($i=0; $i<count($response_result["list"]); $i++ ) {
$response_result["list"][$i]["path"] = $response_result["list"][$i]["path"] . "?token=" . $token;
}
$response_result["note"] = "success";
$response_result["token"] = $token;
#session_start();//開啟session
#$_SESSION['user_id'] = $account;//將登入名儲存到session中
// 保存并关闭会话
#session_write_close();
#session_commit();
save_log_response($source_flag, $key, $pid, $account,$response_result);
break;
default:
if ($source_flag =="app"){
$response_result["note"] = "4";
echo json_encode($response_result, JSON_UNESCAPED_UNICODE);
}elseif($source_flag =="web"){
header("Location: api-account-send.php?errno=4"); #無使用權限
}
exit();
};
}else{
if ($source_flag =="app"){
$response_result["note"] = "1";
echo json_encode($response_result, JSON_UNESCAPED_UNICODE);
}elseif($source_flag =="web"){
header("Location: api-account-send.php?errno=1"); #使用者名稱或密碼錯誤
}
exit();
}
mysqli_close($link); #代表結束連線
}else{
if ($source_flag =="app"){
$response_result["note"] = "2";
echo json_encode($response_result, JSON_UNESCAPED_UNICODE);
}elseif($source_flag =="web"){
header("Location: api-account-send.php?errno=2"); #請輸入使用者名稱密碼
}
exit();
}
#echo $response_result["list"][0]["path"]