為Apple Push開發(fā)的PHP PEAR 包:Services
Jun 06, 2016 pm 07:43 PMApple Push Notification Service:通過蘋果服務(wù)器向app用戶推送消息,無需啟動app。 蘋果官方文檔:http://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_r
Apple Push Notification Service:通過蘋果服務(wù)器向app用戶推送消息,無需啟動app。
蘋果官方文檔:http://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW9
對于這種第三方庫,PHP官方稱之為PEAR,需要按照PEAR標(biāo)準(zhǔn)開發(fā)(標(biāo)準(zhǔn)URI)。
PEAR的優(yōu)勢:一鍵安裝到php/lib/php目錄,require即可使用,很方便。
PHP PEAR上有一個Services_Apns,github上有一個Services_APNS,但都無法使用,所以我開發(fā)了一個,安裝步驟如下:
pear channel-discover sinkcup.github.io/<span>pear pear </span><span>install</span> sinkcup/Services_Apple_PushNotification
使用步驟:
1、登錄蘋果開發(fā)者后臺,下載dev或prod證書,合并成pem文件。在ios app里添加push權(quán)限,獲得device token。參考:http://www.cnblogs.com/gpwzw/archive/2012/03/31/Apple_Push_Notification_Services_Tutorial_Part_1-2.html
2、demo(參考)
<span>php require_once </span><span>'</span><span>Services/Apple/PushNotification.php</span><span>'</span><span>; $conf </span>=<span> array( </span><span>'</span><span>password</span><span>'</span> => <span>'</span><span>12346</span><span>'</span><span>, </span><span>'</span><span>cert</span><span>'</span> => <span>'</span><span>/home/u1/cert.pem-sandbox</span><span>'</span><span>, ); $o </span>= new Services_Apple_PushNotification(<span>'</span><span>sandbox</span><span>'</span><span>, $conf); $deviceToken </span>= <span>'</span><span>aaaf818eaae8a5aa11aaaf9aa8f8aa15aaefae75a1aaaa597e51917aa2a1a111</span><span>'</span><span>; $data </span>=<span> array( </span><span>'</span><span>aps</span><span>'</span> =><span> array( </span><span>'</span><span>alert</span><span>'</span> => <span>'</span><span>測試push sandbox</span><span>'</span><span>, </span><span>'</span><span>badge</span><span>'</span> => <span>2</span><span>, </span><span>'</span><span>sound</span><span>'</span> => <span>'</span><span>default</span><span>'</span><span>, ) ); $r </span>= $o-><span>send($deviceToken, $data); var_dump($r); exit; </span>?>
輸出:
<span>bool</span>(<span>true</span>)
我的PEAR 頻道:http://sinkcup.github.io/pear/
Services_Apple_PushNotification項目代碼:https://github.com/sinkcup/Services_Apple_PushNotification

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Comments cannot be careless because they want to explain the reasons for the existence of the code rather than the functions, such as compatibility with old interfaces or third-party restrictions, otherwise people who read the code can only rely on guessing. The areas that must be commented include complex conditional judgments, special error handling logic, and temporary bypass restrictions. A more practical way to write comments is to select single-line comments or block comments based on the scene. Use document block comments to explain parameters and return values at the beginning of functions, classes, and files, and keep comments updated. For complex logic, you can add a line to the previous one to summarize the overall intention. At the same time, do not use comments to seal code, but use version control tools.

PHPblockcommentsareusefulforwritingmulti-lineexplanations,temporarilydisablingcode,andgeneratingdocumentation.Theyshouldnotbenestedorleftunclosed.BlockcommentshelpindocumentingfunctionswithPHPDoc,whichtoolslikePhpStormuseforauto-completionanderrorche

The key to writing good comments is to explain "why" rather than just "what was done" to improve the readability of the code. 1. Comments should explain logical reasons, such as considerations behind value selection or processing; 2. Use paragraph annotations for complex logic to summarize the overall idea of functions or algorithms; 3. Regularly maintain comments to ensure consistency with the code, avoid misleading, and delete outdated content if necessary; 4. Synchronously check comments when reviewing the code, and record public logic through documents to reduce the burden of code comments.

TolearnPHPeffectively,startbysettingupalocalserverenvironmentusingtoolslikeXAMPPandacodeeditorlikeVSCode.1)InstallXAMPPforApache,MySQL,andPHP.2)Useacodeeditorforsyntaxsupport.3)TestyoursetupwithasimplePHPfile.Next,learnPHPbasicsincludingvariables,ech

The first step is to select the integrated environment package XAMPP or MAMP to build a local server; the second step is to select the appropriate PHP version according to the project needs and configure multiple version switching; the third step is to select VSCode or PhpStorm as the editor and debug with Xdebug; in addition, you need to install Composer, PHP_CodeSniffer, PHPUnit and other tools to assist in development.

The key to setting up PHP is to clarify the installation method, configure php.ini, connect to the web server and enable necessary extensions. 1. Install PHP: Use apt for Linux, Homebrew for Mac, and XAMPP recommended for Windows; 2. Configure php.ini: Adjust error reports, upload restrictions, etc. and restart the server; 3. Use web server: Apache uses mod_php, Nginx uses PHP-FPM; 4. Install commonly used extensions: such as mysqli, json, mbstring, etc. to support full functions.

To learn PHP, you need to master variables and data types, control structures, function definitions and call specifications, and avoid common syntax errors. 1. Variables start with $, case sensitive, and types include strings, integers, booleans, etc.; 2. The control structure supports if/else/loop, and the template can use colon syntax instead of curly braces, foreach can handle arrays conveniently; 3. Functions are defined with function, supporting default parameters and variable parameters; 4. Common errors include missing semicolons, confusion == and ===, splicing characters errors, and improper use of array subscripts.

The key to writing PHP comments is clear, useful and concise. 1. Comments should explain the intention behind the code rather than just describing the code itself, such as explaining the logical purpose of complex conditional judgments; 2. Add comments to key scenarios such as magic values, old code compatibility, API interfaces, etc. to improve readability; 3. Avoid duplicate code content, keep it concise and specific, and use standard formats such as PHPDoc; 4. Comments should be updated synchronously with the code to ensure accuracy. Good comments should be thought from the perspective of others, reduce the cost of understanding, and become a code understanding navigation device.
