В соответствии с приведенной ниже ссылкой на форум:
https://forums.developer.apple.com/thread/119705, https://forums.developer.apple.com/thread/117754
Я пытаюсь подключиться app- store-connect (https://developer.apple.com/documentation/appstoreconnectapi), используя PHP, но каждый раз получая ошибку ниже:
stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[status] => 401
[code] => NOT_AUTHORIZED
[title] => Authentication credentials are missing or invalid.
[detail] => Provide a properly configured and signed bearer token, and make sure that it has not expired. Learn more about Generating Tokens for API Requests https://developer.apple.com/go/?id=api-generating-tokens
)
)
)
Пожалуйста, проверьте мой код ниже и мою версию php xammp 7.4:
date_default_timezone_set("Asia/Kolkata");
$strKey=file_get_contents("./AuthKey_##########.p8");
$strUrl = "https://api.appstoreconnect.apple.com/v1/users";
$dHeader = array("kid" => "##########", "typ" => "JWT");
$strHeader = json_encode($dHeader);
$strBase64Header = base64url_encode($strHeader);
$dPayLoad = array("iss" => "69a#####-####-####-####-############", "exp"=>time()+1200, "aud"=>"appstoreconnect-v1");
$strPayLoad = json_encode($dPayLoad);
$strBase64PayLoad = base64url_encode($strPayLoad);
$strContent = $strBase64Header . '.' . $strBase64PayLoad;
$strAlgName = "sha256";
$strSignature = base64url_encode(hash_hmac($strAlgName, $strContent, $strKey));
$strToken = $strBase64Header . '.' . $strBase64PayLoad . '.' . $strSignature;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.appstoreconnect.apple.com/v1/users",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer ".$strToken
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
echo "<pre>";
if ($err) {
echo "cURL Error #:" . $err."<br>";
print_r(json_decode($response));
} else {
print_r(json_decode($response));
}
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
Пожалуйста, предоставьте код детали, если я допустил ошибку выше.