$ DeviceToken ='' ;/ / token
$ Pass =''; / / Passphrase for the private key (ck.pem file)
/ / Get the parameters from http get or from command line
$ Message = $ _GET ['message'] or $ message = $ argv [1] or $ message = 'A test message from worldcup';
$ Badge = (int) $ _GET ['badge'] or $ badge = (int) $ argv [2];
$ Sound = $ _GET ['sound'] or $ sound = $ argv [3];
/ / C ***** truct the notification payload
$ Body = array ();
$ Body ['aps'] = array ('alert' => $ message);
if ($ badge)
$ Body ['aps'] ['badge'] = $ badge;
if ($ sound)
$ Body ['aps'] ['sound'] = $ sound;
/ * End of Configurable Items * /
$ Ctx = stream_context_create ();
stream_context_set_option ($ ctx, 'ssl', 'local_cert', 'apns-dev.pem');
/ / Assume the private key passphase was removed.
stream_context_set_option ($ ctx, 'ssl', 'passphrase', $ pass);
/ / Connect to apns
$ Fp = stream_socket_client ('ssl :/ / gateway.sandbox.push.apple.com: 2195', $ err, $ errstr, 60, STREAM_CLIENT_CONNECT, $ ctx);
if (! $ fp) {
print "Failed to connect $ err $ errstr \ n";
return;
}
else {
print "Connection OK \ n
";
}
/ / Send message
$ Payload = json_encode ($ body);
$ 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);
?>
An error as follows: Warning: stream_socket_client () [function.stream-socket-client]: unable to connect to ssl :/ / gateway.sandbox.push.apple.com: 2195 (a period of time because the connected party did not properly respond after or connected host does not respond to the connection attempt fails.) in D: \ Program Files \ VertrigoServ \ www \ apns.php on line 23
Fatal error: Maximum execution time of 30 seconds exceeded in D: \ Program Files \ VertrigoServ \ www \ apns.php on line 23
Push for a javapns same can not connect
reportedCode is as follows:
public static void main (String [] args) throws Exception {
try {
String deviceToken = "" ;/ / my token
PayLoad payLoad = new PayLoad ();
payLoad.addAlert ("I push test");
payLoad.addBadge (4);
payLoad.addSound ("default");
PushNotificationManager pushManager = PushNotificationManager.getInstance ();
pushManager.addDevice ("iPad", deviceToken);
/ / Connect to APNs
String host = "gateway.sandbox.push.apple.com";
int port = 2195;
/ / String certificatePath = "/ Users/jcjc/Desktop/push_p.p12";
String certificatePath = "d: \ \ Cert.p12";
String certificatePassword = "123qaz";
pushManager.initializeConnection (host, port, certificatePath, certificatePassword, SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
/ / Send Push
Device client = pushManager.getDevice ("iPad");
pushManager.sendNotification (client, payLoad);
pushManager.stopConnection ();
pushManager.removeDevice ("iPad");
}
catch (Exception e) {
e.printStackTrace ();
}
} log4j: WARN See http://logging.apache.org/log4j/1.2/faq.html # noconfig for more info.
java.net.ConnectException: Connection timed out: connect
Reply:
You ping the server to see through the barrier. Besides here ios development. . ~ ~ Khan
Reply:
I am a corporate network for apple push servers were shielded anyway access network can be changed
No comments:
Post a Comment