0

我对通行证进行推送通知。如何仅用 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);

4

1 回答 1

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与您的列名匹配,如果不将其替换为正确的值。

于 2013-05-02T09:04:28.233 回答