Php
Why does PHP push two messages when it is running in the background when the server is pushed by iOS? But the mobile phone off the screen push the time is normal ~ Only the background to run the time is two?? How to change it?
Here is the code
/** Mobile phone push information class @author:wtt*/class push{private $deviceToken; Private $message; function __construct ($deviceToken, $message) {$this->devicetoken = $deviceToken; $this->message = $message; } public Function push () {//CK.PEM customs password $pass = ' 123456 '; Message content//badge I don't know what it is $badge = 1; Sound I don't know what it is (perhaps the cue tone when the message is pushed to the phone) $sound = ' duck.wav '; Construction notification Payload (i.e. some information contained in the notification) $body = array (); $body [' aps '] = Array (' alert ' = = $this->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 writing is the death of the wording, generally do not need to modify,//The only thing to modify 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 (', ', $this->devicetoken)). Pack ("n", strlen ($payload)). $payload; Print "Sending message:". $payload. "\ n"; Fwrite ($fp, $msg); Fclose ($FP); }}