`
imjie
  • 浏览: 1803 次
  • 性别: Icon_minigender_1
  • 来自: 广州
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

(转)Push Notification的证书及服务端php的代码方面的资料

阅读更多

(1) You need to create an App ID without .* in the Program Portal (that means one cert for one app)

(2) Generate a certificate signing request from your Mac's keychain and save to disk

(3) Upload the CertificateSigningRequest.certSigningRequest to the Program Portal

(4) Wait for the generation of cert (about 1 min). Download the certificate (aps_developer_identity.cer) from the Program Portal

(5) Keep (or rename them if you want) these 2 files (steps 2 and 4) in a safe place. You might need the CertificateSigningRequest.certSigningRequest file to request a production cert in the future or renew it again.

(6) Suppose you have imported the aps_developer_identity.cer to the keychain. Then you have to export these new cert and the private key of this cert (not the public key) and saved as .p12 files.

(7) Then you use these commands to generate the cert and key in Mac's Terminal for PEM format (Privacy Enhanced Mail Security Certificate)

openssl pkcs12 -clcerts -nokeys -out cert.pem -in cert.p12
openssl pkcs12 -nocerts -out key.pem -in key.p12

(8) The cert.pem and key.pem files will be used by your own program communicating with APNS.

(9) If you want to remove the passphase of private key in key.pem, do this

openssl rsa -in key.pem -out key.unencrypted.pem

Then combine the certificate and key

cat cert.pem key.unencrypted.pem > ck.pem

But please set the file permission of this unencrypted key by using chmod 400 and is only readable by root in a sever configuration.

(10) The testing APNS is at ssl://gateway.sandbox.push.apple.com:2195

(11) For the source codes to push payload message to the APNS, you can find them in the Developer Forum. This is the one that I used, for php. Run this (after obtaining the device token from the testing device and with iPhone Client program setup)
php -f apns.php "My Message" 2

or if you put this php script and the ck.pem in a local web server, you can use this to test
http://127.0.0.1/apns/apns.php?message=test%20from%20javacom&badge=2&sound=received5.caf

apns.php Select all

< ?php $deviceToken = '02da851dXXXXXXXXb4f2b5bfXXXXXXXXce198270XXXXXXXX0d3dac72bc87cd60'; // masked for security reason // 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.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";
}

$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);
?>

(12) For iPhone Client Program, you need to edit the bundle identifier to the App ID that you created and imported the new provisioning profile for that APP ID to the XCode and iPhone. Then implement the following methods in AppDelegate to Build & Go

AppDelegate.m Select all

- (void)applicationDidFinishLaunching:(UIApplication *)application {

NSLog(@"Registering Remote Notications");

// For beta 2
// [[UIApplication sharedApplication] registerForRemoteNotifications];

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; // For beta 3

// other codes here
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

NSLog(@"%@",[[[launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"] objectForKey:@"aps"] objectForKey:@"alert"]);
return YES;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"deviceToken: %@", deviceToken);
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"Error in registration. Error: %@", error);
}

(13) Additional tips
- The feedback service is currently unavailable.
- Send your messages to gateway.sandbox.push.apple.com:2195 during the beta period.
- Devices must be set up as new iPhones in iTunes in order to generate device tokens. Restoring from backup is not currently supported.

分享到:
评论

相关推荐

    Laravel开发-laravel-push-notification Push Notification 服务端支持

    在本文中,我们将深入探讨如何使用 Laravel 框架中的 "laravel-push-notification" 扩展包来实现 Push Notification 的服务端支持。Push Notification 是移动应用中常见的功能,用于向用户实时发送消息、提醒或者...

    华为推送服务服务端PHP示例hms-push-serverdemo-php-master.zip

    此压缩包“hms-push-serverdemo-php-master.zip”提供了一个服务端PHP示例代码,用于演示如何集成和使用华为推送服务。通过这个示例,开发者可以学习如何在PHP环境中实现对华为推送服务的各种操作,如发送单个或批量...

    ios消息推送源码(含php服务端源码)

    在PHP代码中,使用openssl_pkey_get_private函数加载私钥,并使用openssl_x509_read加载证书。 3. **构建推送消息**:APNS推送消息由两部分组成:一个设备令牌(Device Token)和通知负载。设备令牌是在用户的iOS...

    php实现的APNs服务端

    在实现APNs服务端前,你需要在Apple Developer Portal上创建一份Push Notification Service证书,并下载为.p12文件。然后,使用`openssl`命令行工具将其转换为.pem格式,用于PHP连接APNs服务器。 2. **设备Token的...

    [其他文档] ios APNS推送服务器代码pushTest

    在iOS应用开发中,Apple Push Notification service(APNS)是一项重要的服务,允许开发者向用户的设备发送远程通知。本文将深入探讨APNS的工作原理、PHP服务器端实现以及如何使用`pushTest.php`进行推送。 首先,...

    关于IOS_APNS推送消息(iphone端+服务端)

    在iOS应用开发中,Apple Push Notification service (APNs) 是苹果公司提供的一个关键服务,用于向用户的iPhone设备发送远程通知。这些通知可以是系统级别的消息,也可以是应用程序自定义的内容,比如新消息提醒或者...

    解析php做推送服务端实现ios消息推送

    在本文中,我们将深入探讨如何使用PHP作为服务端来实现iOS消息推送,主要针对苹果的APNs(Apple Push Notification service)。首先,了解APNs是苹果提供的一项服务,允许开发者向已安装其应用程序的iOS设备发送远程...

    【个推RestAPI V2】C#服务端SDK

    【个推RestAPI V2】C#服务端SDK是一个针对Android设备推送服务的开发工具,主要功能是通过C#编程语言实现对个推平台提供的RestAPI V2接口的调用,以便于开发者进行消息推送、用户管理、统计分析等操作。个推是一家...

    U盟消息推送_phpios推送_php安卓推送_thinkphp推送

    苹果的Push Notification Service (APNS) 是iOS设备接收推送通知的基础,而PHP作为后端服务器语言,可以通过与APNS交互来发送推送通知。开发者通常需要创建证书,配置服务器,并编写PHP脚本来生成并发送推送令牌。 ...

    ios推送信息 php语言版

    总结起来,实现iOS推送信息的PHP版本涉及多个步骤,包括在iOS客户端获取deviceToken、在Apple Developer Portal配置推送服务并生成PEM证书,以及在服务端编写PHP代码来构造和发送推送通知。这个过程虽然较为复杂,但...

    iOS-远程推送流程

    4. **生成服务端使用的证书文件**:如果使用PHP、Java或.NET等技术栈自行开发服务端,则需要将cer文件转换为适合服务端使用的格式,例如p12文件。这通常涉及到使用命令行工具或专门的软件来完成转换。 综上所述,...

    FCMPushNotification:Google Firebase云消息传递(FCM)推送通知php类,用于将推送通知发送到您的移动设备

    转到“项目设置”,然后转到“云消息传递”选项卡。 复制您的api密钥“ Serverkey”。 发送到设备示例 require require 'FCMPushNotification.php' ; $ FCMPushNotification = new \ BD \ ...

    PushMeBaby

    通过这个项目,我们可以学习到如何设置开发环境、配置证书、编写推送服务端代码以及客户端接收和处理推送通知的全过程。 1. **iOS推送通知概述**:推送通知是iOS应用在后台时与用户交互的主要方式,它可以在应用未...

    androidpn-client 0.5 推送

    AndroidPN(Android Push Notification)是一个开源项目,旨在为Android设备提供一个高效、可靠的消息推送服务。在移动应用开发中,消息推送是提高用户互动性和实时性的重要手段。AndroidPN客户端0.5版本的源码,...

    ios移动社交app的客户端+webservice服务器端源码

    - **通知推送**:使用APNs(Apple Push Notification service)发送消息通知,保持用户互动。 4. **ColorsTrip相关**: - ColorsTrip可能是应用的名称,也可能代表某种特定功能,如多彩旅行分享、颜色主题等,...

Global site tag (gtag.js) - Google Analytics