php - InvalidRegistration 在 php 中发送推送
问题描述
我正在尝试在我的 android 应用程序上发送推送通知,但我总是收到错误消息:
“无效注册”
这是我在“ to ”中发送的令牌
我的代码:-
public function android_push($token, $load, $key) {
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $token,
'data' => $load
);
$headers = array(
'Authorization: key=' . $key,
'Content-Type: application/json'
);
$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_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields, true));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
我的参数:
{"title":"Test","msg":"test"}
token: ["pid_58cc-6fed***"]
key:AA*****zEoEbsgPZCjK_umqrmgMZRkpyN7BAA5MNfGuojQP5olWIe1H_vzU8-9THNcB-CgZAjA6fwL72yE******6V7Cl-IObLDGwA6SqTopuK96begUtysy_cG8rc02vdIeYx****
结果:
{"multicast_id":4723735099133341876,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
解决方案
推荐阅读
- c# - Roslyn 准备好迎接 c# 10 了吗?
- flutter - Flutter ListTile - 将所有项目垂直对齐到中心
- python - Python - 创建一个 11 位数字列表生成器
- css - 在 Webpack 5 中转换 SCSS 文件而不是 CSS 文件的正确方法
- android - 为什么logcat中没有信息?
- python - 如何使用python从pdf中删除文本层
- facebook - Facebook Graph API:如何读取我不管理的 Facebook 群组的提要?
- clang - 是否有我可以传递给 cmake 的环境变量使 clang 使用 lld 而不是 ld?
- javascript - 不能在另一个 div 中创建多个 div
- android - 无法通过改造和协程获得 API 响应