服务器端 iPhone APNS 通信

发布于 2024-07-26 04:53:17 字数 257 浏览 4 评论 0原文

我有一个快速的问题。 对于苹果推送通知服务,我需要有自己的服务器,它将向苹果服务器发送推送通知,对吧?

我可以在常规虚拟主机帐户上使用简单的 PHP 脚本来执行此操作吗?或者我是否需要具有完整管理访问权限的专用服务器?

如果这在 PHP 中是可能的,任何人都可以向我指出一些可以帮助我开始这一点的示例吗? 现在,我非常有信心在实现客户端部分时不会遇到麻烦,但服务器端对我来说仍然有些神秘......

谢谢!

弗洛里安

I have a quick question. For the apple push notification service, I need to have my own server, which will send out the push notifications to the apple servers, right?

Can I do this with a simple PHP script on a regular webhosting account, or do I need a dedicated server with full blown admin access for that?

If this is possible in PHP, can anyone point me to some samples that can help me get started on this? Right now, I am pretty confident I won't have trouble implementing the client-side part, but the server side is still somewhat of a mystery to me...

Thank you!

Florian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟─花易冷 2024-08-02 04:53:17

只要您可以在大部分时间保持与服务器的连接打开,您就可以在有限的托管帐户上执行此操作。 一些示例代码:

http://code.google.com/p/php-apns/< /a>

另请注意,一些公司正在启动服务来专门帮助您进行推送托管(我将保持帖子中立,不提及名称,我不确定哪些服务正在运行)。

You probably will be able to do this on a limited hosting account, as long as you can leave the connection open to the server most of the time. Some sample code:

http://code.google.com/p/php-apns/

Note also that some companies are starting up services to help you specifically with push hosting (I'll keep the post neutral and not mention names, I'm not sure which services are running just yet).

安静 2024-08-02 04:53:17

APNS 的主要问题是端口,

因此许多提供商不打开 2195 端口

,因此一开始就集中精力,然后去找主机提供商

这是我尝试过的代码,但有一个问题是无法获取设备通知

嗨,

我尝试了以下代码(PHP)

$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apple_push_notification_production.pem';

$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
if($apns)
{
    echo "Connection Established<br/>";
    $deviceToken = '**********';//masked

    $body = array();
    $body['aps'] = array(’alert’ => "test message");
    //$body['aps']['badge'] = 1;

    $payload = json_encode($body);


    $apnsMessage = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
    print "sending message :" . $apnsMessage . "<br/>";
    print "sending payload :" . $payload . "<br/>";
    fwrite($apns, $apnsMessage);

}
else
{   
    echo "Connection Failed";

    echo $errorString;
    echo $error;
}
socket_close($apns);
fclose($apns);  

回复已建立连接
正在发送消息 :�� d^÷Îå0ZCd%1äuwOOYš'ÊÈ}ârðm⁄Í�,{"aps":{"\u2019alert\u2019":"测试消息"}}
发送有效负载:{“aps”:{“\u2019alert\u2019”:“测试消息”}}

但无法获得通知

任何帮助?

The Main problem with APNS is ports

so many providers doesnt open 2195 port

so concentrate on that initially then go for the host provider

Here is the code what i tried, but one problem is not able to get device notification

Hi ,

i tried the following code (PHP)

$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apple_push_notification_production.pem';

$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
if($apns)
{
    echo "Connection Established<br/>";
    $deviceToken = '**********';//masked

    $body = array();
    $body['aps'] = array(’alert’ => "test message");
    //$body['aps']['badge'] = 1;

    $payload = json_encode($body);


    $apnsMessage = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
    print "sending message :" . $apnsMessage . "<br/>";
    print "sending payload :" . $payload . "<br/>";
    fwrite($apns, $apnsMessage);

}
else
{   
    echo "Connection Failed";

    echo $errorString;
    echo $error;
}
socket_close($apns);
fclose($apns);  

reply is Connection Established
sending message :�� d^÷Îå0ZCd%1ÄuwOOYš'ÊÈ}ârðm¾Í�,{"aps":{"\u2019alert\u2019":"test message"}}
sending payload :{"aps":{"\u2019alert\u2019":"test message"}}

But am not able to get the notification

any help?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文