check_password($_POST["userid"],$_POST["password"])){
if(isset($_POST["server"])){
#本地登录
setcookie ( "sync_userid" , $_POST["userid"] , 0 , "/" , "" , false , true );
setcookie ( "sync_server" , $_POST["server"] , 0 , "/" , "" , false , true );
#在远程主机验证用户身份
$phpFile = $_POST["server"]."/app/sync/login.php";
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', $phpFile,['verify' => false,'form_params'=>['userid'=>$_POST["userid"],'password'=>$_POST["password"]]]);
$serveMsg=(string)$response->getBody();
$arrServerMsg = json_decode($serveMsg,true);
if($arrServerMsg["error"]==0){
#验证成功
$redis->hset("sync://key",$_POST["userid"],$arrServerMsg["key"]);
$output["message"]="本机登录成功
服务器验证成功:msg:".$serveMsg."
";
$output["message"].="开始同步";
}
else{
#验证失败
$output["error"]=$arrServerMsg["error"];
$output["message"]="本机登录成功
服务器验证失败".$arrServerMsg["message"];
$output["message"]=$arrServerMsg["message"];
}
echo json_encode($output, JSON_UNESCAPED_UNICODE);
}
else{
#服务器登录成功
$key=UUID::v4();
$redis->hset("sync://key",$_POST["userid"],$key);
$output["error"]=0;
$output["message"]="服务器登录成功";
$output["key"]=$key;
echo json_encode($output, JSON_UNESCAPED_UNICODE);
}
}
else{
$output["error"]=1;
$output["message"]="不正确的用户名或密码";
echo json_encode($output, JSON_UNESCAPED_UNICODE);
}
}
else{
$output["error"]=2;
$output["message"]="参数错误";
echo json_encode($output, JSON_UNESCAPED_UNICODE);
}
?>