【发布时间】:2015-08-27 01:14:08
【问题描述】:
我的数据库中注册了 16 台设备。当我推送到单个设备时,它发送和接收成功,但是当我迭代到我的所有设备时,它发送成功,但从未接收到。这是我的 php 代码:
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck_prod.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', 'password');
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
$pid = 0;
$msg = '';
// this where it goes if we try to send single device, we define the device token to send
if ($device_token != '')
{
$token = $device_token;
$payload = json_encode($body);
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $token)) . pack("n",strlen($payload)) . $payload;
if(!$fp)
{
$this->api_model->update_ios_push($device_token, $message, 'failed', $amg_id);
}
else
{
$this->api_model->update_ios_push($device_token, $message, 'delivered', $amg_id);
}
fwrite($fp, $msg);
}
//this if we want to send to all devices in db.
else
{
foreach ($devices as $device)
{
$token = $device['devicetoken'];
$payload = json_encode($body);
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $token)) . pack("n",strlen($payload)) . $payload;
if(!$fp)
{
$this->api_model->update_ios_push($device['pid'], $message, 'failed', $amg_id);
}
else
{
$this->api_model->update_ios_push($device['pid'], $message, 'delivered', $amg_id);
}
$pid++;
fwrite($fp, $msg);
}
}
fclose($fp);
它发送成功,但从未在设备上接收。以前的项目还可以,但现在这段代码不再工作了。
【问题讨论】:
-
仔细检查你
$device['devicetoken']可能与$device_token不一样 -
正确,您可以看到输出,它返回正确的令牌正在发送。
标签: php ios push-notification apple-push-notifications