PHP Apple message push

Source: Internet
Author: User

   /** Apple Message Push method
* $deviceToken Apple device token
* $message message content*/ functionIosmsg_send ($deviceToken,$message){ $message=strlen($message) >40?mb_substr ($message, 0,40, ' Utf-8 '):$message; $ctx=stream_context_create(); stream_context_set_option($ctx, ' SSL ', ' Local_cert ',substr(dirname(__file__), 0,-30). ' Test\productionpush.pem ');//Certificate Path stream_context_set_option($ctx, ' SSL ', ' Passphrase ', ' 123456 '); //Open A connection to the APNS server//This is the official release address $fp=stream_socket_client(' ssl://gateway.push.apple.com:2195 ',$err,$errstr, Stream_client_connect,$ctx); //This is the sandbox test address, after posting to AppStore remember to modify//$fp = stream_socket_client (' ssl://gateway.sandbox.push.apple.com:2195 ', $err, $err STR, stream_client_connect| Stream_client_persistent, $ctx); if(!$fp) Exit("Failed to connect:$err $errstr" .Php_eol); Echo' Connected to APNS '.Php_eol; //Create the payload body $body[' APS '] =Array( ' Alert ' =$message, ' sound ' = ' default ' ); //Encode the payload as JSON $payload= Json_encode ($body); //Build the binary notification $msg=CHR(0).Pack(' n ', 32).Pack(' h* ',$deviceToken).Pack(' n ',strlen($payload)).$payload; //Send It to the server $result=fwrite($fp,$msg,strlen($msg)); if(!$result) Echo' Message not delivered '.Php_eol; Else Echo' Message successfully delivered '.Php_eol; //Close The connection to the server fclose($fp); }

PHP Apple message push

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.