PHP实现简单的页面语音播报功能(setInterval 循环播放)
JS代码
$(function () {
var set = setInterval(function(){
$.post(root+“control/adIndex.php?cla=orderList&fun=getTime”, ‘’, function(data){
if (data.status){
var audio = new Audio(data.url); //获取本地音频文件,ogg,mp3都可以
audio.play(); //执行播放操作
}
}, ‘json’);
}, 5000);
})
后台逻辑处理代码
//定时任务
public function getTime()
{
//这里插叙是否有新订单,如果有就提示,没有则忽略
$num =
t
h
i
s
−
>
s
q
l
Q
u
e
r
y
A
l
l
(
"
s
e
l
e
c
t
∗
f
r
o
m
o
r
d
e
r
L
i
s
t
w
h
e
r
e
o
r
d
e
r
S
t
a
t
e
=
′
待
发
货
′
a
n
d
p
l
a
y
=
′
′
"
)
;
i
f
(
!
e
m
p
t
y
(
this->sqlQueryAll("select * from orderList where orderState='待发货' and play=''"); if (!empty(
this−>sqlQueryAll("select∗fromorderListwhereorderState=′待发货′andplay=′′");if(!empty(num)){
$file=query(“systemFile”,“id=‘xu3rrjx17co8’”);
$json[‘status’]= 1;
j
s
o
n
[
′
u
r
l
′
]
=
r
o
o
t
.
json['url']=root.
json[′url′]=root.file[‘src’];
foreach ($num as KaTeX parse error: Expected '}', got 'EOF' at end of input: …"where"=>"id='{item[‘id’]}’"));
}
} else {
KaTeX parse error: Expected 'EOF', got '}' at position 28: …']= 0; }̲ return…json,320);
}