无效的注册ID FCM [英] Invalid Registration id FCM

查看:84
本文介绍了无效的注册ID FCM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行下面的代码时,我得到:

When I execute the code below I get:

无效的注册令牌

Invalid registration token

我从MYSQL数据库获得令牌.我检查了返回的数据是否与数据库匹配.一切看起来都很完美,但是我找不到我的错误.

I get the token from MYSQL database. I checked that the data returned matches with the database. Everything seems perfect, but I can't find out my error.

如何修复或调试此代码:

How can I fix or debug this code:

function send_android_notification($registration_ids, $message) {
    //print_r($registration_ids);
    //print_r($message);
    //exit;
    define("GOOGLE_API_KEY", "AAAABoqI4ac:APA91bEMNO81wwRARcQftyBhIBU1U4Bq6rLKeRZDLOPAQu-9fk8y_6bOsZWnw2JEq-uwDJXDij1SjGPJtnwG6QO_IRZ54Gbbjfp9-izJ_a7DnLoTHD9Ot6lod7C-wLaYkH2Xl6l8iR8z");
    $fields = array(
        'registration_ids' => array($registration_ids),
        'data' => $message,
    );
    $headers = array(
        'Authorization:key=' . GOOGLE_API_KEY, // FIREBASE_API_KEY_FOR_ANDROID_NOTIFICATION
        'Content-Type: application/json'
    );
    // Open connection
    $ch = curl_init();
    // Set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    // Disabling SSL Certificate support temporarly
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    //echo json_encode($fields);
    //exit;
    // Execute post
    $result = curl_exec($ch);
    if ($result === false) {
        die('Curl failed:' . curl_errno($ch));
    }
    // Close connection
    curl_close($ch);
    return $result; 
}

推荐答案

已解决!

检查您的移动注册令牌存储在数据库表中的字段的长度.将其设置为200以上,因为令牌号的长度超过200.API服务器密钥字段必须是firebase云消息传递提供的旧服务器密钥.

Check your length of the field in which your mobile registration token is stored in your database table. Set it above 200, because the length of the token number exceeds more than 200. The API server key field must be a legacy server key provided by the firebase cloud messaging.

我下面的工作代码!

function send_android_notification($registration_ids, $message) {
    //print_r($registration_ids);
    //print_r($message);
    //exit;
    define("GOOGLE_API_KEY", "AIzaSyDfwSXWRD5tf*******************"); //legacy server key
    $fields = array(
        'registration_ids' => $registration_ids,
        'notification' => $message, //note: body & title fileds must be specified for the message or your only get just the vibration but the notification
    );
    $headers = array(
        'Authorization: key=' . GOOGLE_API_KEY, //  FIREBASE_API_KEY_FOR_ANDROID_NOTIFICATION
        'Content-Type: application/json'
    );
    //Open connection
    $ch = curl_init();
    //Set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    // Disabling SSL Certificate support temporarly
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    //echo json_encode($fields);
    //print_r($headers);
    //exit;
    //Execute post
    $result = curl_exec($ch);
    if ($result === false) {
        die('Curl failed:' . curl_errno($ch));
    }
    // Close connection
    curl_close($ch);
    return $result;
}

这篇关于无效的注册ID FCM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆