Preparatory work
1. Get the Devicetoken of the Mobile registration app (unique value returned when iphone registration app Devicetoken)
2. Get the Ck.pem file (to do the phone-side)
3. Get the pass phrase (to do the phone-side)
push.php file:
<?PHP//Mobile registration App returns unique Devicetoken$deviceToken= ' 6ad7b13f b05e6137 a46a60ea 421e5016 4b701671 cc176f70 33bb9ef4 38a8aef9 ';//CK.PEM Clearance Password$pass= ' Jetson '; //Message Content$message= ' A Test message! ';//badge, I don't know what it is .$badge= 4;//sound I don't know what it is (maybe a beep when I push a message to the phone)$sound= ' Duck.wav ';//Construction Notification Payload (i.e. some information contained in the notification)$body=Array();$body[' id '] = "4f94d38e7d9704f15c000055";$body[' APS '] =Array(' alert ' =$message);if($badge)$body[' APS '] [' badge '] =$badge;if($sound)$body[' APS '] [' sound '] =$sound;//convert array data to JSON data$payload= Json_encode ($body);Echo strlen($payload), "\ r \ n";//The following writing is the death of the wording, generally do not need to modify,//The only thing to modify is: ssl://gateway.sandbox.push.apple.com:2195 This is the sandbox test address, ssl:// GATEWAY.PUSH.APPLE.COM:2195 Official release Address$ctx=stream_context_create();stream_context_set_option($ctx, ' SSL ', ' Local_cert ', ' Ck.pem '); stream_context_set_option($ctx, ' SSL ', ' passphrase ',$pass);$fp=stream_socket_client(' ssl://gateway.sandbox.push.apple.com:2195 ',$err,$errstr, Stream_client_connect,$ctx);if(!$fp) {Print"Failed to connect$err $errstr\ n ";return;}Else {Print"Connection ok\n<br/>";}//Send Message$msg=CHR(0).Pack("n", 32).Pack(' h* ',Str_replace(‘ ‘, ‘‘,$deviceToken)) .Pack("N",strlen($payload)) .$payload;Print"Sending message:".$payload. "\ n"; fwrite($fp,$msg);fclose($fp);?>
iOS push PHP code (GO)