dongyuan9292 2016-07-21 12:54
浏览 38

发送POST REQUEST Firebase云消息传递

EDITED. Solved at the end of the post.

I´m trying to update GCM to FCM and everything works perfect but the connection with the Firebase API.

In GCM I sent had this code from my PHP script:

define( 'API_ACCESS_KEY', 'myapikeynumber');
$registrationIds = array($registrationID);
$msg = array
    (
    'message'         => $message,
    'title'           => 'You have new notification(s)',
    'subtitle'        => 'Please click to view your notification(s)',
    'user_id'         => $user_id,
    'user_type'       => $user_type,
    'notification_id' => $notification_id
    );
$fields = array
    (
    'registration_ids'  => $registrationIds,
    'data'              => $msg,
    'time_to_live'      => 3
    );
$headers = array
    (
    'Authorization: key='.API_ACCESS_KEY,
    'Content-Type: application/json'
    );
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/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;

But now don´t know which fields or values I need send to the https://fcm.googleapis.com/fcm/send.

Any help?


SOLUTION

The problem was here:

$registrationIds = array($registrationID);
$fields = array
    (
    'registration_ids'  => $registrationIds,
    'data'              => $msg,
    'time_to_live'      => 3
    );

Because $registrationsIds had not JSON structure.

So the code is nearly the same, just change that and the URL of the API to https://fcm.googleapis.com/fcm/send.

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!