通过 PHP (curl) 发送 Apple 推送通知 [英] Send Apple Push Notifications via PHP (curl)

查看:45
本文介绍了通过 PHP (curl) 发送 Apple 推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

告诉我如何通过CURL php上的推送方式发送消息?此承诺不起作用:

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;

推荐答案

您无法使用 CURL 发送 Apple 推送通知.

You can't send an Apple Push Notification with CURL.

您正尝试通过 HTTPS 请求向 Apple 发送推送通知.这是行不通的,因为 Apple 推送通知不适用于 HTTP.它们只能通过 TCP 协议使用特定的二进制格式.

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.

作为提供者,您通过二进制接口与 Apple 推送通知服务进行通信.该接口是提供者的高速、大容量接口;它结合二进制内容使用流式 TCP 套接字设计.二进制接口是异步的

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

您可以stream_context 代替CURL.您可以为此找到许多代码示例.

Instead of CURL, you can stream_context. You can find many code samples for that.

这篇关于通过 PHP (curl) 发送 Apple 推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆