Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中为唯一的iOS设备生成jwt时,设备令牌负载丢失或格式不正确_Php_Devicecheck - Fatal编程技术网

在php中为唯一的iOS设备生成jwt时,设备令牌负载丢失或格式不正确

在php中为唯一的iOS设备生成jwt时,设备令牌负载丢失或格式不正确,php,devicecheck,Php,Devicecheck,我想用服务器端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["deviceT

我想用服务器端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的设备令牌负载或其格式不正确。

这不是一个真正快速的问题,因此请删除该标记