albeebe / PHP-FindMyiPhone

PHP class to locate, play sounds, and lock iOS devices
Other
79 stars 49 forks source link

Help~ My code suddenly not working last night #4

Closed yueshiou closed 7 years ago

yueshiou commented 7 years ago

First of all. Many thanks to you for this code. I use it to make a small business. It was working very well. But it suddenly doesn't work last. and I got a error message :

Can you help me? I have no idea of it.

Error message like this:
[sendapp@localhost www]$ php yue.php 
* About to connect() to fmipmobile.icloud.com port 443 (#0)
*   Trying 17.250.120.77... * connected
* Connected to fmipmobile.icloud.com (17.250.120.77) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using TLS_DHE_RSA_WITH_AES_256_CBC_SHA
* Server certificate:
*   subject: C=US,ST=California,O=Apple Inc.,OU=management:idms.group.506364,CN=*.icloud.com
*   start date: Feb 17 14:45:31 2015 GMT
*   expire date: Mar 18 14:45:31 2017 GMT
*   common name: *.icloud.com
*   issuer: C=US,O=Apple Inc.,OU=Certification Authority,CN=Apple IST CA 2 - G1
* Server auth using Basic with user 'send.sheen@msa.hinet.net'
> POST /fmipservice/device/send.sheen@msa.hinet.net/initClient HTTP/1.1
Authorization: Basic c2VuZC5zaGVlbkBtc2EuaGluZXQubmV0OkRkMjM4MDA1OTQ=
User-Agent: FindMyiPhone/472.1 CFNetwork/711.1.12 Darwin/14.0.0
Host: fmipmobile.icloud.com
Accept: */*
X-Apple-Realm-Support: 1.0
X-Apple-Find-API-Ver: 3.0
X-Apple-AuthScheme: UserIdGuest
Content-Length: 0
Content-Type: application/x-www-form-urlencoded

< HTTP/1.1 200 OK
< Server: AppleHttpServer/3b804a0
< Date: Wed, 11 Jan 2017 03:19:38 GMT
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< X-Responding-Instance: fmipservice:33200503:mr22p32ic-hpaf01182201:7003:16H103:2cc8f06
< X-Responding-Server: mr22p32ic-hpaf01182201_003
< X-Responding-Partition: p32
< Vary: Accept-Encoding
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< Set-Cookie: NSC_q32-gnjqtfswjdf=ffffffff1267a60d45525d5f4f58455e445a4a422d6b;path=/;secure;httponly
< via: icloudedge:hk02p00ic-ztde010711:7401:16G41:Hong Kong
< X-Apple-Request-UUID: be9cd992-8e73-4d05-84f7-977baf9470c9
< access-control-expose-headers: X-Apple-Request-UUID
< access-control-expose-headers: Via
< 
* Connection #0 to host fmipmobile.icloud.com left intact
* Closing connection #0
* getaddrinfo(3) failed for https::80
* Couldn't resolve host 'https:'
* Closing connection #0

php code :

<?PHP

    // This will prevent any errors that occur from potentially displaying your username/password
    error_reporting(0);

    // This should properly display device names that contain special characters
    header("Content-type: text/html; charset=utf-8");

    // Include the FindMyiPhone class
    include ("class.findmyiphone.php");

    // This is where we log in to iCloud
    try {
            $fmi = new FindMyiPhone("send@msa.hinet.net", "~password marked~");
    } catch (Exception $e) {
            print "Error: ".$e->getMessage();
            exit;
    }

    // This will print out all the devices on your account so you can grab the device IDs
    $fmi->printDevices();

    // Find a device that is reporting its location and attempt to get its current location
    foreach ($fmi->devices as $device) {
            if ($device->location->timestamp != "") {
                    // Locate the device
                    $location = $fmi->locate($device->ID);

                    print "Device <B>".$device->ID."</B> is located at <I>".$location->latitude.", ".$location->longitude."</I>";

                    // Play a sound on the device
                    //$fmi->playSound($device->ID, "You've been located!");

                    // Lock the device
                    //$fmi->lostMode($device->ID, "You got locked out", "555-555-5555");

                    break;
            }
    }

?> ~

Hand-E-Food commented 7 years ago

Yeah, I have the same problem. I'm guessing Apple have changed the process. I'm not sure how that's going to work with out-of-date iPhones, however.

Egregius commented 7 years ago

Indeed, Apple_MMe_Host and Apple_MMe_Scope aren't in the headers anymore...

ersan commented 7 years ago

Same here, glad I'm not alone.

xfrostyx commented 7 years ago

It does appear Apple has changed their API structure. As mentioned by EGregius Apple_MMe_Host and Apple_MMe_Scope are not longer in the headers. I've been trying to find out more info about updates to the API. But this would be my first venture into and Apple iCloud API so it's unlikely I'll figure anything out. I used this code regularly so I kind of became reliant on it and its a very clean setup so I like it. Hoping a solution is found soon.

xfrostyx commented 7 years ago

The Lua version for Vera is working already. So there is hope

beinnlora commented 7 years ago

Apparently Apple simplified the API: https://www.domoticz.com/forum/viewtopic.php?f=23&t=13318&start=120

beinnlora commented 7 years ago

Yes, replace instances of

$url = "https://".$this->Apple_MMe_Host."/fmipservice/device/".$this->Apple_MMe_Scope."

with

$url = "https://fmipmobile.icloud.com/fmipservice/device/".$this->username."

see this Pull Request #5 for updated code. Tested working on /initClient and /playSound endpoints, not yet tested /refreshClient or /lostDevice

Hand-E-Food commented 7 years ago

Awesome, that has it working again!

jeffersonblizz commented 7 years ago

Hi I use this part of the q code changed as follows

If (isset ($ headers ['X-Apple-MMe-Host'])) { $ This-> host = $ headers ['X-Apple-MMe-Host']; $ This-> scope = $ headers ['X-Apple-MMe-Scope']; Throw new FindMyiPhoneException (true); } I would change what there in this code?

Follow the link to my complete code http://pastebin.com/FhHQKJF0

beinnlora commented 7 years ago

@Halyspectro referring to your pastebin, I would think something like this would fix:

1) remove that portion of code altogether that is checking for the X-Apple-MMe-Host header returned (lines 76-83). Your $host variable will then not be overwritten with the X-apple_mme_host and will remain at fmipmobile.icloud.com

2) amend line 140 request URL to remove reference to obsolete scope; use the bare host URL you defined on line 11: old: CURLOPT_URL => sprintf("https://%s/fmipservice/device/%s/%s", $this->host, $this->scope, $method),

new: CURLOPT_URL => sprintf("https://%s/fmipservice/device/%s", $this->host, $method),

yueshiou commented 7 years ago

Yes~ Super!! It's working again. My system is back online. Thank you so~ much.

jeffersonblizz commented 7 years ago

Error in

Warning: sprintf(): Too few arguments in FindMyiPhone.php on line 133

Follow the code link after the suggested changes http://pastebin.com/AEncEnfY

Are you aware of the new parameter that I have to send instead of the scope?

beinnlora commented 7 years ago

you don't send anything instead of the scope; the URL is now more simple and you don't need any custom host or scope. You just give it the generic host (fmipmobile.icloud.com) ah, didn't remove the extra %s line 132 should be: CURLOPT_URL => sprintf("https://%s/fmipservice/device/%s", $this->host, $method),