分享

消息推送php

 nywrb 2012-09-26

搭建环境

116人阅读 评论(0) 收藏 举报

目录(?)[+]


1。搭建web服务器

 从 http://www./en/xampp-macosx.html 下载 xampp

81M ..  等待中


* Step 1: Download

Simply click on the link below. It's a good idea to get the latest version. :)

A complete list of downloads (older versions) is available at  SourceForge.
There are none yet, but there will be.

XAMPP for Mac OS X 1.7.3, 2010/03/04

Version

Size

Notes
 XAMPP Mac OS X 1.7.3
Universal Binary
86 MB Apache 2.2.14, MySQL 5.1.44, PHP 5.3.1, Perl 5.10.1, ProFTPD 1.3.3, phpMyAdmin 3.2.4, OpenSSL 0.9.8k, GD 2.0.35, Freetype 2.3.5, libjpeg 6b, libpng 1.2.32, libungif-4.1.4, zlib 1.2.3, expat 2.0.1, Ming 0.4.2, Webalizer 2.01-10, pdf class 009e, mod_perl 2.0.4, SQLite 3.6.3, gdbm-1.8.3, libxml-2.7.2, libxslt-1.1.24, openldap-2.3.43, imap-2004g, gettext-0.16.1, libmcrypt-2.5.8, mhash-0.9.9, zziplib-0.13.48, bzip2-1.0.5, freetds-0.64 
MD5 checksum: fcbd4b14461a5b9e7a817f99defd0be2
 Developer package 32 MB Developer package 
MD5 checksum: f31a0619a35507a0e4305b674ae1159b

* Step 2: Installation

To install XAMPP just do the following:

  • Open the DMG-Image.
  • Drag'n'Drop the XAMPP folder into your Applications folder.

Notice: all old installations of XAMPP for MacOS X will be overwritten!

That's all. XAMPP is now installed below the /Applications/XAMPP directory.

* Step 3: Start

To start XAMPP simply open XAMPP Control and start Apache, MySQL and ProFTPD.

* Step 4: Test

OK, that was easy but how can you check that everything really works? Just type in the following URL at your favourite web browser:

http://localhost

Now you should see the start page of XAMPP containing some links to check the status of the installed software and some small programming examples.



2。引入php push的功能

首先创建 pem 文件

Generate a Push Certificate

To generate a certificate on a Mac OS X:

  1. Log-in to the iPhone Developer Program Portal
  2. Choose App IDs from the menu on the right (or click here)
  3. Create an App ID without a wildcard. For example 3L223ZX9Y3.com.armiento.test
  4. Click the Configure link next to this App ID and then click on the button to start the wizard to generate a new Development Push SSL Certificate (Apple Documentation: Creating the SSL Certificate and Keys)
  5. Download this certificate and double click on aps_developer_identity.cer to import it into your Keychain
  6. Launch Keychain Assistant (located in Application, Utilities or search for it with Spotlight) and click on My Certificates on the left
  7. Expand Apple Development Push Services and select Apple Development Push Services AND your private key (just under Apple Development Push Services)
  8. Right-click and choose "Export 2 elements..." and save as server_certificates_bundle_sandbox.p12 (don't type a password).
  9. Open Terminal and change directory to location used to save server_certificates_bundle_sandbox.p12 and convert the PKCS12 certificate bundle into PEM format using this command (press enter when asked for Import Password):

    openssl pkcs12 -in server_certificates_bundle_sandbox.p12 -out server_certificates_bundle_sandbox.pem -nodes -clcerts

Verify peer using Entrust Root Certification Authority

Download the Entrust Root Authority certificate directly from Entrust Inc. website:

  1. Navigate to https://www./downloads/root_index.cfm
  2. Choose "Personal Use"
  3. Download the Entrust CA (2048) file (entrust_2048_ca.cer) https://www./downloads/binary/entrust_2048_ca.cer for theSandbox environment; download the Entrust Secure Server CA file (entrust_ssl_ca.cer)https://www./downloads/binary/entrust_ssl_ca.cer for the Production environment until December 22nd (after December 22nd, 2010 you have to use entrust_2048_ca.cer also for the Production Environment as Apple said: "To ensure you can continue to validate your server's connection to the Apple Push Notification service, you will need to update your push notification server with a copy of the 2048-bit root certificate from Entrust's website.").
If you want to use the same file for the Sandbox and the Production environment please concat the two certificates. For example:

wget https://www./downloads/binary/entrust_2048_ca.cer -O - > entrust_root_certification_authority.pem
echo >> entrust_root_certification_authority.pem
wget https://www./downloads/binary/entrust_ssl_ca.cer -O - >> entrust_root_certification_authority.pem

Otherwise (for use only in a Mac OS X environment), export the Entrust Root Authority certificate:

  1. Launch Keychain Assistant (located in Application, Utilities or search for it with Spotlight) and click on System Root Certificate on top-left and Certificates on the bottom-left
  2. Right-click on Entrust Root Certification Authority and export with entrust_root_certification_authority.pem file name and choose as document format Privacy Enhanced Mail (.pem).
  3. Now you can use this PEM file as Entrust Root Certification Authority in ApnsPHP to verify Apple Peer!

anpns 的api:

http://apns-php./svn/reference/index.html


部署apns

将http://code.google.com/p/apns-php/ 里面下载到的框架代码放置到 xampp/xamppfiles/htdocs/  目录下。

将 server_certificates_bundle_sandbox.pem 和 Entrust Root Certification Authority.pem 放置到 xampp/xamppfiles/htdocs/  目录下。

修改 sample_xxxxxx.php 里面的 ‘server_certificates_bundle_sandbox.pem’ 名字,原php文件里面的命名是错的。这个如果是新接触php或者完全不懂php的人,一开始可能还以为证书位置放错了-- ,其实是名字有点点的不同。

启动xmpp后,准备测试几个sample_xxx.php,进入这几个文件,将自己的 device token 填进去替换原来的。

网页访问 http://localhost/sample_push.php ,会报错连接一个错误。进入 Abstract.php 343行。注释掉 

'verify_peer' => isset($this->_sRootCertificationAuthorityFile),
即可。


测试该网页,你会发现,你收到push消息了。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多