0, ' msg ' = ' ERROR request '])); if (!isset ($_get[' Device_token ')) {exit (Json_encode ([' Code ' = 0, ' msg ' = ' device Information missing ']);} if (!isset ($_get[' message '))) {exit ([' Code ' = 0, ' msg ' = ' push message missing ')]);} if (strlen ($_get[' message ') >) {exit (Json_encode ([' Code ' = + 0, ' msg ' = ' + ' push message length more than 256 characters ') ]));} if (!isset ($_get[' app_id ')) {exit (Json_encode ([' Code ' = ' + 0, ' msg ' = ' appid missing ')]);} $apps = [' 101 ' = [' cert ' and ' = '/cert/1.pem ',//ios generated PEM, ' password ' = ' 1 ',//pem password ' Deb UG ' = ' 1 ',//Development mode 1 production mode 0]];if (!array_key_exists ($_get[' app_id '), $apps)) {exit (Json_encode ([' Code ' =&G T 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_client (' Ssl://gatew ay.sandbox.push.apple.com:2195 ', $err, $err _str, stream_client_connect| Stream_client_persistent, $ctx);} else{$fp = stream_socket_client (' ssl://gateway.push.apple.com:2195 ', $err, $err _str, 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);//Buil d 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 ' = ' push message send failed, message: '. $result]);} else{exit (Json_encode ([' Code ' = 1, ' msg ' = ' push message sent successfully, message: '. $result]);}
PEM generation strategy See: http://my.oschina.net/u/2340880/blog/413584