firebaseを使用してIonic 2アプリに通知をプッシュしたいとします。私はfirebaseコンソールを使って直接通知をプッシュすることができますが、私はPHPファイル経由で送信したいと思います。ionic - PHPを使用したfirebase通知が機能しない
私は私のようにPHPからの応答を取得送る:{"message_id":5718309985299480645}
と電話には通知がありません。
私はapp.component.tsコンストラクタにthis.fcm.subscribeToTopic('all')
を配置しました。私は私が間違っているのか知ってはいけない...
this.fcm.subscribeToTopic('all')
は私のアプリでは、FCMに関連したコードのみです。
MY PHPコード:
<?php
$data = array('title'=>'FCM Push Notifications');
$target = '/topics/mytopic';
//FCM API end-point
$url = 'https://fcm.googleapis.com/fcm/send';
//api_key available in Firebase Console -> Project Settings -> CLOUD MESSAGING -> Server key
$server_key = 'my_server_key_from_firebase';
$fields = array();
$fields['data'] = $data;
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='.$server_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);
echo $result;
?>
私はEVEN PUSHBOTS試みたが、彼らが使用beeingている特別な場合には、
あなたはこのページの最後に似ペイロード以下の通りです?:https://github.com/fechanique/cordova-plugin-fcm –
FCM_PLUGIN_ACTIVITYは何ですか? –
これは、FCMのAndroidでプッシュを使用するためのデフォルトであるため、これを探すのは面倒ではありませんが、ペイロードの説明に「どのように動作するか」と書かれているように、 –