我正在尝试实现 APNS-PHP,并发现在我的测试环境中有一些无效 token (随着测试设备移至生产环境)。
我需要从数组中的序列化对象获取 token ID,因为我想捕获这种情况并从数据库中删除无效 token 。我使用以下代码,但这不起作用:
$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'] 中的序列化对象,我不记得如何访问该对象中的 token ...
变量转储:
["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" }
最佳答案
_aDeviceTokens
是一个 protected 属性,你会发现直接访问这个属性会抛出异常。
您应该改为使用 Message
对象上的 getRecipients()
或 getRecipient($recipientNumber = 0)
方法来检索设备 token (s).
例如:
$token = $error['MESSAGE']->getRecipient();
关于php - 从 APNS-php 错误中检索 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5537619/