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); } ?>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。