0

PHP에서 푸시 알림을 보내고 있습니다. 결과 변수에 "87"이 있습니다. 무엇 않습니다 그 의미.푸시 알림 결과 87

<?php 
    $deviceToken = "a448b8946a5de3801dc6a11862a5a0bf11f1adc16xxxxxxxxxxxx"; // masked for security reason 
    // Passphrase for the private key 
    $pass = 'molik'; 

    // Get the parameters from http get or from command line 
    $message = $_GET['message'] or $message = $argv[1] or $message = 'Test Message'; 
    //$badge = (int)$_GET['badge'] or $badge = (int)$argv[2] or $badge = 1; 
    $sound = $_GET['sound'] or $sound = $argv[3] or $sound = 'default'; 

    // Construct the notification payload 
    $body = array(); 
    $body['aps'] = array('alert' => $message); 
    if ($badge) 
    $body['aps']['badge'] = $badge; 
    if ($sound) 
    $body['aps']['sound'] = $sound; 


    /* End of Configurable Items */ 
    $ctx = stream_context_create(); 
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem'); 
    // assume the private key passphase was removed. 
    stream_context_set_option($ctx, 'ssl', 'passphrase', $pass); 

    // for production change the server to ssl://gateway.push.apple.com:219 
    $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx); 

    if (!$fp) { 
     print "Failed to connect $err $errstr\n"; 
     return; 
    } 
    else { 
     print "Connection OK\n"; 
    } 

    $payload = json_encode($body); 
    $msg = chr(0) . pack("n",32) . pack('H*', $deviceToken) . pack("n",strlen($payload)) . $payload; 
    print "sending message :" . $payload . "\n"; 

    $result=fwrite($fp, $msg); 

    echo ">>" .$result ."<<" . PHP_EOL; 
    fclose($fp); 

출력이 경우에, 당신의 소켓에 기록 된 바이트의 수를 쓴 문자 수를 반환 fwrite PHP에서

Connection OK 
sending message :{"aps":{"alert":"Test Message","sound":"default"}} 
>>87<< 
+0

정확하게 ">> 87 <<"출력은 어디에서 왔습니까? 코드 스 니펫 (snippet)은 "메시지 보내기"와 메시지를 인쇄하는 줄에서 끝나기 때문에 어디서 왔는지 판단 할 방법이 없습니다. –

+0

세 번째 마지막 줄 에코 결과 –

+0

아래의 triphoenix가 정확합니다. 수신하는 번호는 fwrite에 의해 쓰여진 바이트입니다. 하지만 당신이 0 응답을 받으면 fwrite가 아무 것도 쓸 수 없다는 것을 의미하기 때문에 에러 체크를 위해 이것을 사용할 수 있습니다. 아마도 애플이 서버 연결을 닫았 기 때문일 것입니다. 그래서 문제가 0 인 fwrite가 아니라 성공적으로 전송 된 이전 fwrite이지만 사과가 마음에 들지 않아서 서버 연결을 종료했습니다. SELECT 문에 "ORDER BY id"를 사용하면 문제가 발생한 위치를 대략 알아낼 수 있고 거기에서 PUSH를 계속 진행할 수 있습니다. – jsherk

답변

1

.