iPhone推送通知服务器:服务器更改后该怎么办?

发布于 2024-10-02 20:56:25 字数 1167 浏览 4 评论 0原文

去年我成功地实现了 iPhone 推送通知服务器(PHP);我必须更改服务器,并且认为移动文件就足够了......我错了,因为不再发送修改通知。没有错误,一切似乎都正常,但没有收到通知。

下面是我的服务器代码;任何人都可以想到原因或找到问题的方法吗? (注意: $deviceTokens var 是正确的,包含设备令牌,并且我已使用 openssl 命令成功测试了我的 .pem 证书)。

    $payload['aps'] = array('alert' => 'notification!!', 'sound' => 'push.aif');
    $payload = json_encode($payload);

    $streamContext = stream_context_create();
    stream_context_set_option($streamContext, 'ssl', 'local_cert', 'libraries/ck_prod.pem');
    $apns = stream_socket_client('ssl://gateway.sandbox.push.apple.com:' . 2195, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);

    if($error) {
        log_message('error', $errorString);
        return;
    }

    log_message('debug', 'sending push notification...');

    if($apns) {
        foreach($deviceTokens as $deviceToken) {
            $apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;
            fwrite($apns, $apnsMessage);
        }
        fclose($apns);
    } else {
        log_message('error', 'error while sending push notification');
    }

I successfully manage to implement an iPhone push notification server (PHP) last year; I had to change the server, and was thinking that moving files was sufficient... I was wrong, since the modification notifications are not sent anymore. There's no error, everything seems ok, but notification aren't received.

Below is my server code; anyone can think of a cause, or a way to find the problem ? (notes: the $deviceTokens var is correct, contains the device tokens, and I've successfully tested my .pem certificate with an openssl command).

    $payload['aps'] = array('alert' => 'notification!!', 'sound' => 'push.aif');
    $payload = json_encode($payload);

    $streamContext = stream_context_create();
    stream_context_set_option($streamContext, 'ssl', 'local_cert', 'libraries/ck_prod.pem');
    $apns = stream_socket_client('ssl://gateway.sandbox.push.apple.com:' . 2195, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);

    if($error) {
        log_message('error', $errorString);
        return;
    }

    log_message('debug', 'sending push notification...');

    if($apns) {
        foreach($deviceTokens as $deviceToken) {
            $apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;
            fwrite($apns, $apnsMessage);
        }
        fclose($apns);
    } else {
        log_message('error', 'error while sending push notification');
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魂ガ小子 2024-10-09 20:56:25

好吧...也许我应该注意到我正在联系测试服务器(网关。sandbox.push.apple.com)...有些日子只是困难...

Well well... Maybe I should have notice that I was contacting the test server (gateway.sandbox.push.apple.com)... Some days are just difficult...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文