Push notification is not receiving on device

你说的曾经没有我的故事 提交于 2019-12-20 07:34:58

问题


I am using push notification through PHP script. Code seems to be working fine, it does not give me any error. But notification does not receive me on my device.

Here is my code:

$passphrase = '123';
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'cert.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);
    // Create the payload body
    $body['aps'] = array(
                 'alert' => $message,
                 'sound' => 'default'
                 );
    // Encode the payload as JSON
    $payload = json_encode($body);
    // Build the binary notification
    $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

Can anyone suggest what is wrong in it.


回答1:


try this php code: but you have to change device token and passpharse as you had set. you can download php script from below link

http://d1xzuxjlafny7l.cloudfront.net/downloads/SimplePush.zip

i have run this php script it's works well..



来源:https://stackoverflow.com/questions/32967011/push-notification-is-not-receiving-on-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!