Parse php for push server to push ios Messages. Preparation 1. get the deviceToken of the mobile phone registration application (the unique value deviceToken is returned when the iphone registers the application) 2. get the ck. pem file (for the mobile phone end) 3. get passphrase (do
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 );
?>
Lifecycle 1. obtain the deviceToken of the mobile phone registration application (the unique value deviceToken is returned when the iphone registers the application) 2. obtain ck. pem file (for the mobile terminal) 3. get pass phrase (do...