php从苹果apns的feedback服务器获取推送失败的token
注意事项: 1.建议和feedback服务器建立长连接,连接过于频繁有可能被当做攻击(简简单单的做一些测试时没有关系的); 2.获取的token是在上次你给你的应用发推送失败时加feedback服务的,里面会返回失败的具体时间 3.返回的数据由三部分组成,请看下面的图 结
注意事项:
1.建议和feedback服务器建立长连接,连接过于频繁有可能被当做攻击(简简单单的做一些测试时没有关系的);
2.获取的token是在上次你给你的应用发推送失败时加feedback服务的,里面会返回失败的具体时间
3.返回的数据由三部分组成,请看下面的图
结构中包含三个部分,第一部分是一个上次发推送失败的时间戳,第二个部分是device_token的长度,第三部分就是失效的device_token
下面是我的代码:
<?php /** * @desc 连接苹果的推送服务器 * @return bool|resource */ function connect_feedback(){ $passphrase = 'cheshi123'; $cert_file = 'cheshi_productionck.pem';//推送的证书地址,环境不要错了 $feedback_server = 'ssl://feedback.push.apple.com:2196';//feedback服务器地址 //沙盒环境地址是 ssl://feedback.sandbox.push.apple.com:2196 $ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', $cert_file); stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); $fp = stream_socket_client($feedback_server, $error, $errorString, 60, STREAM_CLIENT_CONNECT, $ctx); if(!$fp){ print "Failed to connect feedback server: $error $errorString\n"; return false; }else{ print "Connection to feedback server OK\n"; } return $fp; } /** * @desc 连接本地的redis,用来存储获取到的token,也可以用其他方式存储 * @param $redis_server * * @return bool|Redis */ function connect_redis($redis_server){ $param = parse_url($redis_server); $redis = new Redis(); if($redis->connect($param['host'],$param['port'])){ print "connect redis OK"; }else{ print "failed to connect redis server"; return false; } return $redis; } /** * @desc 执行推送操作的主要代码 */ function feedback(){ $count1 = 0; $run_times = 0; $redis_server = "tcp://localhost:6379"; $iostokenremoved= 'iostokenremoved'; $iostokenremoved_num = 'iostokenremoved_num'; $fp = connect_feedback(); $redis = connect_redis($redis_server); //苹果建议provider和feedback服务维持一个长连接,如果频繁的建立连接可能会被当做攻击处理 $devcon =''; while($run_timesping()==='+PONG'){ print date('Ymd His').'|redis server disconnected'; @$redis->close(); unset($redis); $redis = connect_redis($redis_server); } //每次读取38个字段,这是保存的一个完整token 信息的长度 while ($devcon = fread($fp, 38)){ $count1 ++ ; $arr = unpack("H*", $devcon);//解包传过来的二进制数据 $rawhex = trim(implode("", $arr)); $feedbackTime = hexdec(substr($rawhex, 0, 8)); $feedbackDate = date('Y-m-d H:i:s', $feedbackTime); $feedbackDeviceToken = substr($rawhex, 12, 64); //记录被删除的token $redis->hSet($iostokenremoved,$feedbackDeviceToken,$feedbackDate); //记录每天的卸载数量 $redis->hIncrBy($iostokenremoved_num,date('Y-m-d',$feedbackTime),1); } echo 'FeedBack:'. $count1 . PHP_EOL; usleep(10000000);//sleep 10秒 } $redis->close(); fclose($fp); } //可以通过命令行来执行这个脚本 php -f feedback.php feedback if(isset($argc[1]) && function_exists($argv[1])){ $argv[1](); }else{ die('invalid input'); }
原文地址:php从苹果apns的feedback服务器获取推送失败的token, 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



DeepSeek Smart AI Tool Download and Installation Guide (Apple Users) DeepSeek is a powerful AI tool. This article will guide Apple users how to download and install it. 1. Download and install steps: Open the AppStore app store and enter "DeepSeek" in the search bar. Carefully check the application name and developer information to ensure the correct version is downloaded. Click the "Get" button on the application details page. The first download may require AppleID password verification. After the download is completed, you can open it directly. 2. Registration process: Find the login/registration portal in the DeepSeek application. It is recommended to register with a mobile phone number. Enter your mobile phone number and receive the verification code. Check the user agreement,

Why can’t the Bybit exchange link be directly downloaded and installed? Bybit is a cryptocurrency exchange that provides trading services to users. The exchange's mobile apps cannot be downloaded directly through AppStore or GooglePlay for the following reasons: 1. App Store policy restricts Apple and Google from having strict requirements on the types of applications allowed in the app store. Cryptocurrency exchange applications often do not meet these requirements because they involve financial services and require specific regulations and security standards. 2. Laws and regulations Compliance In many countries, activities related to cryptocurrency transactions are regulated or restricted. To comply with these regulations, Bybit Application can only be used through official websites or other authorized channels

It is crucial to choose a formal channel to download the app and ensure the safety of your account.

This article will guide you in detail how to access the official website of Gate.io, switch Chinese language, register or log in to your account, as well as optional mobile app download and use procedures, helping you easily get started with the Gate.io exchange. For more tutorials on using Gate.io in Chinese, please continue reading.

Ouyi OKX is a world-leading cryptocurrency exchange that provides users with a safe and convenient trading experience. Users can download Ouyi OKX's mobile apps, including Android and Apple versions through official channels.

The official download steps of the Sesame Open Exchange app cover the Android and iOS system download process, as well as common problems solutions, helping you download safely and quickly and enable convenient transactions of cryptocurrencies.

Abstract: This article aims to guide users on how to install and register a virtual currency trading application on Apple devices. Apple has strict regulations on virtual currency applications, so users need to take special steps to complete the installation process. This article will elaborate on the steps required, including downloading the application, creating an account, and verifying your identity. Following this article's guide, users can easily set up a virtual currency trading app on their Apple devices and start trading.

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
