Parsing PHP To do push server implementation iOS message push _php tutorial

Source: Internet
Author: User
Preparatory work
1. Get the Devicetoken of the Mobile registration app (unique value returned when iphone registration app Devicetoken)
2. Get the Ck.pem file (to do the phone-side)
3. Get the pass phrase (to do the phone-side)

testpush.php File
Copy CodeThe code is as follows:
Mobile registration app returns unique Devicetoken
$deviceToken = ' 6ad7b13f b05e6137 a46a60ea 421e5016 4b701671 cc176f70 33bb9ef4 38a8aef9 ';
CK.PEM Clearance Password
$pass = ' Jetson ';
Message content
$message = ' A test message! ';
Badge, I don't know what it is.
$badge = 4;
Sound I don't know what it is (maybe a beep when I push a message to the phone)
$sound = ' duck.wav ';
Construction notification Payload (i.e. some information contained in the notification)
$body = Array ();
$body [' id '] = "4f94d38e7d9704f15c000055";
$body [' aps '] = Array (' alert ' = = $message);
if ($badge)
$body [' APS '] [' badge '] = $badge;
if ($sound)
$body [' APS '] [' sound '] = $sound;
Convert array data to JSON data
$payload = Json_encode ($body);
echo strlen ($payload), "\ r \ n";
The bottom of the writing is the death of the wording, generally do not need to modify,
The only thing to be modified is: ssl://gateway.sandbox.push.apple.com:2195 This is the sandbox test address, ssl://gateway.push.apple.com:2195 official release address
$ctx = Stream_context_create ();
Stream_context_set_option ($ctx, ' SSL ', ' Local_cert ', ' Ck.pem ');
Stream_context_set_option ($ctx, ' SSL ', ' passphrase ', $pass);
$fp = stream_socket_client (' ssl://gateway.sandbox.push.apple.com:2195 ', $err, $errstr, $, stream_client_connect, $ CTX);
if (! $fp) {
Print "Failed to connect $err $errstr \ n";
Return
}
else {
Print "Connection ok\n
";
}
Send Message
$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);
?>

http://www.bkjia.com/PHPjc/327978.html www.bkjia.com true http://www.bkjia.com/PHPjc/327978.html techarticle Getting ready to work 1. Get the Devicetoken (unique value Devicetoken) for the Mobile registration app (iphone registration App) 2. Get the Ck.pem file (to do the phone) 3. Get pass phrase (do ...

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