Push information through apple's apns

Source: Internet
Author: User
Why not push information through apple's apns? PhpclassphpApns {*** @ varstring certificate address * protected $ cert_path; *** @ varstring * protected $ password; *** @ varbool is the sandbox * protected $ is_sandbox; * ** @ varstring official push server *

Why not push information through apple's apns? Phpclass phpApns {/*** @ var string certificate address */protected $ cert_path;/*** @ var string password */protected $ password; /*** @ var bool whether it is a sandbox */protected $ is_sandbox;/*** @ var string officially pushes the server */

Push information through apple's apns <无>
  Cert_path = $ cert_path; $ this-> password = $ password; $ this-> is_sandbox = $ is_sandbox ;} /*** @ param $ device_token * @ param $ msg: the message sent by the device_token device * @ param string $ sound push sound */public function pushMessage ($ device_token, $ msg, $ sound = 'default') {$ apns = stream_context_create (); stream_context_set_option ($ apns, 'ssl ', 'local _ cert', $ this-> cert_path ); stream_context_set_option ($ apns, 'ssl ', 'passp Hrase ', $ this-> password); if ($ this-> is_sandbox) {$ uri = $ this-> sandbox_uri ;} else {$ uri = $ this-> publish_uri;} // set 60s timeout $ fp = stream_socket_client ($ uri, $ err, $ errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ apns); if (! $ Fp) {$ errMsg = "connection opening failed: ($ err) $ errstr"; die ($ errMsg );} // composition of the information stream sent to apns $ body ['aps '] = array ('alert' => $ msg, 'sound' => $ sound ); $ json = json_encode ($ body); // convert it to a binary stream $ message = chr (0 ). pack ('n', 32 ). pack ('H * ', $ device_token ). pack ('n', strlen ($ json )). $ json; $ result = fwrite ($ fp, $ message, strlen ($ message); if (! $ Result) {die ('information push failed! ');} Fclose ($ fp); echo' push successful! ';}}

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.