【发布时间】:2013-07-17 11:18:59
【问题描述】:
我正在尝试使用 Api 使用推送通知,但我没有收到任何错误消息,也没有收到任何响应。
我已经检查了Apple Push Notification Service with PHP Script
并相应地在我的代码中应用了更改,但仍然无法正常工作。
我无法获得我必须在其中使用的serverId
$device = 'fbb5a9c71066794d57fee33b4005a89f1bb8941a68660fd6e91f466be1299ab6'; // My iphone deviceToken
$payload['aps'] = array(
'alert' => 'This is the alert text',
'badge' => 1,
'sound' => 'default'
);
$payload['server'] = array(
'serverId' => 1,
'name' => 'keyss.in'
);
$payload = 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);
得到错误:
警告:stream_socket_client():无法连接到 ssl://gateway.sandbox.push.apple.com:2195(连接超时)
警告:fwrite() 期望参数 1 是资源,给定的布尔值
警告:fclose() 期望参数 1 是资源,给定的布尔值
【问题讨论】:
标签: php ios push-notification apple-push-notifications