2

我想生成代码来识别具有服务器端 php 代码的唯一 iOS 设备。无法从 api 获得正确的响应。

我收到 200 个 http 响应,但收到“缺少或格式错误的设备令牌有效负载”

<?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;


?>

我预计结果“{“bit0”:true,“bit1”:false,“last_update_time”:“2017-06”}”但收到错误“缺少或格式错误的设备令牌有效负载”,响应代码为200。

4

0 回答 0