Reference article: Http://blog.csdn.net/showhilllee/article/details/8631734#comments
The first step, download your project development certificate
Step two, export the key from keychain access
Note that the password I used here is 123456.
Put them in the same file.
The third step, certificate file processing
Open terminal to enter the above folder
The ① input command converts the. cer SSL certificate to a. pem file, OpenSSL x509-in aps_development.cer -inform der-out Pushchatcert.pem
The ② input command converts the private key TEST.P12 file to a. pem file
OpenSSL pkcs12-nocerts-out pushchatkey.pem-in TEST.P12
③ the generated two PEM files into a PEM file to consolidate the certificate and private key into a single file:
Cat Pushchatcert.pem Pushchatkey.pem > Ck.pem
Generate Ck.pem File
④ test with Apple push server connection;
Telnet gateway.sandbox.push.apple.com 2195
⑥ Below we will use our generated SSL certificate and private key to set a secure link to the Apple server
OpenSSL s_client-connect Gateway.sandbox.push.apple.com:2195-cert Pushchatcert.pem-key PushChatKey.pem
Enter Q end
Client I'm not going to tell you.
Fourth step, get Devicetoken and push PHP test code
① run your app to get Devicetoken, and get you to Devicetoken fill in the PHP code location;
② input php pushme.php in terminal (PHP code is affixed later)
Note that the PHP code must be placed in a folder with other files
PHP Code Snippets
1<?PHP2 3 //Put your device token here (without spaces):4 5 $deviceToken= ' Devicetoken Remove the middle space ';6 7 //Put your private key ' s passphrase here: Whispers8 $passphrase= ' 123456 ';9 Ten //Put your alert message here: One $message= ' This is a push message '; A - //////////////////////////////////////////////////////////////////////////////// - the $ctx=stream_context_create(); - stream_context_set_option($ctx, ' SSL ', ' Local_cert ', ' Ck.pem '); - stream_context_set_option($ctx, ' SSL ', ' passphrase ',$passphrase); - + //Open A connection to the APNS server - $fp=stream_socket_client( +' ssl://gateway.sandbox.push.apple.com:2195 ',$err, A $errstr, stream_client_connect|. Stream_client_persistent,$ctx); at - if(!$fp) - Exit("Failed to connect:$err $errstr" .Php_eol); - - Echo' Connected to APNS '.Php_eol; - in //Create the payload body - $body[' APS '] =Array( to' Alert ' =$message, +' Sound ' = ' default ' - ); the * //Encode the payload as JSON $ $payload= Json_encode ($body);Panax Notoginseng - //Build the binary notification the $msg=CHR(0).Pack(' n ', 32).Pack(' h* ',$deviceToken) .Pack(' n ',strlen($payload)) .$payload; + A //Send It to the server the $result=fwrite($fp,$msg,strlen($msg)); + - if(!$result) $ Echo' Message not delivered '.Php_eol; $ Else - Echo' Message successfully delivered '.Php_eol; - the //Close The connection to the server - fclose($fp);Wuyi the?>
Code Download: PHP code download
iOS push--the development mode test