gpt4 book ai didi

ios6 - 发送推送通知时如何从 APN 获取反馈

转载 作者:行者123 更新时间:2023-12-02 21:29:12 25 4
gpt4 key购买 nike

现在我可以从已经安装了通行证的设备发送推送 token ,但我不知道此时反馈是如何工作的。根据Apple文档,Apple推送通知服务(APNs)向服务器提供反馈以判断pushToken是否有效。如何获得此反馈?我尝试了这段代码,但有很多错误。这是代码:

<?php
$cert = '/Applications/MAMP/htdocs/passesWebserver/certificates.pem';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $cert);
stream_context_set_option($ctx, 'ssl', 'verify_peer', false);

$fp = stream_socket_client('ssl://feedback.sandbox.push.apple.com:2196', $error, $errorString, 60, STREAM_CLIENT_CONNECT, $ctx);
// production server is ssl://feedback.push.apple.com:2196

if (!$fp) {
error_log("Failed to connect feedback server: $err $errstr",0);
return;
}
else {
error_log("Connection to feedback server OK",0);
}
error_log("APNS feedback results",0);
while ($devcon = fread($fp, 38))
{
$arr = unpack("H*", $devcon);
$rawhex = trim(implode("", $arr));
$feedbackTime = hexdec(substr($rawhex, 0, 8));
$feedbackDate = date('Y-m-d H:i', $feedbackTime);
$feedbackLen = hexdec(substr($rawhex, 8, 4));
$feedbackDeviceToken = substr($rawhex, 12, 64);
error_log ("TIMESTAMP:" . $feedbackDate, 0);
error_log ( "DEVICE ID:" . $feedbackDeviceToken,0);
}
fclose($fp);
?>

最佳答案

这应该有效。您不需要对每个推送请求都运行它。根据您的更新频率和设备数量,您可以设置每日或每周的 cron 作业。

$cert_file = '/path/to/combined/cert.pem';
$cert_pw = 'top secret';

$stream_context = stream_context_create();
stream_context_set_option($stream_context, 'ssl', 'local_cert', $cert_file);
if (strlen($cert_pw))
stream_context_set_option($stream_context, 'ssl', 'passphrase', $cert_pw);

$apns_connection = stream_socket_client('feedback.push.apple.com:2196', $error_code, $error_message, 60, STREAM_CLIENT_CONNECT, $stream_context);

if($apns_connection === false) {
apns_close_connection($apns_connection);

error_log ("APNS Feedback Request Error: $error_code - $error_message", 0);
}

$feedback_tokens = array();

while(!feof($apns_connection)) {
$data = fread($apns_connection, 38);
if(strlen($data)) {
$feedback_tokens[] = unpack("N1timestamp/n1length/H*devtoken", $data);
}
}
fclose($apns_connection);


if (count($feedback_tokens))
foreach ($feedback_tokens as $k => $token) {
// code to delete record from database
}

关于ios6 - 发送推送通知时如何从 APN 获取反馈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15943671/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com