问题
Tell me how to send a message by means of a push on the CURL php? This commitment does not work:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://gateway.push.apple.com:2195');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSLCERT,'1.pem');
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "12345");
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"device_tokens": ["........................................."], "aps": {"alert": "test message one!"}}');
$curl_scraped_page = curl_exec($ch);
echo $curl_scraped_page;
回答1:
You can't send an Apple Push Notification with CURL.
You are attempting to send a push notification to Apple with an HTTPS request. That can't work, since Apple Push Notifications don't work with HTTP. They only work with a specific binary format over TCP protocol.
As a provider you communicate with Apple Push Notification service over a binary interface. This interface is a high-speed, high-capacity interface for providers; it uses a streaming TCP socket design in conjunction with binary content. The binary interface is asynchronous
Instead of CURL, you can stream_context
. You can find many code samples for that.
来源:https://stackoverflow.com/questions/22425758/send-apple-push-notifications-via-php-curl