gpt4 book ai didi

php - 使用 PHP 从 Apple 增强推送通知中读取错误

转载 作者:搜寻专家 更新时间:2023-10-31 20:51:51 25 4
gpt4 key购买 nike

我试图触发一个错误,以便我可以为 APNS 构建错误日志记录。因此我向服务器发送了一个太大的负载。但我没有收到任何错误。

代码:

连接:

$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $this->_sslPem);
stream_context_set_option($streamContext, 'ssl', 'passphrase', "");

$this->_apnsConnection = stream_socket_client("ssl://" . Config::$apns['host'] . ":" . Config::$apns['port'], $error, $errorString, $timeout, STREAM_CLIENT_CONNECT, $streamContext);

if ($this->_apnsConnection) {
stream_set_blocking($this->_apnsConnection, 0);
}

发送通知:

$this->_log("Sending notification to device token '$deviceToken'");

$identifiers = array();
for ($i = 0; $i < 4; $i++) {
$identifiers[$i] = rand(1, 100);
}

$apnsMessage = chr(1) . chr($identifiers[0]) . chr($identifiers[1]) . chr($identifiers[2]) . chr($identifiers[3]) . pack('N', time() + 3600)
. chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($message)) . $message;
$bytes = fwrite($this->_apnsConnection, $apnsMessage);

$this->_log("bytes written: $bytes");

$this->_log("Fetching response");
$response = fread($this->_apnsConnection, 6);

$this->_log("Strlen: " . strlen($response));

if ($response === false || strlen($response) != 6) {

$this->_log("No response...");
} else {

$responseArray = unpack('Ccommand/CstatusCode/Nidentifier', $response);
$this->_log("Response!");
$this->_log($responseArray);
}

输出:

2011-07-12 16:25:55: Sending notification to device token 'XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX'
2011-07-12 16:25:55: bytes written: 438
2011-07-12 16:25:55: Fetching response
2011-07-12 16:25:55: Strlen: 0
2011-07-12 16:25:55: No response...

最佳答案

我有一个解决方案。

解决方法:

$read = array($this->_apnsConnection);
$null = null;
$changedStreams = stream_select($read, $null, $null, 0, 1000000);

if ($changedStreams === false) {

$this->_log("Error: Unabled to wait for a stream availability");
} elseif ($changedStreams > 0) {

$responseBinary = fread($this->_apnsConnection, 6);
if ($responseBinary !== false || strlen($responseBinary) == 6) {

$response = unpack('Ccommand/Cstatus_code/Nidentifier', $responseBinary);
$this->_log($response);
}
}

关于php - 使用 PHP 从 Apple 增强推送通知中读取错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6665921/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com