http://blog.csdn.net/think12/article/details/8863411 // IOS Push 证书的重新生成
本文着重讨论如何合成证书
1.将aps_developer_identity.cer转换成pem
openssl x509 -in aps_developer_identity.cer -inform der -out PushChatCert.pem
2.将Apple Development Push Services证书转换成pem
(push.p12文件是在钥匙串里面用证书生成的)
openssl pkcs12 -nocerts -out PushChatKey.pem -in Push.p12
3.合成两个pem证书
1)Java服务器所需的证书为p12格式
openssl pkcs12 -export -in PushChatCert.pem -inkey PushChatKey.pem -out pushCert.p12 -name “apns-cert”
2)PHP服务器所需证书为pem格式
cat PushChatCert.pem PushChatKey.pem > pushCert.pem
//这两行代码是用来测试的时候配合php测试来使用的,附件中的图片有详细介绍,附件有php运行源文件。
telnet gateway.sandbox.push.apple.com 2195
openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert PushChatCert.pem -key PushChatKey.pem
PHP服务器推送代码
李建国 10:35:18
七 项目测试
建立我们的推送的项目(注意BundleIdentifier必须和我们推送应用的App id一致)
在AppDelegate里didFinishLaunchingWithOptions函数里写
- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
……
//推送的形式:标记,声音,提示
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
return YES;
}
- (void)application:(UIApplication *)applicationdidRegisterForRemoteNotificationsWithDeviceToken:(NSData *)pToken {
NSLog(@"regisger success:%@",pToken);
//注册成功,将deviceToken保存到应用服务器数据库中
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
// 处理推送消息
NSLog(@"userinfo:%@",userInfo);
NSLog(@"收到推送消息:%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]);
}
- (void)application:(UIApplication *)applicationdidFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"Registfail%@",error);
}
我们运行程序的时候会有提示,说我们的程序要发送推送通知
//解析请求返回的deviceToken
const unsigned *tokenBytes = [deviceToken bytes];
NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
NSLog(@"regisger success:%@",hexToken);