I wanna generate code to identify unique iOS device with server side php code. unable to get the right response from api.
I'm getting 200 http response but getting "Missing or incorrectly formatted device token payload"
<?php
require_once "vendor/autoload.php";
use Zenstruck\JWT\Token;
use Zenstruck\JWT\Signer\OpenSSL\ECDSA\ES256;
use \Ramsey\Uuid\Uuid;
$deviceToken = (isset($_POST["deviceToken"]) ? $_POST["deviceToken"] : null);
$transId = (isset($_POST["transId"]) ? $_POST["transId"] : null);
function generateJWT($teamId1, $keyId1, $privateKeyFilePath1) {
$tt = time();
$payload = [
"iss" => $teamId1,
"iat" => $tt
];
$header = [
"alg" => "ES256",
"kid" => $keyId1
];
$token = new Token($payload, $header);
return (string)$token->sign(new ES256(), $privateKeyFilePath1);
}
function postReq($url, $jwt, $bodyArray) {
$body = json_encode($bodyArray);
$header = array('Authorization: Bearer '.$jwt,
'Content-Type: application/json',
'Content-Length: '.strlen($body)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body); //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$server_output = curl_exec($ch);
curl_close($ch);
return $server_output;
}
$teamId = "####";
$keyId = "####";
$privateKeyFilePath = "AuthKey_4A34ER43.p8";
$jwt = generateJWT($teamId, $keyId, $privateKeyFilePath);
// $body = [
// "device_token" => $deviceToken,
// "transaction_id" => $transId,
// "timestamp" => ceil(microtime(true)*1000)
// ];
$ttt = ceil(microtime(true)*1000);
$body = array('device_token' => $deviceToken,'timestamp' => $ttt,'transaction_id' => $transId);
//$body1 = json_encode($body);
$myjsonis = postReq("https://api.development.devicecheck.apple.com/v1/query_two_bits", $jwt, $body);
//print_r($myjsonis);
echo $myjsonis;
?>
I expected the result "{"bit0":true,"bit1":false,"last_update_time":"2017-06"}" but getting the error "Missing or incorrectly formatted device token payload" with response code 200.