【发布时间】:2010-10-08 13:42:30
【问题描述】:
我正在尝试向我的 iPhone (APNS) 发送推送通知。我读了这个post 并尝试实现它。所以我所有的证书都很好(正常)。
现在我有了这个 php 脚本:
$device = '4f30e047 c8c05db9 3fa87e7d ca5325f7 738cb2c0 0b4a02d4 d4329a42 a7128173'; // My iphone deviceToken
$payload['aps'] = array('alert' => 'This is the alert text', 'badge' => 1, 'sound' => 'default');
$payload['server'] = array('serverId' => $serverId, 'name' => $name);
$output = json_encode($payload);
$apnsCert = 'apple_push_notification_production.pem';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $device)) . chr(0) . chr(strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);
//socket_close($apns); seems to be wrong here ...
fclose($apns);
当我运行这个脚本时,什么都没有发生。没有错误只是一个空白页面,但我的 iPhone 没有收到推送通知...
你有想法吗?
非常感谢!
【问题讨论】:
标签: php iphone notifications push