Php interface for IOSAPNS push
0, 'MSG '=> 'Error request']);} if (! Isset ($ _ GET ['device _ token']) {exit (json_encode (['code' => 0, 'MSG '=> 'device information missing']);} if (! Isset ($ _ GET ['message']) {exit (json_encode (['code' => 0, 'MSG '=> 'push information missing']);} if (strlen ($ _ GET ['message'])> 256) {exit (json_encode (['code' => 0, 'MSG '=> 'push message length exceeds 256 characters']);} if (! Isset ($ _ GET ['app _ id']) {exit (json_encode (['code' => 0, 'MSG '=> 'appid missing']);} $ apps = ['000000' => ['cert' => '. /cert/1. pem ', // The pem generated by ios, 'password' => '1', // The pem password 'debug' => '1 ', // Development Mode 1 production mode 0]; if (! Array_key_exists ($ _ GET ['app _ id'], $ apps) {exit (json_encode (['code' => 0, 'MSG '=> 'appid error']);} $ ctx = stream_context_create (); stream_context_set_option ($ ctx, 'SSL', 'local _ cert ', $ apps [$ _ GET ['app _ id'] ['cert']); stream_context_set_option ($ ctx, 'SSL ', 'passphrase ', $ apps [$ _ GET ['app _ id'] ['password']); // Open a connection to the APNS serverif ($ apps [$ _ GET ['app _ id'] ['debug']) {$ fp = stream_socket_c Lient ('SSL: // container: 100', $ err, $ err_str, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ ctx);} else {$ fp = stream_socket_client ('SSL: // gateway.push.apple.com: 2195 ', $ err, $ err_str, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ ctx);} if (! $ Fp) {exit (json_encode (['code' => 0, 'MSG '=>' connection to the APN server failed, error code :'. $ err. ', error message :'. $ err_str]);} $ body ['aps '] = array ('alert' => $ _ GET ['message'], 'sound' => 'default'); $ payload = json_encode ($ body); // Build the binary notification $ msg = chr (0 ). pack ('N', 32 ). pack ('H * ', $ _ GET ['device _ token']). pack ('N', strlen ($ payload )). $ payload; // Send it to the server $ result = fwrite ($ fp, $ msg, strlen ($ msg )); Fclose ($ fp); if (! $ Result) {exit (json_encode (['code' => 0, 'MSG '=>' message :'. $ result]);} else {exit (json_encode (['code' => 1, 'MSG '=>' message :'. $ result]);}
Pem generation policy see: http://my.oschina.net/u/2340880/blog/413584.