我正在尝试通过PHP脚本通过Firebase Cloud Messaging
将推送通知发送到iOS App。
当前,我正在使用以下测试PHP
脚本。
$url = "https://fcm.googleapis.com/fcm/send";
$token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$serverKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$title = "Title";
$body = "Body of the message";
$notification = array('title' =>$title , 'text' => $body, 'sound' => 'default', 'badge' => '1');
$arrayToSend = array('to' => $token, 'notification' => $notification,'priority'=>'high');
$json = json_encode($arrayToSend);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: key='. $serverKey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
//Send the request
$response = curl_exec($ch);
//Close request
if ($response === FALSE) {
die('FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);
但是,当我尝试通过浏览器运行脚本时,收到以下错误消息。
{"multicast_id":5417898622260949101,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
但是当我从FCM控制台使用相同的设备令牌时,它可以正常工作。
我在互联网上尝试了许多PHP脚本,但最终得到了相同的结果,这里的问题是什么?
任何帮助将不胜感激。
答案 0 :(得分:0)
您使用的令牌似乎不是FCM的有效注册令牌,因此出现InvalidRegistration错误。
答案 1 :(得分:0)
CREATE PROCEDURE UPDATE_ALL
@SOURCE VARCHAR(100),
@DEST VARCHAR(100),
@ID VARCHAR(100)
AS
DECLARE @SQL VARCHAR(MAX) =
'UPDATE D SET ' +
-- Google 'for xml path stuff' This gets the rows from query results and
-- turns into comma separated list.
STUFF((SELECT ', D.'+ COLUMN_NAME + ' = S.' + COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @DEST
AND COLUMN_NAME <> @ID
FOR XML PATH('')),1,1,'')
+ ' FROM ' + @SOURCE + ' S JOIN ' + @DEST + ' D ON S.' + @ID + ' = D.' + @ID
--SELECT @SQL
EXEC (@SQL)