我正试图通过我的.PHP页面向我的手机发送通知…
一切都设置正确,但我收到错误:
{"multicast_id":7751536172966571167,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}
我不知道为什么因为发件人ID是对的,api也是(我已经尝试过服务器密钥和浏览器密钥,只是为了确定).
我真的不知道我哪里错了!
在我的应用程序中我只有发件人ID,所有都已经正确,在我的服务器中我已经获得了浏览器的密钥(现在):
PHP require_once("../pi_classes/commonSetting.PHP");
include('../pi_classes/User.PHP');
ini_set("display_errors",1);
class GCM{
function __construct(){}
public function send_notification($registatoin_ids,$message){
// GOOGLE API KEY
define("GOOGLE_API_KEY","xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
$url="https://android.googleapis.com/gcm/send";
$fields=array(
"registration_ids"=>$registatoin_ids,"data"=>$message,);
var_dump($fields);
$headers=array(
"Authorization: key=".GOOGLE_API_KEY,"Content-Type: application/json"
);
$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,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($fields));
$result=curl_exec($ch);
if($result===FALSE){
die("Curl Failed: ".curl_error($ch));
}
curl_close($ch);
echo $result;
}
}
// ======================
//=INVIA LE NOTIFICHE AGLI UTENTI =
// ======================
$messaggio="Ciao,sono una notifica!";
$pushCounter=0;
$registatoin_ids=array();
$result=MysqL_query("SELECT android_regi_id FROM user_details");
while($row=MysqL_fetch_array($result)){
$token=$row["android_regi_id"];
if($token!=""){
$registatoin_ids[]=$token;
$pushCounter++;
}
}
if($pushCounter>0){
$gcm=new GCM();
$message=array("price"=>$messaggio);
$result_android=$gcm->send_notification($registatoin_ids,$message);
echo $result_android;
}
最佳答案
原文链接:/android/430997.html