首页 php教程 php手册 分享一个搭建php版push服务器的流程

分享一个搭建php版push服务器的流程

Jun 06, 2016 pm 07:54 PM
http php push 分享 搭建 服务器 流程

http://www.cocoachina.com/bbs/read.php?tid-30410.html 得出从零开始的php版push服务器搭建流程: ============================================================== 0.在Mac OS X机器上安装好XCode, 连接一台正常的iPhone, 保持平和的心态 APP 开发基础设

http://www.cocoachina.com/bbs/read.php?tid-30410.html


得出从零开始的php版push服务器搭建流程:
==============================================================
0.在Mac OS X机器上安装好XCode, 连接一台正常的iPhone, 保持平和的心态

APP 开发基础设置
1.在iPhone Provisioning Portal中建立好APP ID和Device.
2.在Keychain Access.app中生成证书请求CertificateSigningRequest.certSigningRequest(菜单 > Keychain Access > Certificate Assistant > Request a Certificate From a Certificate Authority...).
3.在iPhone Provisioning Portal > Certificates中请求一个证书(点击Request Certificate,上传CertificateSigningRequest.certSigningRequest).
4.请求完成后,将证书文件(developer_identity.cer)下载,双击导入到Key Chain中.
5.在iPhone Provisioning Portal > Provisioning 中,新建一个Profile, 选择指定的APP ID和 Devices后生成.
6.将刚刚生成的Profile下载为*_profile.mobileprovision, 双击该文件, 将profile加载到iPhone中.

Push Notification service设置
7.在iPhone Provisioning Portal > App IDs,选择需要Push服务的App ID, 进入Configure.
8.确认 Enable for Apple Push Notification service ,配置 Development Push SSL Certificate, 上传第2步生成的证书请求.
9.下载生成的aps_developer_identity.cer, 完成Push服务配置.
10.双击aps_developer_identity.cer,保存到Key Chain.

生成php Push Notification sender需要的证书文件
11.在Keychain Access.app里选定这个新证书(Apple Development Push Services*),导出到桌面,保存为Certificates.p12.
12.运行如下命令:

    openssl pkcs12 -clcerts -nokeys -out cert.pem -in Certificates.p12 
    openssl pkcs12 -nocerts -out key.pem -in Certificates.p12 
    openssl rsa -in key.pem -out key.unencrypted.pem 
    cat cert.pem key.unencrypted.pem > ck.pem
登录后复制

获得php Push Notification sender所需的设备令牌:
13.新建一个View-based Application项目,在$PROJECT_NAMEAppDelegate.m中:
a.粘贴如下代码:

- (void)applicationDidFinishLaunching:(UIApplication *)app { 
    // other setup tasks here…. 
    [window addSubview:viewController.view]; 
    [self alertNotice:@"" withMSG:@"Initiating Remote Noticationss Are Active" cancleButtonTitle:@"Ok" otherButtonTitle:@""]; 
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)]; 
} 
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 
    //NSLog(@"devToken=%@",deviceToken); 
    [self alertNotice:@"" withMSG:[NSString stringWithFormat:@"devToken=%@",deviceToken] cancleButtonTitle:@"Ok" otherButtonTitle:@""]; 
} 
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { 
    NSLog(@"Error in registration. Error: %@", err); 
    [self alertNotice:@"" withMSG:[NSString stringWithFormat:@"Error in registration. Error: %@", err] cancleButtonTitle:@"Ok" otherButtonTitle:@""]; 
} 
-(void)alertNotice:(NSString *)title withMSG:(NSString *)msg cancleButtonTitle:(NSString *)cancleTitle otherButtonTitle:(NSString *)otherTitle{ 
    UIAlertView *alert; 
    if([otherTitle isEqualToString:@""]) 
        alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:cancleTitle otherButtonTitles:nil,nil]; 
    else 
        alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:cancleTitle otherButtonTitles:otherTitle,nil]; 
    [alert show]; 
    [alert release]; 
}
登录后复制

b.在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 方法中增加
    [self alertNotice:@"" withMSG:@"Initiating Remote Noticationss Are Active" cancleButtonTitle:@"Ok" otherButtonTitle:@""]; 
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)];
登录后复制

14.项目设置
a.Targets > $APP_NAME > context menu > Properties > Identifier
    修改 identifier 为App ID
b.Targets > $APP_NAME > context menu > Build > Code Signing > Code Signing Identifier > Any iPhone OS Device
    指定 iPhone Developer 为开发用机
15.编译并运行后会在iPhone上显示设备令牌

16.php Push Notification sender代码如下:

<?php $deviceToken = "设备令牌"; 

$body = array("aps" => array("alert" =&gt; 'message', "badge" =&gt; 1, "sound" =&gt; 'received5.caf')); 

$ctx = stream_context_create(); 
stream_context_set_option($ctx, "ssl", "local_cert", "ck.pem"); 

$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 $errstrn"; 
    return; 
} 
print "Connection OK\n"; 
$payload = json_encode($body); 
$msg = chr(0) . pack("n",32) . pack("H*", $deviceToken) . pack("n",strlen($payload)) . $payload; 
print "sending message :" . $payload . "\n"; 
fwrite($fp, $msg); 
fclose($fp); 
?&gt;
登录后复制











本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门文章

仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章

仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章标签

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

适用于 Ubuntu 和 Debian 的 PHP 8.4 安装和升级指南 适用于 Ubuntu 和 Debian 的 PHP 8.4 安装和升级指南 Dec 24, 2024 pm 04:42 PM

适用于 Ubuntu 和 Debian 的 PHP 8.4 安装和升级指南

CakePHP 日期和时间 CakePHP 日期和时间 Sep 10, 2024 pm 05:27 PM

CakePHP 日期和时间

CakePHP 项目配置 CakePHP 项目配置 Sep 10, 2024 pm 05:25 PM

CakePHP 项目配置

CakePHP 文件上传 CakePHP 文件上传 Sep 10, 2024 pm 05:27 PM

CakePHP 文件上传

CakePHP 路由 CakePHP 路由 Sep 10, 2024 pm 05:25 PM

CakePHP 路由

讨论 CakePHP 讨论 CakePHP Sep 10, 2024 pm 05:28 PM

讨论 CakePHP

CakePHP 快速指南 CakePHP 快速指南 Sep 10, 2024 pm 05:27 PM

CakePHP 快速指南

如何设置 Visual Studio Code (VS Code) 进行 PHP 开发 如何设置 Visual Studio Code (VS Code) 进行 PHP 开发 Dec 20, 2024 am 11:31 AM

如何设置 Visual Studio Code (VS Code) 进行 PHP 开发

See all articles