Note: 1. we recommend that you establish a persistent connection with the feedback server. If the connection is too frequent, it may be used as an attack (it does not matter if you do some test in a simple way); 2. the obtained token is added with the feedback service when the last time you failed to send a push to your application, which will return the specific failure time 3. the returned data is composed of three parts. See the figure below.
Note: 1. we recommend that you establish a persistent connection with the feedback server. If the connection is too frequent, it may be used as an attack (it does not matter if you do some test in a simple way); 2. the obtained token is added with the feedback service when the last time you failed to send a push to your application, which will return the specific failure time 3. the returned data is composed of three parts. See the figure below.
Note:
1. We recommend that you establish a persistent connection with the feedback server. If the connection is too frequent, it may be used as an attack (it does not matter if you do some test in a simple way );
2. The obtained token is added with the feedback service when the last push failed to your application. The specific time of the failure will be returned.
3. The returned data is composed of three parts. See the figure below.
The structure contains three parts: The first part is the timestamp of the last push failure, the second part is the length of device_token, and the third part is the invalid device_token.
The following is my code:
Connect ($ param ['host'], $ param ['Port']) {print "connect redis OK";} else {print "failed to connect redis server "; return false;} return $ redis;}/*** @ desc the main code for executing the push operation */function feedback () {$ count1 = 0; $ run_times = 0; $ redis_server = "tcp: // localhost: 6379"; $ ioyunenremoved = 'ioyunenremoved'; $ ioyunenremoved_num = 'ioyunenremoved _ num'; $ fp = connect_feedback (); $ redis = connect_redis ($ redis_s Erver); // Apple recommends that provider and feedback maintain a persistent connection. If a connection is established frequently, it may be treated as an attack $ devcon = ''; while ($ run_times <2000) {$ run_times ++; // socket connection detection if ($ devcon === FALSE) {print date ('ymd His '). '| feedback server disconnected'; @ fclose ($ fp); unset ($ fp); $ fp = connect_feedback ();} // redis connection Detection if (! Is_resource ($ redis) OR! $ Redis-> ping () ===' + PONG ') {print date ('ymd His '). '| redis server disconnected'; @ $ redis-> close (); unset ($ redis); $ redis = connect_redis ($ redis_server);} // reads 38 fields each time, this is the length of a complete token saved while ($ devcon = fread ($ fp, 38) {$ count1 ++; $ arr = unpack ("H *", $ devcon); // extract binary data from the package $ rawhex = trim (implode ("", $ arr); $ feedbackTime = hexdec (substr ($ rawhex, 0, 8); $ feedbackDate = date ('Y-m-d H: I: s', $ feedbackTime); $ feedbackDeviceToken = substr ($ rawhex, 12, 64 ); // record the deleted token $ redis-> hSet ($ iostokenremoved, $ feedbackDeviceToken, $ feedbackDate); // record the number of detaches per day $ redis-> hIncrBy ($ ioyunenremoved_num, date ('Y-m-d', $ feedbackTime), 1);} echo 'feedback :'. $ count1. PHP_EOL; usleep (10000000); // sleep 10 seconds} $ redis-> close (); fclose ($ fp );} // you can run the script php-f feedback through the command line. php feedbackif (isset ($ argc [1]) & function_exists ($ argv [1]) {$ argv [1] ();} else {die ('invalid input ');}
Original article address: php obtains the failed push token from the feedback server of Apple apns. Thank you for sharing it with me.