Firebase推送通知无效获取令牌号但仍无效

我正在使用firebase发送推送通知。 它最近使用旧包名称工作正常我更改了我的应用程序的包名称以后通知不起作用,我再次使用firebase注册新包名称并在app文件夹中添加了新的google-services.json文件,我也获得了令牌号但是通知 没有发送到手机。</ p>

 &lt;?php 
//获取api密钥
$ api_key ='api_key';

//获取注册令牌我们必须将其作为数组
$ token ='token_number';
$ reg_token = array($ token);

//获取消息
$ message = '测试消息成功!!';

//创建消息数组
$ msg = array

'消息'=&gt; $消息,
'标题'=&gt;'测试消息' ,
'副标题'=&gt;'使用FCM演示的Android推送通知',
'tickerText'=&gt;'此处的代码文本...此处的代码文本...此处代码文字',
'振动'= &gt; 1,
'声音'=&gt; 1,
'largeIcon'=&gt;'large_icon',
'smallIcon'=&gt;'small_icon'
);

//创建新的 数组文件并在这里​​添加msg数组和注册令牌数组
$ fields = array

'registration_ids'=&gt; $ reg_token,
'data'=&gt; $ msg
);

//在另一个数组头中添加api密钥
$ headers = array

'授权:key ='。$ api_key,
'Content-Type:application / json'
);

//使用curl执行http请求
$ ch = curl_init();
curl_setopt($ ch,CURLOPT_URL,'https://fcm.googleapis.com/fcm/send');
curl_setopt($ ch,CURLOPT_POST,true);
curl_setopt($ ch,CURLOPT_HTTPHEADER,$ headers);
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,true);
ncurl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,false);
ncurl_setopt($ ch,CURLOPT_POSTFIELDS,json_encode ($ fields));

//获取结果
$ result = curl_exec($ ch);
curl_close($ ch);

//从结果解码json
// $ res = json_decode($ result);

//从成功中获取价值
// $ flag = $ res-&gt; success;
?&gt;
</ code> </ pre>
\ n

和json结果:</ p>

{“multicast_id”:6575432603807598829,“success”:1,“failure”:0,“canonical_ids”:0,“
results”: [{“message_id”:“0:1549340761166996%1ca91b70f9fd7ecd”}]} </ p>

通知未发送&amp; 我尝试使用firebase云消息传递 - &gt; 通知部分也没有工作。</ p>
</ div>

展开原文

原文

I am using firebase for sending push notification. It was working fine with old package name recently I changed package name of my app later notification is not working, again I registered new package name with firebase and added new google-services.json file in app folder and I get token number also but notification is not sending to mobile.

 <?php 
//Getting api key 
$api_key = 'api_key'; 

//Getting registration token we have to make it as array 
$token = 'token_number';
$reg_token = array($token);

//Getting the message 
$message = 'Test Message Success!!';

//Creating a message array 
$msg = array
(
    'message' => $message,
    'title' => 'Test Message',
    'subtitle' => 'Android Push Notification using FCM Demo',
    'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
    'vibrate' => 1,
    'sound' => 1,
    'largeIcon' => 'large_icon',
    'smallIcon' => 'small_icon'
);

//Creating a new array fileds and adding the msg array and registration token array here 
$fields = array
(
    'registration_ids' => $reg_token,
    'data' => $msg
);

//Adding the api key in one more array header 
$headers = array
(
    'Authorization: key=' . $api_key,
    'Content-Type: application/json'
); 

//Using curl to perform http request 
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/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 ) );

//Getting the result 
$result = curl_exec($ch );
curl_close( $ch );

//Decoding json from result 
// $res = json_decode($result);


//Getting value from success 
// $flag = $res->success;
?>

And json result :

{"multicast_id":6575432603807598829,"success":1,"failure":0,"canonical_ids":0," results":[{"message_id":"0:1549340761166996%1ca91b70f9fd7ecd"}]}

Notification is not sending & i tried with in firebase cloud messaging --> notification section also there also not working.

douguanya4248
douguanya4248 是的我尝试了一切...php文件显示上面的json结果但没有在移动设备获取通知但在firebase控制台它将工作意味着获取通知当我使用PHP文件它不工作。
一年多之前 回复
duano3557
duano3557 你修改了代码中的api密钥并尝试使用fbase的firebase控制台吗?还尝试从控制台向所有用户发送消息。
一年多之前 回复
dongshan8194
dongshan8194 添加了json结果请帮忙
一年多之前 回复
dsz1966
dsz1966 上传你的json文件和清单文件
一年多之前 回复

1个回答



试试这个</ p>

  $ url ='https://fcm.googleapis。  com / fcm / send'; 

$ fields = array(
'registration_ids'=&gt; $ ids,
//修复新的json格式
'通知'=&gt;数组(
'body' =&gt;'测试消息:)',
'标题'=&gt;'测试',

);

$ fields = json_encode($ fields);

$ server_key ='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
//继承密钥

$ headers = array(
'Content-Type:application / json',
'授权:key ='。$ server_key
);
\ n $ ch = curl_init();
curl_setopt($ ch,CURLOPT_URL,$ url);
curl_setopt($ ch,CURLOPT_POST,true);
curl_setopt($ ch,CURLOPT_HTTPHEADER,$ headers);
ncurl_setopt($ ch,CURLOPT_RETURNTRANSFER ,true);
curl_setopt($ ch,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ ch,CURLOPT_POSTFIELDS,$ fields);
$ result = curl_exec($ ch); \ n
var_dump($ result);

if($ result === FALSE){
die('哎呀!FCM发送错误 :'。 curl_error($ ch));
}

curl_close($ ch);
</ code> </ pre>
</ div>

展开原文

原文

Try this

$url = 'https://fcm.googleapis.com/fcm/send';

$fields = array (
        'registration_ids' => $ids,
         // fix new json format
        'notification' => array(
            'body' => 'Test message :)',
            'title' => 'Test',
        )

);

$fields = json_encode($fields);

$server_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
// inherited key

$headers = array(
    'Content-Type:application/json',
    'Authorization:key='.$server_key
);

$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, $fields);
$result = curl_exec($ch);

var_dump($result);

if ($result === FALSE) {
    die('Oops! FCM Send Error: ' . curl_error($ch));
}

curl_close($ch);

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐