简体   繁体   English

推送iOS无效

[英]Push IOS don't work

I created a PhoneGap application and I use PushPlugin for notifications. 我创建了一个PhoneGap应用程序,并使用PushPlugin进行通知。

I created my ck.pem and everything worked in development. 我创建了ck.pem,所有内容都在开发中工作。 Then I posted my application and created ck.pem production and it does not work. 然后,我发布了我的应用程序并创建了ck.pem生产,它不起作用。

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时,请确保您的应用程序正在使用临时证书,否则很有可能会失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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