我尝试为 iPhone 发送推送通知。我没有输入密码,因为证书没有它。我将设备令牌 njInRSuzfRLxdCiv8dG9JqRZLvxxTK95HRVYCvPGAUw= 从 Base64 转换为 HEX 但没有收到通知。可能是什么原因?我还收到我连接到 APNS 并成功的消息。正如我告诉我的 iPhone 开发人员的那样,证书是正确的,因为以前它们被用于 PARSE 服务这是我的代码
$deviceToken = '9E3227452BB37D12F17428AFF1D1BD26A4592EFC714CAF791D15580AF3C6014C';
$message = 'TEST!';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
$payload = json_encode($body);
$msg =chr(0).pack('n',32).pack('H*', $deviceToken) . pack('n',strlen($payload)).$payload;
$result = fwrite($fp, $msg);
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
socket_close($fp);
fclose($fp);