gpt4 book ai didi

ios - PHP 推送通知服务,反馈为空

转载 作者:行者123 更新时间:2023-11-29 13:33:56 25 4
gpt4 key购买 nike

推送工作正常,问题是反馈是空的。我需要删除已过期或状态无效的 token 。这是我的推送代码:

// Push code example
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $certificateName);
//stream_context_set_option($ctx, 'ssl', 'verify_peer', false);
//stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

// Open a connection to the APNS server
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err,$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

if (!$fp) {
exit("Failed to connect: $err $errstr" . PHP_EOL);
}

// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);

// Encode the payload as JSON
$payload = json_encode($body);

// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));

if (!$result) {
echo '<p>The message has not been sent '. PHP_EOL;
} else {
echo '<p>The message has been sent ' . PHP_EOL;
}

// Close the connection to the server
fclose($fp);

还有我试过的反馈代码1.

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $certificateName);
stream_context_set_option($ctx, 'ssl', 'verify_peer', false);
// assume the private key passphase was removed.
// stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);

$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) {
//echo "Failed to connect feedback server: $err $errstr\n";
return;
} else {
// echo "Connection to feedback server OK\n";
}

echo "APNS feedback results\n";
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);
echo "TIMESTAMP:" . $feedbackDate . "\n";
echo "DEVICE ID:" . $feedbackDeviceToken. "\n\n";
}
fclose($fp);

结果为空。

2。 //设置默认时区 date_default_timezone_set('欧洲/布加勒斯特');

// Report all PHP errors
error_reporting(-1);

// Using Autoload all classes are loaded on-demand
//require_once 'ApnsPHP/Autoload.php';
$feedback = new ApnsPHP_Feedback(
ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
$certificateName
);

// Connect to the Apple Push Notification Feedback Service
$feedback->connect();

$aDeviceTokens = $feedback->receive();
if (!empty($aDeviceTokens)) {
var_dump($aDeviceTokens . '<br><br>');
}



// Disconnect from the Apple Push Notification Feedback Service
$feedback->disconnect();

结果也是空的

3.

//创建上下文流$stream_context = stream_context_create();

stream_context_set_option($stream_context, 'ssl', 'local_cert', $certificateName);
stream_context_set_option($streamContext, 'ssl', 'verify_peer', false);
$apns = stream_socket_client('ssl://feedback.sandbox.push.apple.com:2196', $errcode, $errstr, 60, STREAM_CLIENT_CONNECT, $stream_context);
if (!$apns) {
echo "ERROR $errcode: $errstr\n";
} else {
$feedback_tokens = array();
//and read the data on the connection:
while (!feof($apns)) {
$data = fread($apns, 38);
if (strlen($data)) {
$feedback_tokens[] = unpack("N1timestamp/n1length/H*devtoken", $data);
}
}
var_dump($feedback_tokens);

结果也是空的....请帮忙。

最佳答案

Apple 沙盒反馈服务器似乎没有返回非事件 token ,尽管生产环境似乎运行良好。
看看这个线程:Apple Push Notification Feedback Service - how frequently does it check

建议的解决方案是在您的设备上安装两个开发应用程序,然后删除一个。被删除的应该出现在非事件 token 列表中。

关于ios - PHP 推送通知服务,反馈为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11117163/

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