【发布时间】:2017-09-27 15:17:39
【问题描述】:
我正在开发一个将使用 FCM 发送推送通知的 IOS 应用程序,我已经在 FCM 控制台上正确配置了所有内容,并测试了从控制台向设备发送消息并且它工作正常。现在我正在使用以下脚本,消息无法推送到手机。 当我发送时,我会收到此消息
{"multicast_id":7893466200486146313,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1506525095628728%b54fead7f9fd7ecd"}]}
下面是我的脚本
// Replace with the real server API key from Google APIs
$apiKey = "-------";
// Replace with the real client registration IDs
$registrationIDs = array('00000');
// Message to be sent
$message = "New Message from GWCL";
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( 'message' => $message,'title' => "New Message",'notId'=>''.time(), 'complain_id'=>'90','push'=>'reply','priority'=>'high'),
);
$headers = array(
'Authorization: key=' . $apiKey,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the URL, number of POST vars, POST data
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_POSTFIELDS, json_encode( $fields));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
我按照教程告诉我添加'priority'=>'high',我做了但仍然没有工作
【问题讨论】:
-
确保您从 ios 获得正确的注册设备令牌,并且根据您的 php 响应没有错误。可能来自您必须检查的 ios 设备。
-
如果成功则意味着您拥有正确的设备令牌,否则将引发无效注册
-
我没用过FCM,但是你是在Release还是Debug?如果您正在调试,则必须使用调试证书并指示 FCM 连接到 Apple 调试 APN。
-
我已将 .p12 文件上传到 fcm
-
只有 VoIP 推送证书对于调试和发布是相同的。普通推送证书不同。
标签: php ios google-cloud-messaging