我的PHP脚本有问题。因此,我试图连接到FMI服务器,但是当我输入有效的凭据时,服务器始终返回HTTP代码330,而不是200 OK。另外,当我尝试使用无效的凭据时,它会返回401并且可以,但是为什么我只有有效的凭据才有这个问题? 我尝试过什么?
curl_setopt($ch,CURLOPT_ENCODING , "gzip");
但没有运气:(
这是我的代码:
<?php
$username = "callibra@yandex.ru"; //Valid login
$password = "callibra4App"; //Valid Password
class FMIWebApplication {
private $client = array(
"user-agent" => "FindMyiPhone/472.1 CFNetwork/711.1.12 Darwin/14.0.0",
"headers" => array(
"X-Apple-Realm-Support" => "1.0",
"X-Apple-Find-API-Ver" => "3.0",
"X-Apple-AuthScheme" => "UserIdGuest",
"X-Apple-I-MD-RINFO" => "17106176",
"Accept" => "*/*",
"Connection" => "keep-alive",
"Accept-Encoding" => "br, gzip, deflate",
"Accept-Language" => "en-us",
"X-Apple-I-TimeZone" => "GMT+2",
"X-Apple-I-Locale" => "en_US"
)
);
public $username;
public $password;
public $devices = array();
public function __construct($username, $password) {
$this->username = $username;
$this->password = $password;
$this->authenticate();
}
public function authenticate() {
$url = "https://fmipmobile.icloud.com/fmipservice/device/".$this->username."/initClient";
list($headers, $body) = $this->curlPOST($url, "", $this->username.":".$this->password);
/*
if ($headers["http_code"] == 200) {
return 200;
};
if ($headers["http_code"] == 401) {
return 401;
};
if ($headers["http_code"] == 403) {
return 403;
};*/
echo $headers["http_code"];
}
private function curlPOST($url, $body, $authentication = "") {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $this->client["user-agent"]);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
if (strlen($authentication) > 0) {
curl_setopt($ch, CURLOPT_USERPWD, $authentication);
}
$arrHeaders = array();
$arrHeaders["Content-Length"] = strlen($request);
foreach ($this->client["headers"] as $key=>$value) {
array_push($arrHeaders, $key.": ".$value);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $arrHeaders);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$responseBody = substr($response, $header_size);
$headers = array();
foreach (explode("\r\n", substr($response, 0, $header_size)) as $i => $line) {
if ($i === 0)
$headers['http_code'] = $info["http_code"];
else {
list ($key, $value) = explode(': ', $line);
if (strlen($key) > 0)
$headers[$key] = $value;
}
}
return array($headers, json_decode($responseBody, true));
}
}
$API = new FMIWebApplication($username, $password);
$API->authenticate();
?>
这就是我从服务器上得到的:
HTTP/1.1 330 Server: AppleHttpServer/70a91026 Date: Thu, 07 Mar 2019 13:23:40 GMT Content-Length: 0 Connection: keep-alive X-Responding-Instance: fmipservice:34000504:mr23p40ic-ztdg08174101:7004:1903B41:738abffa X-Responding-Server: mr23p40ic-ztdg08174101_004 X-Responding-Partition: p40 X-Apple-MMe-Host: p40-fmipmobile.icloud.com X-Apple-MMe-Scope: 639524741 Strict-Transport-Security: max-age=31536000; includeSubDomains Set-Cookie: NSC_q40-gnjqtfswjdf=6ad0a3dee1e78d9bd168cb5a7ceafc289128c7a38269b4bddde70dac09e4e273e5f12331;path=/;secure;httponly via: icloudedge:mc10p01ic-zteu01141501:7401:18RC846:Manchester X-Apple-Request-UUID: 8d5dc207-f1f8-453f-8863-9e0d5ab3b58b access-control-expose-headers: X-Apple-Request-UUID access-control-expose-headers: Via 330