簡體   English   中英

推送iOS無效

[英]Push IOS don't work

我創建了一個PhoneGap應用程序,並使用PushPlugin進行通知。

我創建了ck.pem,所有內容都在開發中工作。 然后,我發布了我的應用程序並創建了ck.pem生產,它不起作用。

這是我要推送的功能:

$passphrase = '********';
$message = $titre;

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', '********/ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

// Open a connection to the APNS server
$fp = stream_socket_client(
    'ssl://gateway.push.apple.com:2195', $err,
    $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
    var_dump($fp); echo "<br/>";
if (!$fp)
    die("Failed to connect: $err $errstr" . PHP_EOL);

$body['aps'] = array(
    'alert' => $message,
    'sound' => 'default',
    'id' => $id
    );

// Encode the payload as JSON
$payload = json_encode($body);
echo $payload."<br/>";
$ids = get_list_ids_smartphone_ios();
foreach ($ids as $id){
    echo $id."<br/>";
    // Build the binary notification
    $msg = chr(0) . pack('n', 32) . pack('H*', $id) . pack('n', strlen($payload)) . $payload;
    echo $msg."<br/>";
    // Send it to the server
    $result = fwrite($fp, $msg, strlen($msg));
    var_dump($result); echo "<br/>";
    if (!$result)
        die('Erreur à l\'envoi d\'une notification push pour IOS');
}

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

結果:

resource(1280) of type (persistent stream) 
{"aps":{"alert":"this is a test","sound":"default","id":13299}}
abc46897b077eec6bb477edabb7a620e9d79a967c0a0d689dbc6c17d10eb9fef
îÄh—°wîÆ»G~Ú»zby©gÀ Ö‰ÛÆÁ}ëŸïl{"aps":{"alert":"this is a test","sound":"default","id":13299}}
int(145) 
ab33c500d0e8ac8211ac7b8834e4053266e65f046aca5af7ae1fa4bc41ca33e5
Ö3ÅÐ謂¬{ˆ4ä2fæ_jÊZ÷®¤¼AÊ3ål{"aps":{"alert":"this is a test","sound":"default","id":13299}}
int(145) 

謝謝你的幫助。

嘗試將生產環境用於APNS時,請確保您的應用程序正在使用臨時證書,否則很有可能會失敗。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM