我想在管理员信息中心显示声音通知,而无需每当用户从前端下订单时加载页面。请帮我解决这个问题我在互联网上花了很多时间,但还没有找到任何解决方案。或者任何建议如何在PHP中进行通知处理?
答案 0 :(得分:1)
我的建议是使用Pusher。您可以注册一个免费帐户(pusher.com)。它们提供了一些非常简单的代码来启动。
第1步 - 在下新订单时触发此代码:
<?php
require __DIR__ . '/vendor/autoload.php';
$options = array(
'cluster' => 'eu',
'encrypted' => true
);
$pusher = new Pusher\Pusher(
'xxxx',
'xxxx',
'xxxx',
$options
);
$data['message'] = 'hello world';
$pusher->trigger('my-channel', 'my-event', $data);
?>
显然,您可以更改数组的内容以“推送”您喜欢的任何数据。
第2步 - 在您的管理信息中心接收推送的代码
<!DOCTYPE html>
<head>
<title>Pusher Test</title>
<script src="https://js.pusher.com/4.1/pusher.min.js"></script>
<script>
// Enable pusher logging - don't include this in production
Pusher.logToConsole = true;
var pusher = new Pusher('xxxx', {
cluster: 'eu',
encrypted: true
});
var channel = pusher.subscribe('my-channel');
channel.bind('my-event', function(data) {
alert(data.message);
});
</script>
</head>
因此,当您发送推送时,此代码将提醒您。
然后,您可以更改警报以实际播放声音。这里有很多关于如何实现这一目标的帖子,例如Playing sound notifications using Javascript?