CloudKit服务器到服务器和PHP

CloudKit服务器到服务器和PHP,php,cloudkit,cloudkit-web-services,server-to-server,Php,Cloudkit,Cloudkit Web Services,Server To Server,以下PHP代码在开发环境中工作正常,但在生产环境中返回错误: {“uuid”:“xxxxx”,“serverErrorCode”:“身份验证失败”,“原因”:“身份验证失败”} 有什么想法吗 function cloudKitRequest($requestType, $jsonbody) { $KEY_ID = '97659598759875987508750875087087608785987585985'; $CONTAINER

以下PHP代码在开发环境中工作正常,但在生产环境中返回错误:

{“uuid”:“xxxxx”,“serverErrorCode”:“身份验证失败”,“原因”:“身份验证失败”}

有什么想法吗

function cloudKitRequest($requestType, $jsonbody)
{
    $KEY_ID                 = '97659598759875987508750875087087608785987585985';
    $CONTAINER              = 'xyz.zz.zzyyxx.xyz';
    $PRIVATE_PEM_LOCATION   = 'eckey.pem';
    //$Environment            = 'development';
    $Environment            = 'production';
    $dbtype                 = 'public';
    $result                 = NULL;


    $url = 'https://api.apple-cloudkit.com/database/1/' . $CONTAINER . '/'. $Environment . '/' . $dbtype . '/records/'.$requestType;

    // Set cURL
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);

    // Create signature
    date_default_timezone_set('UTC');
    $explode_date = explode('+', date("c", time()));
    $time = $explode_date[0] . 'Z';
    $signature = $time . ":" . base64_encode(hash("sha256", $jsonbody, true)) . ":" . explode('cloudkit.com', $url)[1];
    // Get private key
    $pkeyid = openssl_pkey_get_private("file://" . $PRIVATE_PEM_LOCATION);
    // Sign signature with private key
    if(openssl_sign($signature, $signed_signature, $pkeyid, "sha256WithRSAEncryption")) {
        openssl_free_key($pkeyid);
        // Set headers
        curl_setopt($ch, CURLOPT_HTTPHEADER,
                    [
                    "Content-Type: text/plain",
                    "X-Apple-CloudKit-Request-KeyID: " . $KEY_ID,
                    "X-Apple-CloudKit-Request-ISO8601Date: " . $time,
                    "X-Apple-CloudKit-Request-SignatureV1: " . base64_encode($signed_signature),
                    ]
                    );
        // Set body
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonbody);
        // Send the request & save response to $resp
        $resp = curl_exec($ch);
        if($resp === false) {
            die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
        } else {
            //echo $resp;
            // $result = json_decode($resp, true);
            $result = $resp;
        }
        curl_close($ch);
    } else {
        while ($msg = openssl_error_string()) {
            echo $msg . "<br />\n";
        }
    }
    return $result;
}
函数cloudKitRequest($requestType,$jsonbody)
{
$KEY_ID='976595987598759875087508750870876087885987585985';
$CONTAINER='xyz.zz.zzyyxx.xyz';
$PRIVATE_PEM_LOCATION='eckey.PEM';
//$Environment=‘开发’;
$Environment=‘生产’;
$dbtype='public';
$result=NULL;
$url='1https://api.apple-cloudkit.com/database/1/“.$CONTAINER./.$Environment./.$dbtype./records/.$requestType;
//卷曲
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,'POST');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
//创建签名
日期\默认\时区\设置('UTC');
$explode_date=explode(“+”,date(“c”,time());
$time=$explode_date[0]。'Z';
$signature=$time.:“.base64_编码(散列(“sha256”,“jsonbody,true))。:”.explode('cloudkit.com',$url)[1];
//获取私钥
$pkeyid=openssl\u pkey\u get\u private(“文件:/”$private\u PEM\u位置);
//用私钥签名
if(openssl_-sign($signature,$signed_-signature,$pkeyid,“sha256withrsa加密”)){
openssl免费密钥($pkeyid);
//设置标题
curl_setopt($ch,CURLOPT_HTTPHEADER,
[
“内容类型:文本/普通”,
“X-Apple-CloudKit-Request-KeyID:”.$KEY\u ID,
“X-Apple-CloudKit-Request-ISO8601Date:”.$time,
“X-Apple-CloudKit-Request-SignatureV1:”.base64_编码($signed_签名),
]
);
//集合体
卷曲设置($ch,卷曲设置桩,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$jsonbody);
//将请求和保存响应发送到$resp
$resp=curl_exec($ch);
如果($resp==false){
die('Error:'.curl_Error($ch)。'-Code:'.curl_errno($ch));
}否则{
//echo$resp;
//$result=json_decode($resp,true);
$result=$resp;
}
卷曲关闭($ch);
}否则{
而($msg=openssl\u error\u string()){
echo$msg。“
\n”; } } 返回$result; }

有什么想法吗?

两个环境是否有相同的证书?您无法进行身份验证,因此似乎没有为生产提交正确的凭据。您是对的,谢谢两个环境是否具有相同的证书?您无法进行身份验证,因此您似乎没有为生产提交正确的凭据。您是对的,谢谢