1

푸시가 제대로 작동하지만 문제는 피드백이 비어 있다는 것입니다. 만료되었거나 유효하지 않은 상태의 토큰을 삭제해야합니다. 여기 내 밀어 코드입니다 :PHP 푸시 알림 서비스, 피드백이 비어 있습니다.

// Push code example 
$ctx = stream_context_create(); 
stream_context_set_option($ctx, 'ssl', 'local_cert', $certificateName); 
//stream_context_set_option($ctx, 'ssl', 'verify_peer', false); 
//stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); 

// Open a connection to the APNS server 
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err,$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); 

if (!$fp) { 
    exit("Failed to connect: $err $errstr" . PHP_EOL); 
} 

// Create the payload body 
$body['aps'] = array(
    'alert' => $message, 
    'sound' => 'default' 
); 

// Encode the payload as JSON 
$payload = json_encode($body); 

// Build the binary notification 
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload; 

// Send it to the server 
$result = fwrite($fp, $msg, strlen($msg)); 

if (!$result) { 
    echo '<p>The message has not been sent '. PHP_EOL; 
} else { 
    echo '<p>The message has been sent ' . PHP_EOL; 
} 

// Close the connection to the server 
fclose($fp); 

그리고 피드백 코드 나는 1

$ctx = stream_context_create(); 
stream_context_set_option($ctx, 'ssl', 'local_cert', $certificateName); 
stream_context_set_option($ctx, 'ssl', 'verify_peer', false); 
// assume the private key passphase was removed. 
// stream_context_set_option($ctx, 'ssl', 'passphrase', $pass); 

$fp = stream_socket_client('ssl://feedback.sandbox.push.apple.com:2196', $error, $errorString, 60, STREAM_CLIENT_CONNECT, $ctx); 
// production server is ssl://feedback.push.apple.com:2196 

if (!$fp) { 
    //echo "Failed to connect feedback server: $err $errstr\n"; 
    return; 
} else { 
    // echo "Connection to feedback server OK\n"; 
} 

echo "APNS feedback results\n"; 
while ($devcon = fread($fp, 38)) { 
    $arr = unpack("H*", $devcon); 
    $rawhex = trim(implode("", $arr)); 
    $feedbackTime = hexdec(substr($rawhex, 0, 8)); 
    $feedbackDate = date('Y-m-d H:i', $feedbackTime); 
    $feedbackLen = hexdec(substr($rawhex, 8, 4)); 
    $feedbackDeviceToken = substr($rawhex, 12, 64); 
    echo "TIMESTAMP:" . $feedbackDate . "\n"; 
    echo "DEVICE ID:" . $feedbackDeviceToken. "\n\n"; 
} 
fclose($fp); 

을 시도하고 그 결과가 비어 있습니다.

2. // 설정 기본 시간대 date_default_timezone_set ('유럽/부쿠레슈티'); 빈 결과 또한

// Report all PHP errors 
error_reporting(-1); 

// Using Autoload all classes are loaded on-demand 
//require_once 'ApnsPHP/Autoload.php'; 
$feedback = new ApnsPHP_Feedback(
    ApnsPHP_Abstract::ENVIRONMENT_SANDBOX, 
    $certificateName 
); 

// Connect to the Apple Push Notification Feedback Service 
$feedback->connect(); 

$aDeviceTokens = $feedback->receive(); 
if (!empty($aDeviceTokens)) { 
    var_dump($aDeviceTokens . '<br><br>'); 
} 



// Disconnect from the Apple Push Notification Feedback Service 
$feedback->disconnect(); 

3.

// $ stream_context stream_context_create =() 콘텍스트 스트림을 생성;

stream_context_set_option($stream_context, 'ssl', 'local_cert', $certificateName); 
stream_context_set_option($streamContext, 'ssl', 'verify_peer', false); 
$apns = stream_socket_client('ssl://feedback.sandbox.push.apple.com:2196', $errcode, $errstr, 60, STREAM_CLIENT_CONNECT, $stream_context); 
if (!$apns) { 
    echo "ERROR $errcode: $errstr\n"; 
} else { 
    $feedback_tokens = array(); 
    //and read the data on the connection: 
    while (!feof($apns)) { 
     $data = fread($apns, 38); 
     if (strlen($data)) { 
      $feedback_tokens[] = unpack("N1timestamp/n1length/H*devtoken", $data); 
     } 
    } 
    var_dump($feedback_tokens); 

또한 빈 결과에 .... 도와주세요.

답변

1

생산 환경이 정상적으로 작동하고 있지만 Apple 샌드 박스 피드백 서버는 비활성 토큰을 반환하지 않는 것으로 보입니다. Apple Push Notification Feedback Service - how frequently does it check

제안 된 해결이 장치에 두 개발 애플 리케이션을 가지고있다 다음 중 하나를 삭제하려면 :
이 스레드에서보세요. 삭제 된 것이 비활성 토큰 목록에 나타납니다.

+0

이것은 또한 내가 알아 차린 것입니다. 얼마 후 그것은 단지 작동했습니다 ... 이상한 사과. 고맙습니다 –