PHP调用APNS服务发送提醒样例

 '收到后请给李高峰个电话', 'badge' => 1, 'sound' => 'default');
$payload = json_encode($aData);
$streamContext = stream_context_create();
$res = stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
 if (!$apns) {
    print "Failed to connect $err $errstrn";
    return false;
}
$deviceToken = 'd14e47t13d258f6d5a4d48547a6d1826f2a6b80fefd9d3119cadf0102648ed0';
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;

$result = fwrite($apns, $apnsMessage);
if ($result) {
    echo 'Message successfully delivered';
} else {
    echo 'Message not delivered';
}
socket_close($apns);
fclose($apns);
?>

你可能感兴趣的:(PHP调用APNS服务发送提醒样例)