我目前正在尝试为我的网站编写程序,但我正在尝试自动登录到mojang,这样他们可以更快地迁移,并确保他们的MC帐户是安全的。然而,当我尝试自动登录Mojang进行迁移时,它会给我一个错误:身份验证失败。
我知道其他人尝试过并成功了,但那是用JAVA编码的,我想用HTML做这个。
<form action="https://account.mojang.com/migrate/check" method=POST target=_blank>
<input type="text" name="mcusername">
<input type="text" name="password">
<?php
echo '<input type="hidden" name="authenticityToken" value='.$token.'>';
?>
<input type=submit value="Migrate Account">
</form>
我试着使用我从mojang.com/migrate上获得的代币,使用的代码是:
$file = file_get_contents('https://account.mojang.com/migrate');
function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
$fullstring = $file;
$fullstring = str_replace("/migrate/check", "https://account.mojang.com/migrate/check", $fullstring);
$token = get_string_between($fullstring, '<input type="hidden" name="authenticityToken" value="', '">');
但是,当我按下:迁移帐户时,会返回一个错误。我想我需要用cookie或Auth令牌做点什么。如果你们中有人有想法。。请告诉我
您使用脚本检索的令牌是为您的服务器生成的,而不是为用户提交html表单生成的。您必须使用Javascript获取令牌。
但是
MLHttpRequest cannot load https://account.mojang.com/migrate. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://yourdomain.com' is therefore not allowed access.
所以我认为您将无法使用html/php对客户端进行身份验证。