真的很奇怪,也没有人问过这个问题。当授权密钥是我的服务器密钥时Firebase MismatchSenderID
我得到MismatchSenderId
作为我的服务器密钥的错误作为我的授权密钥(服务器密钥)。 另一方面,如果我的设备令牌作为我的授权密钥,但是我的设备上没有收到通知,我将从push_notification()返回成功。
我确定我的令牌是正确的,因为我可以使用firebase(单一设备)控制台中的令牌发送到单个设备。
,然后让我这个另一question,但后来我想移动到通知部分
我敢实际损失之前,证实了这个问题,因为所有的MismatchSenderId
错误是用的替代解决正确的服务器密钥
<?php
require "dbconfig.php";
$sql = "SELECT token FROM tokendb";
$result = mysql_query($sql) or die($sql."<br/><br/>".mysql_error());
$tokens = array();
while($row = mysql_fetch_assoc($result))
{
echo $row['token']; //this shows the same token compared to the token show in logcat(visual studio)
$tokens[] = $row["token"];
echo '<form id="form1" name="form1" method="post" action="">'.
'<p>From<br>'.
'<input type="text" size="100" maxlength="100" name="From" id="From" /><br>'.
'<p>Title<br>'.
'<input type="text" size="100" maxlength="100" name="Title" id="Title" />'.
'<br>'.
'<input type="submit" name="Send" id="Send" value="Send" />'.
'</form>';
}
$message = array("message" => "notification test");
$message_status = sendFCMMessage($message, $tokens);
echo $message_status;
function sendFCMMessage($message,$target){
//FCM API end-point
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array();
$fields['body'] = $message;
if(is_array($target)){
$fields['registration_ids'] = $target;
}else{
$fields['to'] = $target;
}
//header with content_type api key
$headers = array(
'Content-Type:application/json',
'Authorization:key=********'
);
//CURL request to route notification to FCM connection server (provided by Google)
$ch = curl_init();
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_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Oops! FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);
return $result;
}
?>
编辑:这个简短的PHP代码也给我MismatchSenderId
错误
<?php
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header=array('Content-Type: application/json',
"Authorization: key=***(serverkey from project)");
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{ \"notification\": { \"title\": \"Test desde curl\", \"text\": \"Otra prueba\" }, \"to\" : \"my device's token\"}");
curl_exec($ch);
curl_close($ch);
?>
UPDATE
卸载并重新安装应用程序解决了这个问题。
哇chigga是天才 –