Send Apple Push Notifications via PHP (curl)

两盒软妹~` 提交于 2020-01-16 22:07:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!