温馨提醒

如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢

本文最后更新于2023年11月14日,已超过 180天没有更新

使用场景:

所涉网站启用了会员功能,部分内容需要升级VIP会员才可以,所以需要在网站后台增加一个对VIP会员数据的检测,当有新订单创建的时候,自动发送语音提醒。

本次涉及的数据表为#@__member_operation。

实现思路:

通过AJAX定时检测指定的表,如果检测到符合的数据,就执行播放语音的操作。

具体步骤:

一、在dede/templets/index2.htm页面底部增加如下代码:

<!--支付成功声音提示-->
<script type="text/javascript">
    function hello() {
        $.ajax({
            url: '/dede/getOrder.php',
            type: 'get',
            datatype: 'text',
            async: false,
            success: function(result) {
                if (result == 200) {
                    playSound();
                }
            }
        });
    }
    setInterval("hello()", 10000); // 10秒刷新一次 window.onbeforeunload = function (e) { var message = 'some word'; e = e || window.event; if (e) { e.returnValue = message; } clearInterval() }; 
    
</script>
<script>
    var playSound = function(msgfile = "/images/voice.mp3") {
        var borswer = window.navigator.userAgent.toLowerCase();
        if (borswer.indexOf("ie") >= 0) { //IE内核浏览器 var strEmbed = '<embed name="embedPlay" src="'+msgfile+'" autostart="true" hidden="true" loop="false"></embed>'; if ( $( "body" ).find( "embed" ).length <= 0 ) $( "body" ).append( strEmbed ); var embed = document.embedPlay; //浏览器不支持 audion,则使用 embed 播放 embed.volume = 100; //embed.play();这个不需要 } else { //非IE内核浏览器 var strAudio = "<audio id='audioPlay' src='"+msgfile+"' hidden='true'>"; if($("#audioPlay").length<=0){ $( "body" ).append( strAudio ); } var audio = document.getElementById( "audioPlay" ); //浏览器支持 audio audio.play(); } } 
            
</script>

二、新增文件dede/getOrder.php,具体代码如下:

<?php 
/** * 订单检测管理 * * @writer zhimatong * @time 2021-12-19 */
require_once(dirname(__FILE__).'/config.php');
require_once(DEDEINC.'/common.func.php');
$row = $dsql->GetOne("SELECT * FROM `#@__member_operation` WHERE sta=0 and (mtime <= (now() - 1000*60*30))");
//30分钟内有新订单提醒 if(is_array($row)) { echo 200; }else{ echo 100; } exit();

这样就可以了,当30分钟内有新的未完成的订单时就会自动语音消息提醒。如果只检测付款成功的,可以将查询语句改成sta=1。

历史上的今天
11月
14
    抱歉,历史上的今天作者很懒,什么都没写!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。