1. Local Certificate synthesis
RM *. Pemecho"Export cert ..."OpenSSL pkcs12-clcerts-nokeys- outPUSH_CERT.PEM-inchPush_cert.p12echo"Export Key ..."OpenSSL pkcs12-nocerts- outPUSH_KEY.PEM-inchpush_key.p12openssl RSA-inchPUSH_KEY.PEM- outPush_key_noenc.pemecho"Combine together"Cat Push_cert.pem Push_key_noenc.pem> apns-Dev.pemecho" Done"
Among them, PUSH_CERT.P12 and PUSH_KEY.P12 are the certificates and private keys which are based on the development certificate in keychain.
The above script will eventually export an authentication file called "Apns-dev.pem".
The following will use this authentication file for Sanbox push
2. Sandbox push
<?PHP$deviceToken=86441e1421a239d0f7eed26ab4c8bd9a9ccec21b‘; $body=Array("APS" =Array("Alert" = ' message ', "badge" = 2, "sound" = ' default ')); $ctx=stream_context_create();stream_context_set_option($ctx, "SSL", "Local_cert", "Apns-dev.pem");$Pass = "AABB11";stream_context_set_option($ctx, ' SSL ', ' passphrase ',$pass);//$fp = stream_socket_client ("ssl://gateway.push.apple.com:2195", $err, $errstr, A, stream_client_connect, $ctx); For real push service$fp=stream_socket_client("ssl://gateway.sandbox.push.apple.com:2195",$err,$errstr, Stream_client_connect,$ctx);//For Sandboxif(!$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);?>
One of the Devicetoken is the 40-bit udid of the Apple phone.
This was learned at the time of the internship, but in the end the program was not tested successfully:
The problem is:
PHP pushtest.php
Warning:stream_socket_client (): Failed to enable crypto in pushtest.php on line 10
Warning:stream_socket_client (): Unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in pushtest.php on line 10
I really regret to hope that I will have the opportunity to learn about iOS!
IOS Remote Notification