准備工作
testpush
<?php
//手機注冊應用返回唯一的deviceToken
$deviceToken =
//ck
$pass =
//消息內容
$message =
//badge我也不知是什麼
$badge =
//sound我也不知是什麼(或許是推送消息到手機時的提示音)
$sound =
//建設的通知有效載荷(即通知包含的一些信息)
$body = array();
$body[
$body[
if ($badge)
$body[
if ($sound)
$body[
//把數組數據轉換為json數據
$payload = json_encode($body);
echo strlen($payload)
//下邊的寫法就是死寫法了
//唯一要修改的就是
$ctx = stream_context_create();
stream_context_set_option($ctx
stream_context_set_option($ctx
$fp = stream_socket_client(
if (!$fp) {
print "Failed to connect $err $errstrn";
return;
}
else {
print "Connection OKn<br/>";
}
// send message
$msg = chr(
print "Sending message :"
fwrite($fp
fclose($fp);
?>
From:http://tw.wingwit.com/Article/program/PHP/201311/21331.html