How to send push notification by web interface:
http://www.macoscoders.com/2009/05/17/iphone-apple-push-notification-service-apns/comment-page-1/
Other Link:
1. http://iphonesdkdev.blogspot.com/2009/04/apns-client-development-certificate.html
2. http://mobiforge.com/developing/story/programming-apple-push-notification-services
Commands to create pem file:
error_reporting(0);
$deviceToken = '144ed2a746e7fe2de57aa9307a91e6a2f001cc62f3608515a46a1b90c8625e06';
// Passphrase for the private key (ck.pem file)
// $pass = '';
// Get the parameters from http get or from command line
$message = $_GET['message'] or $message = $argv[1] or $message = 'Message received from javacom';
$badge = (int)$_GET['badge'] or $badge = (int)$argv[2];
$sound = $_GET['sound'] or $sound = $argv[3];
// Construct 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','ck.pem');
// assume the private key passphase was removed.
// stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp) {
print "Failed to connect $err $errstrn";
return;
}
else {
print "Connection OK";
}
$payload = json_encode($body);
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
print "sending message :" . $payload . "***";
fwrite($fp, $msg);
fclose($fp);
?>
http://www.macoscoders.com/2009/05/17/iphone-apple-push-notification-service-apns/comment-page-1/
Other Link:
1. http://iphonesdkdev.blogspot.com/2009/04/apns-client-development-certificate.html
2. http://mobiforge.com/developing/story/programming-apple-push-notification-services
Commands to create pem file:
- openssl pkcs12 -clcerts -nokeys -out cert.pem -in cert.p12
- openssl pkcs12 -nocerts -out key.pem -in key.p12
- openssl rsa -in key.pem -out key.unencrypted.pem
- cat cert.pem key.unencrypted.pem > ck.pem
error_reporting(0);
$deviceToken = '144ed2a746e7fe2de57aa9307a91e6a2f001cc62f3608515a46a1b90c8625e06';
// Passphrase for the private key (ck.pem file)
// $pass = '';
// Get the parameters from http get or from command line
$message = $_GET['message'] or $message = $argv[1] or $message = 'Message received from javacom';
$badge = (int)$_GET['badge'] or $badge = (int)$argv[2];
$sound = $_GET['sound'] or $sound = $argv[3];
// Construct 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','ck.pem');
// assume the private key passphase was removed.
// stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp) {
print "Failed to connect $err $errstrn";
return;
}
else {
print "Connection OK";
}
$payload = json_encode($body);
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
print "sending message :" . $payload . "***";
fwrite($fp, $msg);
fclose($fp);
?>
Comments
Post a Comment