IOS APNs Push PHP interface

Source: Internet
Author: User
  0, ' msg ' = ' ERROR request '])); if (!isset ($_get[' Device_token ')) {exit (Json_encode ([' Code ' = 0, ' msg ' = ' device Information missing ']);} if (!isset ($_get[' message '))) {exit ([' Code ' = 0, ' msg ' = ' push message missing ')]);}    if (strlen ($_get[' message ') >) {exit (Json_encode ([' Code ' = + 0, ' msg ' = ' + ' push message length more than 256 characters ') ]));} if (!isset ($_get[' app_id ')) {exit (Json_encode ([' Code ' = ' + 0, ' msg ' = ' appid missing ')]);} $apps = [' 101 ' = [' cert ' and ' = '/cert/1.pem ',//ios generated PEM, ' password ' = ' 1 ',//pem password ' Deb UG ' = ' 1 ',//Development mode 1 production mode 0]];if (!array_key_exists ($_get[' app_id '), $apps)) {exit (Json_encode ([' Code ' =&G T 0, ' msg ' = ' AppID error '])); $ctx = Stream_context_create () stream_context_set_option ($ctx, ' SSL ', ' Local_cert ', $apps [$_get[' app_id ']][' cert ']) ; Stream_context_set_option ($ctx, ' SSL ', ' Passphrase ', $apps [$_get[' app_id ']][' password ']);//OPen a connection to the APNS Serverif ($apps [$_get[' app_id ']][' Debug ') {$fp = Stream_socket_client (' Ssl://gatew ay.sandbox.push.apple.com:2195 ', $err, $err _str, stream_client_connect| Stream_client_persistent, $ctx);} else{$fp = stream_socket_client (' ssl://gateway.push.apple.com:2195 ', $err, $err _str, Stream_client_ Connect| Stream_client_persistent, $ctx);} if (! $fp) {exit (Json_encode ([' Code ' = = 0, ' msg ' = ' = ' connection to the APN server failed, error code: '. $err. ', error message: '. $err _str])) ;} $body [' aps '] = Array (' alert ' = $_get[' message '], ' sound ' = ' default '), $payload = Json_encode ($body);//Buil d the binary notification$msg = chr (0). Pack (' n ', 32). Pack (' h* ', $_get[' Device_token '). Pack (' n ', strlen ($payload)).         $payload;//Send it to the Server$result = Fwrite ($fp, $msg, strlen ($msg)), fclose ($FP), if (! $result) {exit (Json_encode ([ ' Code ' = 0, ' msg ' = ' push message send failed, message: '. $result]);}        else{exit (Json_encode ([' Code ' = 1, ' msg ' = ' push message sent successfully, message: '. $result]);} 

PEM generation strategy See: http://my.oschina.net/u/2340880/blog/413584

  • 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.