熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> PHP編程 >> 正文

php ios推送(代碼)

2013-11-15 12:26:16  來源: PHP編程 
本篇文章是對php ios推送進行了詳細的分析介紹需要的朋友參考下   復制代碼 代碼如下:

  
<?php
//php需要開啟ssl(OpenSSL)支持
$apnsCert = "ckpem";//連接到APNS時的證書許可文件證書需格外按要求創建
$pass = "";//證書口令
$serverUrl = "ssl://gatewaysandboxpushapplecom:";//push服務器這裡是開發測試服務器
$deviceToken = "afcdaabdebcdfeabbfcdbcdbaca";//ios設備id中間不能有空格每個ios設備一個id
$message = $_GET [message] or $message = "hello!";
$badge = ( int ) $_GET [badge] or $badge = ;
$sound = $_GET [sound] or $sound = "default";
$body = array(aps => array(alert => $message badge => $badge sound => $sound));
$streamContext = stream_context_create();
stream_context_set_option ( $streamContext ssl local_cert $apnsCert );
stream_context_set_option ( $streamContext ssl passphrase $pass );
$apns = stream_socket_client ( $serverUrl $error $errorString STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT $streamContext);//連接服務器
if ($apns) {
echo "Connection OK <br/>";
} else {
echo "Failed to connect $errorString";
return;
}
$payload = json_encode ( $body );
$msg = chr() pack(n ) pack(H* str_replace( $deviceToken)) pack(n strlen($payload)) $payload;
$result = fwrite ( $apns $msg);//發送消息
fclose ( $apns );
if ($result)
echo "Sending message successfully: " $payload;
else
echo Message not delivered;
?>


From:http://tw.wingwit.com/Article/program/PHP/201311/20950.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.