dsf23223 2017-08-02 07:58
浏览 154

Firebase无效注册令牌

I am a web developer and hired ios developer to create native app for my client. The client wants to have push notifications. We are using firebase but the problem is that i can't send push notifications from my php script, because of the InvalidRegistration error. I've read all over stackoverflow about this error and still dont have a clue how to fix it.

I am saving the device_token in a mysql table CHAR(64).

This is my script:

if (isset($_POST['submit'])) {
// API access key from Google API's Console
define('API_ACCESS_KEY', 'API');

$users = $db->getResults("device_id", "users", "device_id != '' AND travel_stay = '" . $_POST['group'] . "'");
foreach ($users as $user) {
    $registrationIds = (string)$user['device_id'];
    // prep the bundle
    $msg = array(
        'message'       => $_POST['description'],
        'title'         => $_POST['title'],
        'subtitle'      => 'This is a subtitle. subtitle',
        'tickerText'    => 'Ticker text here...Ticker text here...Ticker text here',
        'vibrate'       => 1,
        'sound'         => 1,
        'largeIcon'     => 'large_icon',
        'smallIcon'     => 'small_icon');
    $fields = array('to' => $registrationIds, 'data' => $msg);

    $headers = array('Authorization: key=' . API_ACCESS_KEY, 'Content-Type: application/json');

    $ch = curl_init();
    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_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    $result = curl_exec($ch);
    curl_close($ch);
    echo $result;
}

} ?>

I have no idea what is wrong with it, is the device_token sent wrong? How can i fix it.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 手机连接电脑热点显示无ip分配
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大