我正在为Apple设备实现推送通知服务。使用php脚本,仅当php脚本从浏览器中命中时,它才推送通知。当我通过浏览器点击服务器php脚本时,它将通知推送到Apple设备。我的PHP脚本是...
//在Apple设备中发送通知的方法的结尾
function sendNotificationToAppleDevice($token,$message)
{
/////////////////////////////////////////////For apple divice////////////////////////////////
$passphrase='1234';
// Create a stream to the server
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', 'sample.pem');
stream_context_set_option($streamContext, 'ssl', 'passphrase', $passphrase);
$apns = stream_socket_client( 'ssl://gateway.sandbox.push.apple.com:2195', $error,$errorString,60,STREAM_CLIENT_CONNECT, $streamContext);
// You can access the errors using the variables $error and $errorString
// Now we need to create JSON which can be sent to APNS
$inc=0;
$load = array(
'aps' => array(
'alert' => $message,
'badge' =>$inc,
)
);
$inc++;
$payload = json_encode($load);
// The payload needs …Run Code Online (Sandbox Code Playgroud)