iOS APNs 推送通知发送成功,但手机收不到通知

iOS APNs push notification send successfully, but notification not receiving in mobile

自上周五(4 月 23 日)以来一切正常,我收到了沙盒和生产通知。但是当我现在检查时,通知不起作用。我检查了我的 .pem 文件在 2021 年 12 月之前有效,当我 运行 下面的代码时,结果是 'Message successfully delivered'。我不知道发生了什么事。请帮助我。

<?php
    $deviceToken = "a9eb9cd54446b5cad4fa3636dbe822b5d420126fdbb632ef79b4bf07bfd8b6b4";
    $passphrase = 'secret';

    $message = "Hello world!";

    $ctx = stream_context_create();

    $passphrase = 'secret';
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'certi.pem');
    
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
  /* $fp = stream_socket_client(
                               'ssl://gateway.push.apple.com:2195', $err,
                               $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);*/
    $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err,$errstr, 60,STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
    
    if (!$fp){
        exit("Failed to tess connect: $err $errstr" . PHP_EOL);
    }
    $body = array('aps' => array('alert' => $message,'sound' => 'default','badge' => 1),'rewards_badge' => 1);
    
    $payload = json_encode($body);

    $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
    $result = fwrite($fp, $msg, strlen($msg));
    if (!$result){
        echo 'Message not delivered' . PHP_EOL;
    }else{
        echo 'Message successfully delivered' . PHP_EOL;
    }
    fclose($fp);
?>

谢谢

我也是。我向 Apple 提交了帮助请求,请他们提供帮助。

我使用相同的测试脚本。我注意到 ssl://gateway.sandbox.push.apple.com:2195 不再有效。 如果您的 Apple 设备没有收到 Apple 推送通知

这是新域名? api.sandbox.push.apple.com:443

Sending Notification Requests to APNs

  • 旧端口 2195 和 2196 已弃用,2021 年 3 月后将不再受支持。

我也是。让我们像《Apex 英雄》一样一起解决这个问题。

我已经向 Apple 提交了 TSI。他们在 2 月 10 日发了一封电子邮件说:

2021 年 3 月 29 日,与 Apple 推送通知服务的基于令牌和证书的 HTTP/2 连接必须包含新的根证书 (AAACertificateServices 5/12/2020),该证书将替换旧的 GeoTrust Global CA 根证书证书。为确保无缝过渡并避免推送通知传送失败,请在 3 月 29 日之前验证 HTTP/2 接口的新旧根证书是否包含在每个通知服务器的信任库中。

请注意,Apple 颁发给您的 Apple 推送通知服务 SSL 提供商证书目前不需要更新。

了解有关连接到 APNs 的更多信息。

如有任何疑问,请联系我们。

此致,Apple 开发者关系

更新 - 5 月 3 日星期一,在向 Apple Dev 提交 TSI 后

  1. 在 Apple 迁移到新的 APNS 提供商 API(http/2 协议)后,推送通知于 2021 年 3 月 31 日停止为开发人员工作。
  2. 要继续使用推送,请参阅此页面:向 APNs 发送通知请求
  3. 在该页面上,我对这 3 个项目特别感兴趣:

Registering Your App with APNs

Establishing a Token-Based Connection to APNs

Generating a Remote Notification

我学到了什么?

  1. 撤销所有与APNS相关的开发者账号证书
  2. 制作新证书,这次在将它们安装到您的提供服务器时不要制作任何 PEM 文件。另外,确保在连接到 APNS 时停止使用端口 2195,并使用 443 或 2197。

好消息?新的 APNS 提供商 API 仍然兼容 Objective C!