我向传球发出推送通知。如何只用1行发送到两个网址?我使用此代码:$ConnectAPNS = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $streamContext);
$ConnectAPNS1 = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $streamContext);
答案 0 :(得分:1)
所有Passbook APNS请求都应该使用生产服务器,因此您可以完全删除'ssl://gateway.sandbox.push.apple.com:2195`行。要发送多个设备的请求,只需在流打开时写入该流。
// Code edited to match info provided in the comments below.
$to_push = array();
$payload = json_encode(array('aps' => ''));
while($device = mysql_fetch_array($query2,MYSQL_ASSOC)){
$to_push[] = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $device['pushToken;])) . chr(0) . chr(mb_strlen($payload)) . $payload;
}
$ConnectAPNS = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $streamContext);
foreach ($to_push as $push)
fwrite($ConnectAPNS, $push);
fclose($ConnectAPNS);
在上面的代码中,将$ device_query替换为包含从数据库中检索到的设备的对象。另外,请验证pushToken
是否与您的列名匹配,如果没有用正确的值替换它。