php – 如何知道所有设备令牌在循环中发送推送通知(APNS)?
发布时间:2020-12-13 22:02:27 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试使用 PHP代码发送给下载我的iPhone应用程序的所有令牌.你能告诉我如何发送到多个设备以及如何进入设备令牌循环吗? 这是我的代码: ?php$deviceToken = ''; // HERE I CAN SEND TO ONE DEVICE// Passphrase for the private key (ck.pem file)// $
我正在尝试使用
PHP代码发送给下载我的iPhone应用程序的所有令牌.你能告诉我如何发送到多个设备以及如何进入设备令牌循环吗?
这是我的代码: <?php $deviceToken = ''; // HERE I CAN SEND TO ONE DEVICE // Passphrase for the private key (ck.pem file) // $pass = ''; // Get the parameters from http get or from command line $message = $_GET['message'] or $message = $argv[1] or $message = 'MY NOTIFICATION BODY'; $badge = (int)$_GET['badge'] or $badge = (int)$argv[2]; $sound = $_GET['sound'] or $sound = $argv[3]; // Construct the notification payload $body = array(); $body['aps'] = array('alert' => $message); if ($badge) $body['aps']['badge'] = $badge; if ($sound) $body['aps']['sound'] = $sound; /* End of Configurable Items */ $ctx = stream_context_create(); stream_context_set_option($ctx,'ssl','local_cert','apns-dev.pem'); // assume the private key passphase was removed. // stream_context_set_option($ctx,'passphrase',$pass); $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195',$err,$errstr,60,STREAM_CLIENT_CONNECT,$ctx); if (!$fp) { print "Failed to connect $err $errstrn"; return; } else { print "Connection OKn"; } $payload = json_encode($body); $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); ?> 解决方法
我写了一个关于推送通知的教程.我建议你阅读它,这样你就能更好地理解你应该做的事情:
http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |