我已经制作了网络服务来使用 curl 向 ios 发送推送通知,我有用于开发的 ck.pem 文件,其中包含证书和 RSA 私钥,并正确引用它。
但每次我调用网络服务时,我都会收到相同的错误 Curl failed: unable to use client certificate (no key found or wrong pass phrase?)
所有相关的解决方案都不起作用,除了使用“stream_context_create”的替代方案,但我想用 curl 和 idk 来做,问题出在哪里。
在我的代码下面找到:
function test_push_to_ios() {
$url = 'https://gateway.sandbox.push.apple.com:2195';
$cert = base_url() . 'backend_includes/ios_cert/ck.pem';
$gcm_ids = array("xxxxxx");
$passphrase = "passphrase";
$message = 'nbad_notification';
$aps = array('alert' => $message, 'sound' => 'default');
$fields = array('device_tokens' => $gcm_ids, 'data' => $message, 'aps' => $aps);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSLCERT, $cert);
//curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $passphrase);
curl_setopt($ch, CURLOPT_SSLKEY, $cert);
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $passphrase);
curl_setopt($ch, CURLOPT_CERTINFO, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
echo json_encode($result);
}