简体   繁体   中英

Push IOS don't work

I created a PhoneGap application and I use PushPlugin for notifications.

I created my ck.pem and everything worked in development. Then I posted my application and created ck.pem production and it does not work.

This is my function to push :

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

and the result :

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) 

Thanks for your help.

尝试将生产环境用于APNS时,请确保您的应用程序正在使用临时证书,否则很有可能会失败。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM