我想使用curl(PHP或Linux)从苹果推送通知中获取反馈。 我找到了用于发送推送通知的代码
<?php
$url = 'https://feedback.push.apple.com:2196';
$cert = 'Cert.pem';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSLCERT, $cert);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "passphrase");
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"device_tokens": ["XXXX"], "aps": {"alert": "test message one!"}}');
$curl_scraped_page = curl_exec($ch);
?>
反馈服务
Apple 提供反馈服务,您应该偶尔进行民意调查。这将提供以前但不再有效的 deviceToken 列表,例如用户是否已卸载您的 iPhone 应用程序。然后,您可以从数据库中删除 deviceToken,这样您就不会与无效设备进行通信。
我需要一个 PHP 脚本来从 Apple 反馈服务获取此列表。
谢谢
最佳答案
您可以使用以下代码:
<?php
$apnsCert = 'Your_Certificate_File.pem'; //Put your Certificate_PATH/Certificate_File.pem Here
$streamContext = stream_context_create(); //Creates a stream context
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);//Sets option for a stream | For more information please see this page http://php.net/manual/en/function.stream-context-set-option.php
stream_context_set_option($streamContext, 'ssl', 'verify_peer', false); //Sets option for a stream
$apns = stream_socket_client('ssl://feedback.push.apple.com:2196', $error,
$errorString, 60, STREAM_CLIENT_CONNECT, $streamContext); //Open Internet or Unix domain socket connection
echo 'error=' . $error . "<br />"; //Show error number
echo 'errorString=' . $errorString . "<br />"; //Show error string
$result = fread($apns, 38); // Binary-safe file read and store in $result
$unpacked = unpack("N1timestamp/n1length/H*devtoken", $result);//Get token from apple APNS
echo 'Token is' ;print_r($unpacked); // Show token and can be replace with database update commands
fclose($apns);
关于php - 从 Apple 推送通知反馈中获取信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33124387/