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); 

輸出

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

輸出「>> 87 <<」來自何處?你在代碼片段結尾處打印「發送消息」和消息,因此目前還沒有辦法確定它來自哪裏。 –

+0

第三行最後一行回顯結果 –

+0

下面的triphoenix是正確的:您收到的數字是由fwrite寫入的字節。但是你可以使用它來進行錯誤檢查,因爲如果你收到0迴應,這意味着fwrite無法寫入任何內容,可能是因爲Apple關閉了服務器連接。所以它不是帶有0響應的fwrite,它是一個先前的成功發送的fwrite,但是蘋果不喜歡它,所以它們關閉了服務器連接。如果你在SELECT語句中使用「ORDER BY id」,那麼你可以計算出發生問題的地方並從那裏繼續PUSH。 – jsherk

回答

1

在PHP fwrite返回寫入的字符數,在這種情況下寫的套接字的字節數。