The recent project is to complete a PHP push server, either Php,apns or GCM is basically zero-based.
Write down a little bit of insight to make it easier for the porter to continue to do the code later.
Because the PHP and iOS are not familiar with, there may be errors and omissions ... Poor kids don't have to use iOS stuff ...
If you want to be able to receive server messages in a timely manner, there are about three ways:
1) Polling method: The client and the server actively connect to the query. Because of the timeliness and power consumption requirements can not be combined, generally not considered.
2) SMS (Push) mode: On the Android platform, you can intercept the SMS message and parse the message content to understand the server's intentions and get its display content for processing. But the cost of the program is relatively high, and it needs to be paid to the mobile company.
3) Persistent connection (Push) mode: On Android has GCM, set can run their own background program to link their own server. On iOS, you can only use Apple's own APNs (Apple Push Notification Service)
"PHP Implementation APNs push Notifications"
After the Pem file is ready, PHP sends a push notification code as follows:
Private Static functionPushios ($deviceToken= ",$message= ' '){ $body=Array("APS" =Array("Alert" =$message, "badge" = 2, "sound" = ' default ');//push mode, including content and sound $ctx=stream_context_create(); //If there is a problem finding the PEM path on the Windows Server, the path is modified as follows: $pem=dirname(__file__) . ‘/‘ . ' Apns-dev.pem '; stream_context_set_option($ctx, "SSL", "Local_cert",$pem); //Linux servers directly write the path of the PEM can be//stream_context_set_option ($ctx, "SSL", "Local_cert", "Apns-dev.pem"); $pass= "1234"; stream_context_set_option($ctx, ' SSL ', ' passphrase ',$pass); //must select between, servers:if for Testing,select sandbox server and Dev Pem file, if for Relese,use Product PEM and server//$fp = Stream_socket_client ("ssl://gateway.push.apple.com:2195", $err, $errstr, Stream_client_conne CT, $ctx); $fp=stream_socket_client("ssl://gateway.sandbox.push.apple.com:2195",$err,$errstr, Stream_client_connect,$ctx); if(!$fp) { Echo"Failed to connect$err $errstrn"; return; } Print"Connection ok\n"; $payload= Json_encode ($body); $msg=CHR(0).Pack("n", 32).Pack("h*",Str_replace(‘ ‘, ‘‘,$deviceToken)) .Pack("N",strlen($payload)) .$payload; Echo"Sending message:".$payload." \ n "; fwrite($fp,$msg); fclose($fp); }
"PHP implements APNs's feedback Service"
functionsend_feedback_request () {//Connect to the APNS feedback servers//make sure your ' re using the right dev/production server & cert COMBO! $stream _context=stream_context_create(); stream_context_set_option($stream _context, ' SSL ', ' Local_cert ', '/path/to/my/cert.pem '); $pass= "1234"; stream_context_set_option($ctx, ' SSL ', ' passphrase ',$pass); $apns=stream_socket_client(' ssl://feedback.push.apple.com:2196 ',$errcode,$errstr, Stream_client_connect,$stream _context)//If it is in development, the address should be: feedback.sandbox.push.apple.com:2196if(!$apns) { EchoThe ERROR$errcode:$errstr\ n "; return; } $feedback _tokens=Array(); //and read the data on the connection: while(!feof($apns)) { $data=fread($apns, 38); if(strlen($data)) { $feedback _tokens[] =Unpack("N1timestamp/n1length/h*devtoken",$data); } } fclose($apns); return $feedback _tokens;}
If it goes well, the return value of this method should be the following form:
Array ( Array ( = =1266604759 = + = Abc1234 ........ etcetc ), Array ( =1266604922 = 32 = = def56789 ....... etcetc ),)
The urine of apples is not humanized at all. Google's GCM each push in the past will return the results of each message, if the device has been uninstalled the app caused the ID is no longer available and can be seen immediately, mass message also support 1000 1000 to send.
Only one of the apples can be sent, and call this unknown feedback service.
Fruit powder See here can curse, but I am black, no matter.
PHP iOS push notifications and feedback services