Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 注册id FCM无效_Php_Android_Firebase Cloud Messaging - Fatal编程技术网

Php 注册id FCM无效

Php 注册id FCM无效,php,android,firebase-cloud-messaging,Php,Android,Firebase Cloud Messaging,当我执行下面的代码时,我得到: 无效的注册令牌 我从MYSQL数据库中获取令牌。我检查了返回的数据是否与数据库匹配。一切似乎都很完美,但我找不到我的错误 如何修复或调试此代码: function send_android_notification($registration_ids, $message) { //print_r($registration_ids); //print_r($message); //exit; define("GOOGLE_API_K

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

无效的注册令牌

我从MYSQL数据库中获取令牌。我检查了返回的数据是否与数据库匹配。一切似乎都很完美,但我找不到我的错误

如何修复或调试此代码:

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云消息传递提供的旧服务器密钥

下面是我的工作代码

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;
}
解决了

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

下面是我的工作代码

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;
}