设为首页 收藏本站
查看: 579|回复: 0

[经验分享] (转)Push Notification的证书及服务端php的代码方面的资料

[复制链接]

尚未签到

发表于 2017-4-13 10:22:15 | 显示全部楼层 |阅读模式
  (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 theCertificateSigningRequest.certSigningRequest file to request aproduction cert in the future or renew it again.
  (6) Suppose you have imported the aps_developer_identity.cer to thekeychain. Then you have to export these new cert and the private key ofthis cert (not the public key) and saved as .p12 files.
  (7) Then you use these commands to generate the cert and key inMac's Terminal for PEM format (Privacy Enhanced Mail SecurityCertificate)
  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 usingchmod 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, youcan find them in the Developer Forum. This is the one that I used, forphp. Run this (after obtaining the device token from the testing deviceand 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.pemfile) // $pass = ''; // Get the parameters from http get or fromcommand 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 bundleidentifier to the App ID that you created and imported the newprovisioning profile for that APP ID to the XCode and iPhone. Thenimplement 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(@"%@",[[[launchOptionsobjectForKey:@"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 generatedevice tokens. Restoring from backup is not currently supported.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-364309-1-1.html 上篇帖子: php与memcached服务器交互的分布式实现源码分析 [memcache版] 下篇帖子: PHP RSS/Feed 生成类库(支持RSS 1.0/2.0和ATOM)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表