<?php
include './func.php';
$c = getDB();
$op = p("op");
$title=$_POST['title'];
if ($op == "register")
{
$firebaseId = p("firebase_id");
$c->query("insert into ids values ('$firebaseId')");
}
if ($op == "get_app_details")
{
$appId = p("app_id");
// Select Sorgusundan Tek Satir Veri Dondurmek
// $r'de Bir Satirin Tum Verisi Tutulur
$r = $c->query("select * from applications where id = $appId")->fetch_assoc();
toJSON($r);
}
if ($op == "get_all_applications")
{
// Select Sorgusundan Tum Verileri Dondurmek
// $rs'de Tum Tablo Verisi Tutulur
$rs = $c->query("select * from applications");
$arr = array();
// Tablodaki Satirlari Tek Tek Don Ve Arraye Ekle
while ($r = $rs->fetch_assoc())
$arr[] = $r;
toJSON($arr);
}
$apiKey ="AAAA_1EwCSM:APA***********jmy9q725Ca7w3sJI01***************GAPtf1Jv1TxZYgwIEIY6hH35Wf0lRCmAEl7HxSB_oaIJyhC6lQMmXvwC1J4PpVIS6K9Jg";
$fb_endpoint = "https://fcm.googleapis.com/fcm/send";
$headers = array('Authorization:key=' . $apiKey, 'Content-Type:application/json');
$token = $c->query("select * from ids");
$meli = mysqli_fetch_array($token);
$string =$meli['firebase_id'];
$data = array(
'title' =>$title,
'message' =>'',
'subtitle' => '',
'tickerText' => '',
'msgcnt' => 1,
'vibrate' => 1
);
$fields = array('data' => $data, 'registration_ids' => array($string), 'delay_while_idle' => true, 'priority' => 'high', 'content_available' => true );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $fb_endpoint);
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_IPRESOLVE, CURL_IPRESOLVE_V4 );
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
//header("Content-Type: application/json");
//echo json_encode($result, JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK);
$res = json_decode($result);
print_r( $_POST );
echo "\r\n";
echo $result;
?>
这是我的代码工作,我也没有获取设备令牌的问题。它工作我成功:1但我的设备没有得到任何通知 你有什么推荐我的?
"multicast_id":7984627576959961401,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1482750065457266%f126618ef9fd7ecd"}]}
我的JAVA
消息服务:
public class MesajServisi extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
String title = remoteMessage.getNotification().getTitle();
// String message = remoteMessage.getNotification().getBody();
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
android.support.v4.app.NotificationCompat.Builder notificationBuilder = new android.support.v4.app.NotificationCompat.Builder(this);
//notificationBuilder.setContentTitle("title");
notificationBuilder.setContentTitle(title);
// notificationBuilder.setContentText(message);
//notificationBuilder.setSmallIcon(R.mipmap.)
notificationBuilder.setAutoCancel(true);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0,notificationBuilder.build());
}
}
ID服务:
public class KayitServisi extends FirebaseInstanceIdService
{
String newToken = "";
public void onTokenRefresh()
{
newToken = FirebaseInstanceId.getInstance().getToken();
Log.e("x","Cihaz ID : "+newToken);
new Thread()
{
public void run()
{
new AsyncTask<String,String,String>()
{
protected String doInBackground(String... strings)
{
try
{
Jsoup.connect("http://192.168.1.18/server/mobile.php")
.ignoreContentType(true)
.timeout(30000)
.data("firebase_id",newToken)
.post();
Log.e("x","ID Server'a Kayit Edildi");
} catch (Exception e) { Log.e("x","DoInBG Ex : "+e.toString()); }
return null;
}
}.execute();
}
}.start();
}
}