2017-09-06 36 views
2

我希望在管理控制台中显示声音通知,而无需在用户从前端添加新订单时进行页面加载。请帮我关于这个问题,我在互联网上花了很多时间,但还没有找到任何解决方案。或者任何建议如何可能在PHP中通知过程?在管理控制台中显示声音通知

+2

你可能在你的管理页面上有一个监听器代码,它会向服务器发出一个AJAX请求每隔n秒(1 Shubhranshu

回答

1

我的建议是使用推杆。您可以注册一个免费帐户(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?