从 APNS-php 错误中检索令牌
我正在尝试实现 APNS-PHP,并发现在我的测试环境中我有一些无效的令牌(当测试设备转移到生产环境时)。
我需要从数组中的序列化对象获取令牌 ID,因为我想捕获这种情况并从数据库中删除无效令牌。我使用以下代码,但这不起作用:
$aErrorQueue = $push->getErrors();
if (!empty($aErrorQueue)) {
foreach($aErrorQueue as $error){
foreach($error['ERRORS'] as $err){
$message .= $err['statusMessage'] . " ";
if($err['statusCode'] == 8){
$phones = Phone::getPhonesWithToken($error['MESSAGE']['_aDeviceTokens:protected'][0]);
Phone::setToken($phones[0]['id'], "");
}
}
}
}
问题是 APNS_Message 是 $error['MESSAGE'] 中的序列化对象,并且我不记得如何访问该对象中的令牌...
Var dump:
["消息"]=> 对象(ApnsPHP_Message)#9 (8) { [“_bAutoAdjustLongPayload:受保护”]=> 布尔(真) [“_aDeviceTokens:受保护”] => 数组(1) { [0]=>;字符串(64) “018E4B9CB8CF73341CE4EBE7138E25E605CD80FB74B3A9701CE5CCA6D9363F3A” } ["_sText:受保护"]=>无效的 ["_nBadge:受保护"]=>整数(256) [“_sSound:受保护”] =>无效的 [“_aCustomProperties:受保护”] => NULL ["_nExpiryValue:protected"]=> 整数(604800) [“_mCustomIdentifier:受保护”] => 字符串(17)“消息徽章-004”}
I am trying to implement APNS-PHP, and discovered that in my test environment I have a few invalid tokens (as the test devices moved to production).
I need to get the token ID from a serialized object in an array, as I want to catch this scenario and remove the invalid tokens form the DB. I use the following code, but that doesn't work:
$aErrorQueue = $push->getErrors();
if (!empty($aErrorQueue)) {
foreach($aErrorQueue as $error){
foreach($error['ERRORS'] as $err){
$message .= $err['statusMessage'] . " ";
if($err['statusCode'] == 8){
$phones = Phone::getPhonesWithToken($error['MESSAGE']['_aDeviceTokens:protected'][0]);
Phone::setToken($phones[0]['id'], "");
}
}
}
}
The problem is that the APNS_Message is the serialized object in $error['MESSAGE'], and I cannot remember how to access the token in that object...
Var dump:
["MESSAGE"]=>
object(ApnsPHP_Message)#9 (8) {
["_bAutoAdjustLongPayload:protected"]=>
bool(true)
["_aDeviceTokens:protected"]=>
array(1) { [0]=> string(64)
"018E4B9CB8CF73341CE4EBE7138E25E605CD80FB74B3A9701CE5CCA6D9363F3A"
} ["_sText:protected"]=> NULL
["_nBadge:protected"]=> int(256)
["_sSound:protected"]=> NULL
["_aCustomProperties:protected"]=>
NULL ["_nExpiryValue:protected"]=>
int(604800)
["_mCustomIdentifier:protected"]=>
string(17) "Message-Badge-004" }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
_aDeviceTokens
是一个受保护的属性,你会发现直接访问这个属性会抛出异常。您应该改为使用
Message
对象上的getRecipients()
或getRecipient($recipientNumber = 0)
方法来检索设备令牌。例如:
_aDeviceTokens
is a protected property, you will find that accessing this property directly will throw an exception.You should instead use the
getRecipients()
orgetRecipient($recipientNumber = 0)
method on theMessage
object to retrieve the device token(s).For example:
$error['MESSAGE']->_aDeviceTokens[0]
$error['MESSAGE']->_aDeviceTokens[0]