EDITED 即可。在帖子结束时解决了。
我正在尝试将GCM
更新为FCM
,一切正常,但与Firebase API的关联。
我GCM
发送了PHP
脚本中的代码:
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;
但现在不知道我需要将哪些字段或值发送到https://fcm.googleapis.com/fcm/send
。
任何帮助?
解
问题在于:
$registrationIds = array($registrationID);
$fields = array
(
'registration_ids' => $registrationIds,
'data' => $msg,
'time_to_live' => 3
);
因为$registrationsIds
没有JSON结构。
所以代码几乎相同,只需将API和API的网址更改为https://fcm.googleapis.com/fcm/send
。