php - Google Firebase 通知无法订阅主题

标签 php ios firebase push-notification notifications

我有一个新的 Firebase 应用。目的是从 php 服务器向 iOS 设备发送主题通知。

我已经成功测试了从服务器向特定设备 ID 发送通知的所有内容。

但是,主题拒绝玩好。

从 PHP 方面:

function call_firebase_notification ($signal){ 
    $to = "/topics/demo";
    $title = "php function test real";
    $body = "php function test real body";
    $payload = json_encode(array(
                    "to" => $to ,
                    "notification" => array(
                      "title" => $title,
                      "body" => $body
                    )
                ));
    $headers = array(
        "Authorization: key=AIzaSyBr0G...Euxr5x4_0",
        "Content-Type: application/json",
        "Content-Length: ". strlen($payload)
        );
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://fcm.googleapis.com/fcm/send"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);    
    $return = curl_exec($ch); 

    curl_close($ch);

    return $return;
}
$return = call_firebase_notification("test");
var_dump($return);

我得到了最积极的结果:string(34) "{"message_id":9067338503195970026}"

从 iOS 端:

[[FIRMessaging messaging] subscribeToTopic:@"/topics/demo"];

我现在的犯罪伙伴也说在订阅时得到了积极的结果。

但是没有通知到达(再次注意:通知发送到他的 id 时成功传递)并且尝试从 firebase 控制台发送通知时没有主题出现。

编辑: (给自己和世界的注释)

    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

除非绝对必要或无聊,否则永远不要使用这些,这是一个演示片段,所以我并不关心,但通常你应该更新你的 ssl 证书

最佳答案

能否请您尝试在您的通知负载中添加prioritycontent_available 参数。

{
  "to": "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
  "notification": {
     "title": "test",
     "body": "my message"
  },
  "priority": "high",
  "content_available": true
}

我还注意到,根据 Firebase Status Dashboard,昨天 Firebase 云消息传递服务中断了.

关于php - Google Firebase 通知无法订阅主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39223417/

相关文章:

php - 为线程安全动态配置 PHP --enable-maintainer-zts,还是使用 yum 安装 pthreads?

javascript - 提交表单而不重新加载页面

ios - 通过 Perform Segue 将特定值从 TableViewCell 发送到 ViewController

iphone - 尝试从导航堆栈中弹出 View 时断言失败

iOS 应用程序 : Enabling logging with minimal changes to the code

ios - 将 Firebase 与适用于 Mac 的 Google 工具箱一起使用时出现 undefined symbol Xcode 错误

ios - 我的 .txt 文件在加载文本时滞后 - 保存到 Firebase 并从那里加载可以加快速度吗?

php - 无法使用 PHP openssl_sign 签署任何内容?

PHP OOP 为类变量赋值

ios - 在从函数返回之前等待 Firebase 加载