首页 > 解决方案 > 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"}]}

标签: phpfirebasefirebase-cloud-messaging

解决方案


推荐阅读