【问题标题】:FCM some times got connection port 443 failed errorFCM 有时会出现连接端口 443 失败错误
【发布时间】:2017-08-01 13:58:23
【问题描述】:

我正在使用 FCM 推送通知来发送消息,一切正常,但有时当我想向我收到的人发送推送通知时

Curl failed: Failed to connect to fcm.googleapis.com port 443: Connection timed out

我几乎搜索了所有内容。这里出现了类似的问题,但我的端口是开放的 Sending notification message to android device curl error

我的网络也不在代理下。

这个问题是否可能是由于频繁调用 firebase 发送通知引起的?它有一些限制吗?

【问题讨论】:

    标签: php android firebase firebase-cloud-messaging


    【解决方案1】:

    这可能是这些原因之一。

    1. 服务器无法访问互联网
    2. 如果您在 localhost(您自己的 PC)上尝试它,它不会工作。请在您的服务器上进行测试。
    3. 您没有正确发送请求(以下是您的参考 PHP 代码)。

      function sendFCMPushNotification(){
      $server_key = //"enter your server key here";
      $mobile_tokens = array("token 1", "token 2", "token n");
      $n_data = array("title"=>"Test Notification", "attribute"=>"3999", "parameter 2"=>"value");
      
          $json_data = [
              "to" => implode($mobile_tokens),
              "notification" => [
                  "title" => "FCM PUSH",
                  "body" => "Text to be shown under the title",
                  "click_action" => "MAIN_ACTIVITY" // activity to be opened in application, remove this if you dont require one.
              ],
              "data" => $n_data
          ];
      
          $data = json_encode($json_data);
      
          $url = 'https://fcm.googleapis.com/fcm/send';
      
          $headers = array(
              'Content-Type:application/json',
              'Authorization:key='.$server_key
          );
      
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_setopt($ch, CURLOPT_POST, true);
          curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
          curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
          $result = curl_exec($ch);
          //print($result);
      
          if ($result === FALSE) {
              print_r('Oops! FCM Send Error: ' . curl_error($ch));
          }else{
              print_r('WoW! FCM SENT SUCCESSFULLY');
          }
          curl_close($ch);
      }
      

      }

    【讨论】:

      猜你喜欢
      • 2023-01-15
      • 1970-01-01
      • 1970-01-01
      • 2015-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多