всегда получает ответ обратной связи APNS ЛОЖЬ, даже если я ошибаюсь apns_regid

Когда я передаю apns_regid как «123456789»,
он посылает мне ответ как ложный. На самом деле этот токен неправильный, я должен получить ответ как недействительный токен,
Когда я передаю правильный токен (apns_regid), он дает мне False, что правильно в соответствии с функцией «checkAppleErrorResponse».

Пожалуйста, помогите мне узнать, где ошибка в моем коде

$apns_port = 2195;
$apns_url = 'gateway.push.apple.com';
$pathCk = $this->container->get('kernel')->locateResource('@MainAdminBundle/Controller/client.pem');
$passphrase = '123';
if (!empty($apns_url) && $apns_url != "") {
$data = json_decode($message);
$response = $response1 = "";
$payload['job_id'] = $data->code;
$code = $data->code;
$detail =  $data->detail;
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $pathCk);
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$apns = stream_socket_client('ssl://' . $apns_url . ':' . $apns_port, $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
stream_set_blocking($apns, 0);
foreach ($apns_user_list as $key => $val) {//
$device = $val['apns_regid'];
if ( $apns != NULL && $apns != '' && !empty($apns) && $apns!= false) {
$payload['aps'] = array(
'alert' => $data->detail,
'badge' => 1,
'sound' => 'default',
'response' => $data->response
);
$final_payload = json_encode($payload);
$apnsMessage = chr(0) . pack('n', 32) . pack('H*', str_replace(' ', '', $device)) . pack('n', strlen($final_payload)) . $final_payload;
$result = '';
try {
$result = fwrite($apns, $apnsMessage , strlen($apnsMessage));
$resp = $this->checkAppleErrorResponse($apns);
var_dump($resp);
exit;
} catch (\Exception $e) {
fclose($apns);
$result = $e->getMessage();
echo('<br>Error sending Device: ' . $device );
echo('<br>Error sending payload: ' . $e->getMessage());
$current .= '<br>Error sending Device: ' . $device ;
$current .= '<br>Error sending payload: ' . $e->getMessage() ;
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $pathCk);
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$apns = stream_socket_client('ssl://' . $apns_url . ':' . $apns_port, $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
stream_set_blocking($apns, 0);
echo "in catch";
exit;
}
}
}
}
// FUNCTION to check if there is an error response from Apple Returns TRUE if there was and FALSE if there was not
public function checkAppleErrorResponse($fp) {
//byte1=always 8, byte2=StatusCode, bytes3,4,5,6=identifier(rowID).
// Should return nothing if OK.
//NOTE: Make sure you set stream_set_blocking($fp, 0) or else fread will pause your script and wait
// forever when there is no response to be sent.
$apple_error_response = fread($fp, 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';
}
echo '<br><b>+ + + + + + ERROR</b> Response Command:<b>' . $error_response['command'] . '</b>&nbsp;&nbsp;&nbsp;Identifier:<b>' . $error_response['identifier'] . '</b>&nbsp;&nbsp;&nbsp;Status:<b>' . $error_response['status_code'] . '</b><br>';

echo 'Identifier is the rowID (index) in the database that caused the problem, and Apple will disconnect you from server. To continue sending Push Notifications, just start at the next rowID after this Identifier.<br>';
return true;
}
return false;
}

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector