使用 PHP 从 Apple 增强型推送通知中读取错误
我试图触发一个错误,以便我可以为 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...
Im trying to trigger an error so I can build in error logging for APNS. Therefore Im sending a too large payload to the server. But I get no error.
Code:
Connecting:
$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);
}
Sending notification:
$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);
}
Output:
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对此有一个解决方案。
解决方案:
I got a solution for this.
Solution: