苹果推送通知 - PHP [英] apple push notification - PHP

查看:65
本文介绍了苹果推送通知 - PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用推送通知时遇到问题,当我使用开发时它可以工作,但是当我想真正使用它时,它不起作用.

CK 是为生产而制造的.

当我使用它时,结果是:消息发送成功但我的手机没有收到消息

$消息,'声音' =>'默认');//将有效负载编码为 JSON$payload = json_encode($body);//构建二进制通知$msg = chr(0) .包('n', 32) .pack('H*', $deviceToken) .pack('n', strlen($payload)) .$有效载荷;//发送到服务器$result = fwrite($fp, $msg, strlen($msg));如果(!$结果)echo '消息未送达'.PHP_EOL;别的echo '消息发送成功'.PHP_EOL;fclose($fp);}?>

谁能看出哪里出了问题?:)

解决方案

APNS

这里面临3种问题<块引用>

  1. 您的设备令牌不匹配
  2. 您的 .pem 不是有效的,原因是 .p12 和 .cer 文件有时已损坏,因此删除 .p12 文件和 .cer 并重新创建一次.
  3. 不是一个有价值的答案,但偶然会发生-- 检查您的设备通知是否ON/OFF

I have a problem when i use push Notification, It works when i use develop, but when i want to use it for real, it won't work.

The ck is made for production.

When i use it, the result is: Message successfully delivered But my phone do not receive the message

<?php

pushNotification('wow2','DeviceToken');

function pushNotification($theMessage, $theDeviceToken)
{

        // Put your device token here (without spaces):
    $deviceToken = $theDeviceToken;     

    // Put your private key's passphrase here:
    $passphrase = 'Code';

    // Put your alert message here:
    $message = $theMessage;

    ////////////////////////////////////////////////////////////////////////////////

    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

    // Open a connection to the APNS server
    $fp = stream_socket_client(
        'ssl://gateway.push.apple.com:2195', $err,
        $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

    if (!$fp)
        //exit("Failed to connect: $err $errstr" . PHP_EOL);
    exit("" . PHP_EOL);
    //echo 'Connected to APNS\n' . PHP_EOL;

    // 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;

    // Send it to the server
    $result = fwrite($fp, $msg, strlen($msg));

    if (!$result)
        echo 'Message not delivered' . PHP_EOL;
    else
        echo 'Message successfully delivered' . PHP_EOL;

    fclose($fp);


}
?>      

Can anyone see what's wrong? :)

解决方案

there are 3 types of problem faced at here on APNS

  1. your Device token does not match
  2. your .pem does not a valid one, the reason is .p12 and .cer files are corrupted some times , so delete the .p12 file and .cer and create again once.
  3. is not a worth able answer but by chance it will be occur -- check your device notification is ON/OFF

这篇关于苹果推送通知 - PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆