<? PHP // PHP needs to enable SSL (OpenSSL) support $ apnscert = "ck. PEM "; // certificate license file when connecting to apns. The certificate must be created as required $ pass =" 123456 "; // certificate password $ serverurl =" SSL: // gateway.sandbox.push.apple.com: 2195 "; // push server. Here is the development and testing server $ devicetoken =" token "; // iOS device ID, which cannot contain spaces, each iOS device has an ID $ message =$ _ Get ['message'] or $ message = "Hello! "; $ Badge = (INT) $ _ Get ['badge'] or $ badge = 2; $ sound = $ _ Get ['sound'] or $ sound = "default"; $ body = array ('aps '=> array ('alert' => $ message, 'badge' => $ badge, 'sound' => $ sound); $ streamcontext = stream_context_create (); stream_context_set_option ($ streamcontext, 'ssl ', 'local _ cert ', $ apnscert); stream_context_set_option ($ streamcontext, 'ssl ', 'passphrase', $ pass); $ apns = stream_socket_c Lient ($ serverurl, $ error, $ errorstring, 60, stream_client_connect | stream_client_persistent, $ streamcontext); // connect to the server if ($ apns) {echo "connection OK <br/>" ;}else {echo "failed to connect $ errorstring"; return ;}$ payload = json_encode ($ body ); $ MSG = CHR (0 ). pack ('n', 32 ). pack ('H * ', str_replace ('','', $ devicetoken )). pack ('n', strlen ($ payload )). $ payload; $ result = fwrite ($ apns, $ MSG );// Send the message fclose ($ apns); if ($ result) echo "sending message successfully:". $ payload; else echo 'message not delivered';?>