This article provides a detailed analysis of how to push ios Messages to the php push server. For more information, see
Preparations 1. get the deviceToken of the mobile phone registration application (the unique value of deviceToken is returned when the iphone registers the application)
2. get the ck. pem file (for the mobile terminal)
3. get the pass phrase (for mobile phones)
Testpush. php file The code is as follows:
// A unique deviceToken is returned for the mobile phone registration application.
$ DeviceToken = '6ad7b13f b05e6425a46a60ea 421e5016 4b701671 cc176f70 33bb9ef4 38a8aef9 ';
// Ck. pem customs clearance password
$ Pass = 'jetson ';
// Message content
$ Message = 'a test message! ';
// Badge, I don't know what it is.
$ Badge = 4;
// Sound I do not know what it is (maybe the prompt sound when the message is pushed to the mobile phone)
$ Sound = 'Duck.wav ';
// Construction notification payload (that is, 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 following statement is dead. it generally does not need to be modified,
// The only modification is: ssl: // gateway.sandbox.push.apple.com: 2195. this is the sandbox test address. ssl: // gateway.push.apple.com: 2195 is the 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: 000000', $ err, $ errstr, 60, 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 );
?>
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.