APNS推送PHP错误的响应

时间:2017-05-05 16:47:52

标签: php apn

我们确实遇到了通过APNS发送推送的问题。因为看起来我们确实从苹果得到了错误的回应。推送已发送,但我们收到错误响应,导致多次发送推送。有没有其他人遇到类似的问题或我错过了什么?

<?php
private function checkAppleErrorResponse($apns, PushToken $token)
{

    //byte1=always 8, byte2=StatusCode, bytes3,4,5,6=identifier(rowID). Should return nothing if OK.
    $apple_error_response = fread($apns, 6);


    if ($apple_error_response) {
        //unpack the error response (first byte 'command" should always be 8)
        $error_response = unpack('Ccommand/Cstatus_code/Nidentifier', $apple_error_response);

        if ($error_response['status_code'] == '0') {
            $error_response['status_code'] = '0-No errors encountered';
        } else if ($error_response['status_code'] == '1') {
            $error_response['status_code'] = '1-Processing error';
        } else if ($error_response['status_code'] == '2') {
            $error_response['status_code'] = '2-Missing device token';
        } else if ($error_response['status_code'] == '3') {
            $error_response['status_code'] = '3-Missing topic';
        } else if ($error_response['status_code'] == '4') {
            $error_response['status_code'] = '4-Missing payload';
        } else if ($error_response['status_code'] == '5') {
            $error_response['status_code'] = '5-Invalid token size';
        } else if ($error_response['status_code'] == '6') {
            $error_response['status_code'] = '6-Invalid topic size';
        } else if ($error_response['status_code'] == '7') {
            $error_response['status_code'] = '7-Invalid payload size';
        } else if ($error_response['status_code'] == '8') {
            $error_response['status_code'] = '8-Invalid token';
        } else if ($error_response['status_code'] == '255') {
            $error_response['status_code'] = '255-None (unknown)';
        } else {
            $error_response['status_code'] = $error_response['status_code'] . '-Not listed';
        }

        if ($token->isExistingUser()) {
            $this->logger->error('#cloudalarm User-Id: ' . $token->getAssociatedUser() . ': Something went wrong with APNS pushing , error is ' . $error_response['status_code']);
        } else {
            $this->logger->error('#cloudalarm  for simple login id ' . $token->getAssociatedUser() . ': Something went wrong with APNS pushing , error is ' . $error_response['status_code']);
        }

        return true;
    }

    return false;
}
?>

1 个答案:

答案 0 :(得分:1)

我认为你误解了这个错误。通常,响应代码旨在帮助您管理列表。如果您收到“无效令牌”错误,则通常会附带更新的令牌,删除无效令牌并在其中插入新令牌。请注意,APNS会自动“转发”此消息,通知只是为了帮助您保持最新状态。

如果您没有获得更新的令牌,那么可能是您的应用已删除但未重新安装,因此令牌无效。