Last active
August 1, 2022 12:39
-
-
Save schevgeny/ff2ef0643f6e08446813077138f941db to your computer and use it in GitHub Desktop.
New APNS Provider API and PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(defined('CURL_HTTP_VERSION_2_0')){ | |
$device_token = '...'; | |
$pem_file = 'path to your pem file'; | |
$pem_secret = 'your pem secret'; | |
$apns_topic = 'your apns topic. Can be your app bundle ID'; | |
$sample_alert = '{"aps":{"alert":"hi","sound":"default"}}'; | |
$url = "https://api.development.push.apple.com/3/device/$device_token"; | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $sample_alert); | |
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array("apns-topic: $apns_topic")); | |
curl_setopt($ch, CURLOPT_SSLCERT, $pem_file); | |
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $pem_secret); | |
$response = curl_exec($ch); | |
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
//On successful response you should get true in the response and a status code of 200 | |
//A list of responses and status codes is available at | |
//https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH107-SW1 | |
var_dump($response); | |
var_dump($httpcode); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment