In this post you will learn how to send apple notification or IOS notification using apn voip token in php.
Here below is the working example in how to send IOS notification in php so please follow the one by one example line and make it success in your php application.
Firebase Notification Send PHP Example
Before you start you have to generate p8 file from your server and after generate bundleId from it, follow the below example.
<?php
$authKey = 'AuthKey_FILE.p8';
$teamId = </YOUR-TEAM-ID>;
$tokenId = </YOUR-TOKEN-ID>;
$production = false; // true to production server
$notification_payload = []; // your notification data or payload like title body
$token_key = file_get_contents($authKey);
$jwt_header = [
'alg' => 'ES256',
'kid' => $tokenId
];
$jwt_payload = [
'iss' => $teamId,
'iat' => time()
];
$raw_token_data = b64($jwt_header, true).".".b64($jwt_payload, true);
$signature = '';
openssl_sign($raw_token_data, $signature, $token_key, 'SHA256');
$jwt = $raw_token_data.".".b64($signature);
$request_body = json_encode($notification_payload);
$endpoint = $production ? 'https://api.push.apple.com/3/device': 'https://api.development.push.apple.com/3/device';
$url = "$endpoint/$token";
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_POSTFIELDS => $request_body,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0,
CURLOPT_HTTPHEADER => [
"content-type: application/json",
"authorization: bearer $jwt",
"apns-topic: $bundleId"
]
]);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$err = curl_error($ch);
curl_close($ch);
echo 'IOS notification send successfully.'
Thank you for read our post.
We always thanks to you for reading our blogs.
Dharmesh Chauhan
(Swapinfoway Founder)Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us
Haresh Chauhan
(Co-Founder)We Are Also Recommending You :
- Get Full Address From Latitude Longitude Google Map API In PHP
- Slug PHP Function Example - slugify($string)
- How To Check Valid Integer Values Using PHP Function Example
- Get Zipcode/Pincode From Latitude and Longitude PHP and Google Maps API
- How Do Check Whether The Email Address Valid Email Or Not In PHP Example
- could not encode content to iso-8859-1
- PhonePe Payment Gateway Example PHP
- IOS Push Notification Send Example
- How To Check Given URL Is Valid Or Not PHP Function Example
- UPI Payment Gateway Integration in PHP/Laravel