在網路上找到很多範例
做法其實都一樣
範例如下:
$deviceToken =
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$certificateFile = 'ck.pem;
$pushServer = 'ssl://gateway.sandbox.push.apple.com:2195';
$feedbackServer = 'ssl://feedback.sandbox.push.apple.com:2196';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert',
$certificateFile);
$fp = stream_socket_client($pushServer, $error, $errorStr, 100,
STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $streamContext);
$payloadObject = array('aps' => array('alert' => 'Server Time','sound' =>
'default','badge' => 3),'custom_key' => 'custom_value22');
$payload = json_encode($payloadObject);
$expire = time() + 3600;
$id = time();
if ($expire) {
$binary = pack('CNNnH*n', 1, $id, $expire, 32, $deviceToken,
strlen($payload)).$payload;
}
$result = fwrite($fp, $binary);
fclose($fp);
if( $result )
{
echo "寫入成功!" . $result;
}
else
{
echo "寫入失敗!";
}
我檢查$fp有連線成功(TRUE)
$result也有回傳成功訊息(字數)
但手機一直沒有收到推播訊息
有人有遇過類似的狀況或可以麻煩幫我看一下是否程式有問題?
若程式沒問題我才能再去檢查是否是其他因素造成QQ