Konuyu Oyla:
  • Derecelendirme: 0/5 - 0 oy
  • 1
  • 2
  • 3
  • 4
  • 5
IOS FCM göndermek? [ÇÖZÜLDÜ]
#10
Merhaba,
Bildirim işlemlerinin tamamını PHP tarafında yaptığımı belirtmek isterim.

Sunucu tarafında gerekli kütüphane kurulumu için aşağıdaki komutu sunucudaki ana dizin içerisinde çalıştırınız. (html veya htdocs -- Windows | Linux )

composer require google/apiclient

PHP alanında IOS cihazdan alınan APN bilgisinin FCM'ye uygun hale getirmek için :

<?php

require 'vendor/autoload.php';
use Google\Client;

$serviceAccountPath = 'indirilenJsonAdı.json';

function getAccessToken($serviceAccountPath) {
   $client = new Client();
   $client->setAuthConfig($serviceAccountPath); 
   $client->addScope('https://www.googleapis.com/auth/firebase.messaging'); 
   $client->useApplicationDefaultCredentials();
   $token = $client->fetchAccessTokenWithAssertion();
   
   if (isset($token['error'])) {
       throw new Exception( $token['error_description']);
   }

   return $token['access_token'];
}

$accessToken = getAccessToken($serviceAccountPath);

$iidurl = 'https://iid.googleapis.com/iid/v1:batchImport';


if (isset($_GET['apn']))            {    $apn         =  $_GET['apn'];          }
if (isset($_GET['sandbox']))        {    $sandbox     =  $_GET['sandbox'];      }

if ((isset($apn)) && (isset($sandbox)))  
{

   $sandbox_bool = ($sandbox == 'true'); 

   $iidbody = json_encode([
       "application" => "com.paketAdi.uygulamaAdi",
       "sandbox" => $sandbox_bool,
       "apns_tokens" => [
            $apn
        ]
   ]);
   
   $iidch = curl_init($iidurl);
   
   curl_setopt($iidch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($iidch, CURLOPT_POST, true);
   curl_setopt($iidch, CURLOPT_HTTPHEADER, [
        'Authorization: Bearer ' . $accessToken,
        'Content-Type: application/json',
        'access_token_auth: true'
    ]);
   curl_setopt($iidch, CURLOPT_POSTFIELDS, $iidbody);
   
   $iidresponse = curl_exec($iidch);
   
   if (curl_errno($iidch)) {
       echo  curl_error($iidch);
   } else {
         echo  $iidresponse ;
   }
   
   curl_close($iidch);

}
else {
   
   $data = array(
       "Result" => array(
          array(
             "ResultStatus" => "0",
             "ResultMessage" => "TOKEN ERROR"
          )
       )
    );

    echo  json_encode  ($data); 

}

?>

Kullanımı :

http://localhost/phpAdi.php?apn=01992fd551185ef0fc546546546435342fe0245605b98e&sandbox=true

"indirilenJsonAdı.json" bilgisini Firebase - Proje ayarları alanından "Generate new private key" kısmından indirip php dosyasının bulunduğu yere kaydediniz.

   

Ek olarak "project ID" bilgisi de bildirim yollarken gerekli ve onu da yine aynı alandaki aşağıdaki sekmeden alabilirsiniz.

   


PHP tarafında hedeflenen TOKEN bilgisine bildirim göndermek için :

<?php

require 'vendor/autoload.php';
use Google\Client;


function getAccessToken($serviceAccountPath) {
   $client = new Client();
   $client->setAuthConfig($serviceAccountPath);
   $client->addScope('https://www.googleapis.com/auth/firebase.messaging');
   $client->useApplicationDefaultCredentials();
   $token = $client->fetchAccessTokenWithAssertion();
   
   if (isset($token['error'])) {
       throw new Exception($token['error_description']);
   }

   return $token['access_token'];
}

function sendMessage($accessToken, $projectId, $message) {
   $url = 'https://fcm.googleapis.com/v1/projects/' . $projectId . '/messages:send';
   $headers = [
        'Authorization: Bearer ' . $accessToken,
        'Content-Type: application/json',
    ];

   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_POST, true);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
   curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['message' => $message]));

   $response = curl_exec($ch);
   if ($response === false) {
       throw new Exception('Curl error: ' . curl_error($ch)); 
   }
   curl_close($ch);
   return json_decode($response, true);
}

$serviceAccountPath = 'indirilenJsonAdi.json';
$projectId = 'projectID';
$message = [
   'notification' => [
        'title' => 'Örnek Başlık',
        'body' => 'Örnek içerik',
    ],
   'token' => 'TOKEN_BILGISI'
];

try {
   $accessToken = getAccessToken($serviceAccountPath);
   $response = sendMessage($accessToken, $projectId, $message);
   print_r( $response);
} catch (Exception $e) {
   echo  $e->getMessage(); 
}
?>


Şimdilik bu kadar...
Takıldığınız yer olursa yardımcı olurum.
Cevapla


Bu Konudaki Yorumlar
IOS FCM göndermek? [ÇÖZÜLDÜ] - Yazar: Mr.X - 06-09-2024, Saat: 20:35
Cvp: IOS FCM göndermek? - Yazar: RAD Coder - 09-09-2024, Saat: 09:06
Cvp: IOS FCM göndermek? - Yazar: Mr.X - 09-09-2024, Saat: 09:51
Cvp: IOS FCM göndermek? - Yazar: RAD Coder - 09-09-2024, Saat: 10:36
Cvp: IOS FCM göndermek? - Yazar: Mr.X - 09-09-2024, Saat: 14:46
Cvp: IOS FCM göndermek? - Yazar: hi_selamlar - 09-09-2024, Saat: 16:00
Cvp: IOS FCM göndermek? - Yazar: Mr.X - 09-09-2024, Saat: 16:34
Cvp: IOS FCM göndermek? - Yazar: Mr.X - 09-09-2024, Saat: 17:09
IOS FCM göndermek? - Yazar: oser - 12-09-2024, Saat: 09:39
Cvp: IOS FCM göndermek? [ÇÖZÜLDÜ] - Yazar: Mr.X - 12-09-2024, Saat: 14:50
Cvp: IOS FCM göndermek? [ÇÖZÜLDÜ] - Yazar: barissagir - 22-09-2024, Saat: 15:46
IOS FCM göndermek? [ÇÖZÜLDÜ] - Yazar: nguzeller - 14-09-2024, Saat: 12:09
IOS FCM göndermek? [ÇÖZÜLDÜ] - Yazar: mrmarman - 22-09-2024, Saat: 23:27
Cvp: IOS FCM göndermek? [ÇÖZÜLDÜ] - Yazar: Mr.X - 23-09-2024, Saat: 09:00
IOS FCM göndermek? [ÇÖZÜLDÜ] - Yazar: barissagir - 23-09-2024, Saat: 12:03
Cvp: IOS FCM göndermek? [ÇÖZÜLDÜ] - Yazar: RAD Coder - 23-09-2024, Saat: 12:24
Cvp: IOS FCM göndermek? [ÇÖZÜLDÜ] - Yazar: RAD Coder - 06-11-2024, Saat: 09:25
Cvp: IOS FCM göndermek? [ÇÖZÜLDÜ] - Yazar: shooterman - 04-12-2024, Saat: 11:33

Konu ile Alakalı Benzer Konular
Konular Yazar Yorumlar Okunma Son Yorum
  Google Play Billing Versiyon Sorunu[ÇÖZÜLDÜ] codder71 12 2.193 01-08-2026, Saat: 22:45
Son Yorum: codder71
  Android 16 Uygulama Ekran Taşma Sorunu[ÇÖZÜLDÜ] codder71 5 1.093 31-07-2026, Saat: 23:38
Son Yorum: mcuyan
  PHPickerDelegate Derleme Sorunu [ÇÖZÜLDÜ] codder71 13 2.374 18-07-2026, Saat: 22:54
Son Yorum: emailx45
  ios için uygulama derleme [ÇÖZÜLDÜ] codder71 29 6.126 01-07-2026, Saat: 14:39
Son Yorum: codder71
  Çözüldü _ Delphi Community Edition SDK ayarları hatası cinarbil 2 1.223 08-06-2026, Saat: 16:22
Son Yorum: emailx45



Konuyu Okuyanlar: 1 Ziyaretçi