本篇文章是对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;
?>