前端public/assets/js/backend/index.js
function tixing(){
$.get("tixing/get",function(res){
if(res.code==1){
playSound(res.data.mp3)
}
setTimeout(function(){tixing()},10000);
});
}
tixing()
function playSound(mp3){
var borswer = window.navigator.userAgent.toLowerCase();
if(!!window.ActiveXObject || "ActiveXObject" in window){
//IE内核浏览器
var strEmbed = '<embed name="embedPlay" src="'+mp3+'" autostart="true" hidden="true" loop="false"></embed>';
if($("body").find("embed").length<=0){
$("body").append(strEmbed);
}else{
$("body").find("embed").remove();
$("body").append(strEmbed);
}
var embed = document.embedPlay;
//浏览器不支持 audion,则使用 embed 播放
embed.volume = 100;
}else{
//非IE内核浏览器
var strAudio = "<audio id='audioPlay' src='"+mp3+"' hidden='true'>";
if($("body").find("audio").length<=0){
$("body").append(strAudio);
}
var audio = document.getElementById( "audioPlay" );
//浏览器支持 audion
audio.play();
}
}
/application/admin/controller/Tixing.php
<?php
namespace app\admin\controller;
use app\common\controller\Backend;
/**
* Ajax异步请求接口
* @internal
*/
class Tixing extends Backend
{
protected $noNeedLogin = [];
protected $noNeedRight = ['*'];
protected $layout = '';
public function _initialize()
{
parent::_initialize();
//设置过滤方法
$this->request->filter(['trim', 'strip_tags', 'htmlspecialchars']);
}
/**
* 判断是否提醒
*/
public function get()
{
$data["mp3"]="/recharge.mp3";
$this->success("有新订单","",$data);
}
}
发表评论 取消回复