码迷,mamicode.com
首页 > 移动开发 > 详细

ios推送消息php做推送服务器

时间:2014-07-10 23:53:40      阅读:357      评论:0      收藏:0      [点我收藏+]

标签:ios推送   php推送   ios推送php服务器   

<?php
    /**
     * Main method to run the object
     * $message 消息内容
     * $deviceToken  这里是iphone手机唯一的Token码(记得去掉空格)
     * $badge  就是应用图标右上角那个数字
     * $sound  消息的声音
     * $apnsCert 证书路径
     * $passphrase  私钥的密码(可以不写)
     */
    public function iosPush($message,$deviceToken,$badge=1,$sound='Duck.wav',$apnsCert,$passphrase){
        $body['aps'] = array('alert' => $message);
        if ($badge)
          $body['aps']['badge'] = $badge;
        if ($sound)
          $body['aps']['sound'] = $sound;
        $payload = json_encode($body);
        $ctx = stream_context_create();
        stream_context_set_option($ctx, 'ssl', 'local_cert', $apnsCert);
        stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
        $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
        if (!$fp) {
            print_r();
            print "Failed to connect $err $errstr\n";
            return;
        }
        else {
           print $message;
           print "Connection OK\n<br/>";
        }
        $msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
        print "Sending message :" . $payload . "\n";
        fwrite($fp, $msg);
        fclose($fp);

    }


?>


ios推送消息php做推送服务器,布布扣,bubuko.com

ios推送消息php做推送服务器

标签:ios推送   php推送   ios推送php服务器   

原文地址:http://blog.csdn.net/maildocgaojingru/article/details/37598153

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!