Created
March 30, 2021 06:03
-
-
Save cevin/7973e7a701aa1e627d5159b5a28fd480 to your computer and use it in GitHub Desktop.
php curl APNs push
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
<?php | |
// passed in php 7.4 | |
$service_url = 'https://api.push.apple.com/3/device/'; | |
$token = '07cd****3217****6289****94999228d7b45339fbafdf08****8f83****499b'; | |
$headers = array(); | |
$header[] = 'apns-topic:com.xxxxx.xxapp'; // bundle-id | |
$payload = '{"aps":{"alert":"hello","sound":"msg_high.m4a"}}'; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); | |
curl_setopt($ch, CURLOPT_SSLCERT, '/var/www/cer.pem'); // client certificate | |
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, ''); // client certificate password | |
# curl_setopt($ch, CURLOPT_SSLCERTYPE, 'P12'); // support p12 cert | |
curl_setopt($ch, CURLOPT_URL, $service_url . $token); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); | |
curl_setopt($ch, CURLOPT_HEADER, TRUE); // show response header (get apns-id) | |
curl_setopt($ch, CURL_RETURNTRANSFER, 1); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
echo $result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment