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 Push Notification Feedback Service - how frequently does it check

建議的解決方案是在您的設備上有兩個開發應用程序,然後刪除一個。已刪除的應該出現在非活動令牌列表中。

+0

這也是我注意到的。一段時間後,它剛剛工作......怪異的蘋果。謝謝 –

相關問題