[英]Send Apple Push Notifications via PHP (curl)
Tell me how to send a message by means of a push on the CURL php? 告诉我如何通过在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;
You can't send an Apple Push Notification with CURL. 您无法使用CURL发送Apple Push Notification。
You are attempting to send a push notification to Apple with an HTTPS request. 您正在尝试通过HTTPS请求将推送通知发送给Apple。 That can't work, since Apple Push Notifications don't work with HTTP.
这是行不通的,因为Apple Push Notifications不适用于HTTP。 They only work with a specific binary format over TCP protocol.
它们仅通过TCP协议使用特定的二进制格式。
As a provider you communicate with Apple Push Notification service over a binary interface.
作为提供者,您通过二进制接口与Apple Push Notification服务进行通信。 This interface is a high-speed, high-capacity interface for providers;
此接口是提供者的高速,大容量接口; it uses a streaming TCP socket design in conjunction with binary content.
它结合了二进制内容使用流式TCP套接字设计。 The binary interface is asynchronous
二进制接口是异步的
Instead of CURL, you can stream_context
. 除了CURL,您还可以
stream_context
。 You can find many code samples for that. 您可以找到许多代码示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.