Php ios push

Source: Internet
Author: User
<? 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';?>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.