0

我在 php 中使用流在 iOS 中进行推送通知。当我打印 fwrite 的结果时,它返回的数字很好。它没有错误。但是我们没有在设备中收到通知。

这是我的代码示例,

$ctx = stream_context_create();
if (ENV == 'live') {
    stream_context_set_option($ctx, 'ssl', 'local_cert', APP_DIR.'live.pem'); // Live
}else{
    stream_context_set_option($ctx, 'ssl', 'local_cert', APP_DIR.'local.pem'); // Dev
}

stream_context_set_option($ctx, 'ssl', 'passphrase', '123456');


if (ENV == 'live') {
    $url = 'ssl://gateway.push.apple.com:2195';
}else{
    $url = 'ssl://gateway.sandbox.push.apple.com:2195';
}

$fp = stream_socket_client($url, $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

if (!$fp)
    return false;

$body['aps'] = array(
    'alert' => array(
        'content-available' => 1,
        'title' => 'Title',
        'body' => 'Message',
        ),
    'sound' => 'default',
    'url' => 'asdas'
);

$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
fclose($fp);

if ($result){
    
    return 1;
}
else{
    return 0;
}

谢谢你

4

0 回答 0