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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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











The Ouyi Exchange app supports downloading of Apple mobile phones, visit the official website, click the "Apple Mobile" option, obtain and install it in the App Store, register or log in to conduct cryptocurrency trading.

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

The official Gate.io APP can be downloaded in the following ways: 1. Visit the official website gate.io to download; 2. Search "Gate.io" on the App Store or Google Play to download. Be sure to download it through the official channel to ensure safety.

Sesame Open Door is a platform that focuses on cryptocurrency trading. Users can obtain portals through official websites or social media to ensure that the authenticity of SSL certificates and website content is verified during access.

Provides a variety of complex trading tools and market analysis. It covers more than 100 countries, has an average daily derivative trading volume of over US$30 billion, supports more than 300 trading pairs and 200 times leverage, has strong technical strength, a huge global user base, provides professional trading platforms, secure storage solutions and rich trading pairs.

Priority is given to compliant platforms such as OKX and Coinbase, enabling multi-factor verification, and asset self-custody can reduce dependencies: 1. Select an exchange with a regulated license; 2. Turn on the whitelist of 2FA and withdrawals; 3. Use a hardware wallet or a platform that supports self-custody.

AI can help optimize the use of Composer. Specific methods include: 1. Dependency management optimization: AI analyzes dependencies, recommends the best version combination, and reduces conflicts. 2. Automated code generation: AI generates composer.json files that conform to best practices. 3. Improve code quality: AI detects potential problems, provides optimization suggestions, and improves code quality. These methods are implemented through machine learning and natural language processing technologies to help developers improve efficiency and code quality.

Visit Binance official website and check HTTPS and green lock logos to avoid phishing websites, and official applications can also be accessed safely.
