Prepare the IOSphp server client. Today, we finally fully understand what the client needs before APNs is pushed. If there is something wrong, please let us know. Preparation: Original address:
Today, we finally fully understand what the client needs before APNs is pushed. If there is something wrong, please let us know.
Preparations:
Original address: click to open the link http://blog.csdn.net/tuxiangqi/article/details/17245553
1. go to the developer center, create an app Id, and select the push notification function (required for game center and the other one ).
2. create certificates
Note: for internal development, you can only use Develpment. the producation test is complete. you can try again when you are about to release it to the appstore.
According to the description of the Develop process, a CSR file will be created (this CSR file can also be shared by the production version) and created through the key string (an application in the general menu). For details, see the official <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + environment + rL6s/a1xM7EvP48YnI + cda-vcd4kpha + environment + oaO4 + b7dtdq2/environment + w5rG + environment + temperature = "http://www.Bkjia.com/uploadfile/Collfiles/20131211/2013121109360487.jpg" alt = "\">
5. make PEM files for SSL and private keys (required by the php server)
A. Make the SSL (cert file) and key (private key) p12 format files respectively, obtained through export. (Note)
B. run the shell command on the terminal to obtain two PEM files of SSL and key, and combine them into one.
The command parameters are as follows:
Original address: click to open the link http://blog.csdn.net/tuxiangqi/article/details/17245553
Path of the cd storage folder
Openssl pkcs12-clcerts-nokeys-out output file name. pem-in original file name such as SSL (Cert file). p12 (change SSLcert file from p12 to pem)
Openssl pkcs12-nocerts-out apns-dev-key.pem-in apns-dev-key.p12 (change the key. p12 file to pem, which will prompt you to set the private key unzip password, at least 4 bits, you can enter)
Openssl rsa-in apns-dev-key.pem-out apns-dev-key-noenc.pem (this command removes the minimum 4-bit password set for the private key, if you want to keep it, but I need to explain it to my colleagues on the php server)
Cat apns-dev-cert.pem apns-dev-key-noenc.pem> apns-dev.pem (this command is to compile the SSL and private key into a file named pem which can be changed by yourself)
The following are other resources found on the Internet.
Array ("alert" => "message123gg32323333", "badge" => 1, "sound" => 'default'); // Push method, including the prompt content, prompts and sounds. $ Ctx = stream_context_create (); // if the pem path is found on a Windows Server, the path is changed to the following method: $ pem =! Empty ($ this-> cfg ['isga ']) & $ this-> cfg ['isga'] = 2? 'Apns-dev. pem': 'apns-dev. pem'; // the development status is stream_context_set_option ($ ctx, 'SSL ', 'local _ cert', "/data/web/cert /". $ pem); // you can directly write the pem path on the linux server to stream_context_set_option ($ ctx, 'SSL ', 'local _ cert ',"/Data/web/cert/". $ pem );// If your pem has a password, you need to add a password login statement stream_context_set_option ($ ctx, 'SSL ', 'passphrase ',''); // if your pem has a password, add a password login statement // $ pass = "123123"; // stream_context_set_option ($ ctx, 'SSL ', 'passphrase ', $ pass); // There are two servers to choose from. for development and testing purposes, select the server with the second sandbox and use the Dev pem certificate. if it is published, use Product's pem and select the official server $ fp = stream_socket_client ("ssl: // gateway.push.apple.com: 2195", $ err, $ errstr, 60, STREAM_CLIENT_CONNECT, $ ctx ); $ fp = stream _ Socket_client ("ssl: // gateway.sandbox.push.apple.com: 2195", $ err, $ errstr, 60, STREAM_CLIENT_CONNECT, $ ctx); if (! $ Fp) {print_r ("Failed to connect $ err $ errstrn"); return;} print_r ("Connection OK \ n"); $ payload = json_encode ($ body ); $ msg = chr (0 ). pack ("n", 32 ). pack ('H * ', str_replace ('','', $ deviceToken )). pack ("n", strlen ($ payload )). $ payload; print_r ("sending message :". $ payload. "\ n"); fwrite ($ fp, $ msg); fclose ($ fp);?>
It's almost done here, so you can follow other server tutorials... There are many websites.Of course, your
The interaction with the php server is over now.
Prepare the client before pushing the producer. If there is something wrong, please let us know. Preparation: Original address :...