3

我正在使用 expiredate 参数在 php 中传递。我想使用 Apple 推送通知更新传递。根据 Passbook 文档,您需要使用 Apple Push Notification Service 触发从 iOS 设备拉取以更新 Passbook。

4

1 回答 1

1

这是我将通知推送到 APNS 的 PHP 代码。你可以参考。

$apnsHost = 'gateway.push.apple.com';
$apnsPort = 2195;
$apnsCert = base_path('certificates.pem');
$push_token = 'device token';
$passIdentify = 'pass indentify';

$payload = '{}';
$msg = chr(0) . pack('n', 32) . pack('H*', $push_token) . pack('n', strlen($payload)) . $payload . pack('n', strlen($passIdentify)) . $passIdentify;

$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);

fwrite($apns, $msg);

@socket_close($apns);
fclose($apns);

Certificates.pem 与您在 .p12 扩展名中用于签署通行证的证书相同。因此,您需要使用以下代码将其导出为 .pem

$ cd ~/Desktop
$ openssl pkcs12 -in WenderCastPush.p12 -out WenderCastPush.pem -nodes -clcerts

根据本教程https://www.raywenderlich.com/123862/push-notifications-tutorial#comments

于 2016-09-29T09:57:32.320 回答