这是我在push_notification模型中的代码
belongs_to :push_notificable, polymorphic: true
validates :remarks, presence:true
before_create :send_push_notification
def send_push_notification
device_id = get_device_id
if device_id.present?
fcm_client = FCM.new(ENV['AAAAzWU3na4:APA91bEDFQ2q37C4d41nPrEcRqHJotUoohjCkYcWjfNr2CS5k-VR4YGX9rpF5mqhkQCke_061hZvLwlqCd8mbqg2L9KbOH4mveFmtbYcVHW1c-8yCrML9Sj0uwwes56i6NFxgkaKxEgh'])
options = { priority: 'high',
data: {
message: remarks,
notify_type: "#{notify_type}",
account_id: account_id
},
notification: {
body: remarks,
sound: 'default'
}
}
registration_id = device_id
res = fcm_client.send(registration_id, options)
end
rescue Exception => e
e
end
def get_device_id
device_id = AccountBlock::Account.find_by(id: push_notificable.account_id).device_id
end
这就是我得到的回应
{:body =〉"\n\n无效密钥\n\n\n\n
无效键
\n
401错误提示
\n\n\n ",:标题=〉{"内容类型"=〉"文本/html;字符集= UTF-8 ","内容编码"=〉" gzip ","日期"=〉"格林尼治标准时间2023年2月9日星期四05:53:03 ","过期"=〉"格林尼治标准时间2023年2月9日星期四05:53:03 ","缓存控制"=〉"私有,最大年龄= 0 "," x内容类型选项"=〉" nosniff "," x帧选项"=〉" SAMEORIGIN ","内容安全策略"=〉"帧祖先自己"," x-xss保护"=〉" 1;模式=块",服务器"=〉"GSE",备用服务器"=〉" h3 =":443";马为2592000,海3 - 29为":443";ma = 2592000 ","传输编码"=〉"分块"},:状态代码=〉401,:响应=〉"验证发件人帐户时出错。"}
1条答案
按热度按时间ut6juiuv1#
401错误是一个身份验证错误,通常表示请求的Authorization标头中使用的API密钥无效。请检查您使用的服务器API密钥是否正确,如Firebase Console > [Project] >Project Settings > Cloud Messaging部分所示。您可以通过本文档中介绍的cURL命令检查服务器密钥的有效性。