firebase 后台发送推送 Android手机收不到消息
谷歌 浏览器 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
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
怎样阻止微信小程序自动打开
PHP中文网 06-13 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01