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返回写入的字符数,在这种情况下写的套接字的字节数。