<?php
$message = 'Hello';
$badge = 3;
$sound = 'default';
$development = false;
$payload = array();
$payload['aps'] = array('alert' => $message, 'badge' => intval($badge), 'sound' => $sound);
$payload = json_encode($payload);
$apns_url = NULL;
$apns_cert = NULL;
$apns_port = 2195;
if($development)
{
$apns_url = 'gateway.sandbox.push.apple.com';
$apns_cert = 'pushcert.pem';
}
else
{
$apns_url = 'gateway.push.apple.com';
$apns_cert = 'pushcert.pem';
}
$stream_context = stream_context_create();
stream_context_set_option($stream_context, 'ssl', 'local_cert', $apns_cert);
$apns = stream_socket_client('ssl://' . $apns_url . ':' . $apns_port, $error, $error_string, 2, STREAM_CLIENT_CONNECT, $stream_context);
echo $error;
echo $error_string;
// You will need to put your device tokens into the $device_tokens array yourself
$device_tokens = array();
foreach($device_tokens as $device_token)
{
$apns_message = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $device_token)) . chr(0) . chr(strlen($payload)) . $payload;
fwrite($apns, $apns_message);
}
@socket_close($apns);
@fclose($apns);
?
错误:
警告:stream_socket_client():SSL操作失败,代码为1. OpenSSL错误消息:错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证在/ opt / lampp / htdocs / conductexam / admin / includes / PushTest / iospush1中失败。第29行的php
警告:stream_socket_client():无法在第29行的/opt/lampp/htdocs/conductexam/admin/includes/PushTest/iospush1.php中启用加密
警告:stream_socket_client():无法连接到/opt/lampp/htdocs/conductexam/admin/includes/PushTest/iospush1.php中的ssl://gateway.push.apple.com:2195(未知错误)第29行 0