Push messages for ios using php as push server

Source: Internet
Author: User
Push messages for ios using php as push server /**
* Main method to run the object
* $ Message content
* $ DeviceToken this is the only Token for the iphone (remember to remove the space)
* $ Badge is the number in the upper-right corner of the application icon.
* $ Sound the sound of a message
* $ ApnsCert certificate path
* $ Passphrase private key password (can be left empty)
*/
Public function iospush(%message,%devicetoken,%badge%1,%sound%'duck.wav ', $ apnsCert, $ passphrase ){
$ Body ['aps '] = array ('alert' => $ message );
If ($ badge)
$ Body ['aps '] ['badge'] = $ badge;
If ($ sound)
$ Body ['aps '] ['sound'] = $ sound;
$ Payload = json_encode ($ body );
$ Ctx = stream_context_create ();
Stream_context_set_option ($ ctx, 'SSL ', 'local _ cert', $ apnsCert );
Stream_context_set_option ($ ctx, 'SSL ', 'passphrase', $ passphrase );
$ Fp = stream_socket_client ('SSL: // gateway.sandbox.push.apple.com: 000000', $ err, $ errstr, 60, STREAM_CLIENT_CONNECT, $ ctx );
If (! $ Fp ){
Print_r ();
Print "Failed to connect $ err $ errstr \ n ";
Return;
}
Else {
Print $ message;
Print "Connection OK \ n
";
}
$ Msg = chr (0 ). pack ("n", 32 ). pack ('H * ', str_replace ('','', $ deviceToken )). pack ("n", strlen ($ payload )). $ payload;
Print "Sending message:". $ payload. "\ n ";
Fwrite ($ fp, $ msg );
Fclose ($ fp );

}


?>

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.