douliang6563 2016-05-20 11:57
浏览 43
已采纳

如何在不使用循环的情况下发送ios批量推送

Right now I use loop to send bulk points, I want to send bulk push in ios, how can I send this without using loop.

Here is my code:

function sendToBulkIphone($artistID,$type="artist") {
            $deviceToken            =       $this->deviceToken;
            $message                =       $this->message;
            $postid                 =       $this->postid;
            $notificationtype       =       $this->NotificationType;
            $time                   =       $this->time;
            $ctx = stream_context_create();
            stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushkey/artist_'.$artistID.'/ck_user_production.pem');
            stream_context_set_option($ctx, 'ssl', 'passphrase', '1234'); STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
            STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
            $fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

            if (!$fp)
            exit("Failed to connect: $err $errstr" . PHP_EOL);
            $body['aps'] = array(
                                                    'alert' => $message,
                                                    'sound' => 'default'
                                            );
            $body['title']="Notification";
            $body['message']=$message;
            $body['postid']=$postid;
            $body['NotificationType']=$notificationtype;
            $body['time']=$time;

            for($n=0;$n<count($deviceToken); $n++) {
                // Build the binary notification
                $payload = json_encode($body);
                $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken[$n]). pack('n', strlen($payload)) . $payload;

                $result = fwrite($fp, $msg, strlen($msg));//, strlen($msg)

                if (!$result) {
                        $jsondata['message'] = 'Message not delivered';
                        $jsondata['status'] = 0;
                }
                else {
                        $jsondata['message'] = 'Message successfully delivered';
                        $jsondata['status'] = 1;
                }
            }
            fclose($fp);
            return true;
    }

Can anyone please tell me how can I resolve this issue ?

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架