drxzpo70788179614 2014-06-07 08:05
浏览 55
已采纳

苹果推送通知 - PHP [关闭]

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
' . 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? :)

  • 写回答

3条回答 默认 最新

  • dongluo8439 2014-06-07 10:48
    关注

    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
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度