• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

firebase 后台发送推送 Android手机收不到消息

武飞扬头像
ChenQM694
帮助1

谷歌 浏览器 firebase 后台发送推送 Android手机收不到消息


谷歌 浏览器 firebase 后台发送推送 Android手机收不到消息问题描述

前台用的是react native 后台是php

前台代码

componentDidMount() {

       // Notification

        this.onNotificationListener()

        this.onNotificationOpenedListener()

        // this.getInitialNotification()

    }

getToken = async () =>{

        const token = await notifications.getToken();

        console.log('token55555',token)

        this.setState({

            getToken: token

        })

    }

    getInitialNotification = async () =>{

    const notification = await notifications.getInitialNotification()

    console.log("getInitialNotification", notification)

    return notification

    }

    onNotificationOpenedListener = async () => {

    this.removeOnNotificationOpened = notifications.onNotificationOpened(

        notification => {

            this.setState({messageCount:this.state.messageCount 1})

            console.log("onNotificationOpened", notification)

            }

        )

    }    

    onNotificationListener = () => {

        this.removeOnNotification = notifications.onNotification(notification=>{

            console.log("onNotification", notification)

            this.setState({messageCount:this.state.messageCount 1})

            Alert.alert(

                "Push Title",

                "バックエンドからメッセージプッシュ:" notification.body,

                [

                    {

                        text:"キャンセル",

                        onPress: () => console.log("Canel Pressed"),

                        style: "cancel"

                    },

                    {text: "確認", onPress: () => console.log("OK Pressed")}

                ]

            );

        } )

      }  

点击登录按钮调用

doLogin =  ()  => {

 this.getToken();

}

后台代码

var express = require("express");
var db = require("../../config/db.js");
var Base = require("../base");
const dbBack = require("../../config/transaction");
const fetch = require("node-fetch")
const url ='https://fcm.谷歌apis.com/fcm/send';

class Notification extends Base{   
    
 sendNotification = async() => {
      let payload = {
        //token
       直接写死手机的token
        to:'***',
    //  to:obj.token,
    
        notification:{
            title:'test',
            body:'*******......',
        }
       
    };
    let opts = {
        method:'post',
        headers:{
            'Authorization': 'key=AAAA8qagpxQ:APA91bGthhEkIfXx-za9gG5UhYaBkDKbeXVqOjqilGVjBmu9f0FgXOLxJzoPs5N7XaWwaoVSnkl2wB-YRWZCZx6D6lKYjlAbLqunUTIt9vlz4iUb-iip9mY-L088_zDRVuzZhFcfoIKR',
            'Content-Type': 'application/json',
        },
        body: JSON.stringify(payload),
    };
   await fetch(url, opts)
  
  
    .then(resp => {
        console.log('.....................',resp);
         console.log(' fetch(url, opts)', fetch(url, opts))
       // res.send({status: 10015, message: this.getMessage('10015') })
        
    })
    .catch(err => {
        console.log('err---------------',err)//代码错误、请求失败捕获
    }); 
}

}
module.exports = Notification;

登录后调用

var express = require("express");
var db = require("../config/db.js");
var Base = require("../api/base");
var config = require('../config/app.json')
var jwt = require('jsonwebtoken');
const dbBack = require("../config/transaction");
var Notification = require("../api/Notification/notification");
const applicationLogger = require("../log/logger").application;

class App extends Base {
  checkUser(req, res) {
    
    var obj = req.body;
    let { app_id, app_password, registration_id } = req.body;
    var sql = `
            SELECT id               
                , name              
                , mail             
                , mail_flg         
                , app_id         
                , app_password     
            FROM driver_trn 
            WHERE deleted_by IS NULL
            AND app_id = '${app_id}'
            AND app_password = '${app_password}'
        `;

    db.query(sql, (err, result) => {

      if (err) {
        console.log("検索失败------", err.message);
        res.send({ status: 500, message: "ログイン失敗!" });
        return;
      } else {
        if (result.length > 0) {
          if (typeof (registration_id) != 'undefined') {
            let register_update_sql = `
                  UPDATE driver_trn SET registration_id = '${registration_id}' WHERE app_id = '${app_id}'
                `;
            db.query(register_update_sql, (err, result) => {
              if (err) {
                console.log(err, "---err--");
              } else {
                console.log(result);
              }
            });
          }
          let token = jwt.sign(
            {
              id: app_id,
            },
            config.secret_key,
            {
              expiresIn: 86400,
            }
          );
          let user = result[0];
           userList: user
          res.send({
            code: 1,
            data: {
              token: token,
              userList: user,
            },
            status: 200,
            message: "ログイン成功!",
          });
          //notification
          var notification = new Notification();          
          notification.sendNotification()
          
        
        } else {

          res.send({
            code: 0,
            status: 404,
            message: "***。",
          });
        }
      }
    });
  }

 


原因分析:

firebase 云上面显示已经发送了

但是手机没有收到,云上面也没有显示收到。

求助 求助大神!!!

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgcajee
系列文章
更多 icon
同类精品
更多 icon
继续加载