【发布时间】:2015-04-18 13:09:58
【问题描述】:
我用过这个php代码
$query = "SELECT * FROM iphone_register";
$result_iphone = mysql_query($query);
$fetres = mysql_num_rows($result_iphone);
while ($rows = mysql_fetch_object($result_iphone)) {
$deviceToken = $rows->device_id;
$passphrase = '******';
$message = 'New Push Notification!';
$badge = 1;
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$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);
}
$body['aps'] = array(
'alert' => 'new notification is arrived',
'body'=> $message,
'badge' => $badge,
'sound' => 'newMessage.wav'
);
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
}
if (!$result) {
echo 'Error, notification not sent' . PHP_EOL;
} else {
echo 'notification sent!' . PHP_EOL;
}
fclose($fp);
当我从服务器向设备发送推送通知时,出现以下错误。
我尝试更改ck.pem 文件以获得解决方案。
但它不起作用。所以我认为ck.pem(Certificate) 文件没有问题。
警告:stream_socket_client():无法连接到 ssl://gateway.sandbox.push.apple.com:2195(连接被拒绝)在 /home/sunstate/public_html/sunstate_api/gcm_message.php 在第 55 行 连接失败:111 连接被拒绝
【问题讨论】:
-
您好,您是在测试开发还是发布?
-
另见“verify error:num=20” when connecting to gateway.sandbox.push.apple.com。您应该确保三件事:(1)TLS 1.0 或更高版本; (2) 服务器名称指示; (3) Entrust.net 证书颁发机构 (2048) 根。
标签: php ios iphone apple-push-notifications