http://eric-gao.iteye.com/blog/1567777
1、将aps_developer_identity.cer转换成aps_developer_identity.pem格式
2、将p12格式的私钥转换成pem
openssl pkcs12 -nocerts -out Push_Noenc.pem -inPush.p12
4、创建p12文件
这样我们就得到了在.net或java等后台应用程序中使用的证书文件: aps_developer_identity.p12
接下来就要测试一下啦,是不是很激动~
为了测试证书工作的状况,我们可以使用“telnet gateway.sandbox.push.apple.com 2195”来检测一下,如果显示
然后,我们使用我们生成的证书和私钥来设置一个安全的链接去链接苹果服务器
在终端输入如下命令:openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert PushChatCert.pem -key PushChatKey.pem
需要输入密码(abc123 我们刚才所设置的)。
然后他会返回一系列的数据,这里我就粘贴一部分啦:
CONNECTED(00000003)
depth=1 /C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C
verify error:num=20:unable to get local issuer certificate
verify return:0
---
Certificate chain
。。。。。(省略)
。。。。。(省略)
。。。。。(省略)
Start Time: 1416389389
Timeout : 300 (sec)
Verify return code: 0 (ok)
---
测试就到这里啦。。。
------代码----
#pragma mark - 接受deviceToken
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
__block NSString *token1 = [NSString stringWithFormat:@"%@", deviceToken];
NSLog(@"My token is:%@", token1);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
token1 = [token1 stringByReplacingOccurrencesOfString:@"<" withString:@""];
token1 = [token1 stringByReplacingOccurrencesOfString:@">" withString:@""];
[SANDBOXHELPER saveCoreInfoToSandBox:token1 withKey:kDeviceTokenInSandBox];
NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithObject:token1 forKey:@"deviceToken"];
if(getUserId && ![[getUserId stringValue] isEqualToString:@""]){//如果userID不为空
[dic setObject:getUserId forKey:@"memberId"];
}
[[JSFAPI shareInstance] do_request:upload_device_token withData:dic withSuccessHandler:^(NSDictionary *json) {
PYLog(@"%@",json);
} fail:^(NSError *error) {
PYLog(@"%@",error);
}];
});
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{
NSLog(@"My token is:");
}
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
NSLog(@"Failed to get token, error: %@" , error);
}
#pragma mark - 接受到push
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
PYLog(@"%@",userInfo);
[UIApplication sharedApplication].applicationIconBadgeNumber++;
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil message:userInfo[@"aps"][@"alert"] delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"去看看", nil];
[alert show];
objc_setAssociatedObject(alert, &alertViewAndUserInfo, userInfo, OBJC_ASSOCIATION_RETAIN);
}