打电话

Posted 羽玉

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了打电话相关的知识,希望对你有一定的参考价值。


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
    <link href="https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/theme/default/layer.min.css" rel="stylesheet" />
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/layer.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script>
        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
        
        var mobileText = getQueryString(\'mobile\'); // 电话号码
        var ownerUserId = getQueryString(\'ownerUserId\'); // 用户id
        var mobile = \'\';
        // 回调的validate
        var validate = \'\';
        // 唯一标识 用于判断回调是否为本页面外呼的
        var flagStr = \'DEFAULT\' + Math.ceil(Math.random() * 10000);
        console.log(flagStr)

        var socket;
        //通话是否开启
        var conn = false;

        window.onload = function () {
            initWebSocket();
            $(\'#Phone\').val(mobileText);
            getPhone();
        }

        var initWebSocket = function () {
        
            if (window.WebSocket) {
            var url=\'ws://127.0.0.1:2013\';
            //url=\'wss://localhost:2014\';
                socket = new WebSocket(url);
                socket.onmessage = function (event) {
                    var data = jQuery.parseJSON(event.data);
                    console.log(data.Event);
                    console.log(data);
                    TimerRun = 15;
                    TimerId = 0;
                    var Workid = \'\';
                    var Phone = \'\';
                    var CXID = \'\';
                    var UserName = \'\';
                    Phone = data.Phone; CXID = data.CXID; UserName = data.UserName;
                    
                    switch (data.Event) {
                        case \'登录\':
                            layer.msg(\'登录成功!\');
                            $("#AgentId").val(data.Workid);
                            break;
                        case \'来电\':
                            console.log(\'来电\');
                            $("#Phone").val(data.Phone);
                            //setTimeout(function () {
                            //    SetAgentTime(\'呼入\', data.Workid, data.Phone);
                            //}, 2000);
                            break;
                        case \'摘机\':
                            TimerRun = 0;
                            answer();
                            break;
                        case \'挂机\':
                            TimerRun = 0;
                            // let mobile = mobile;
                            if (flagStr === data.Validate) {
                                getRecord(data, mobile);
                            }
                            layer.msg(\'挂机!\');
                            console.log(\'挂机\');
                            $("#Phone").val(\'\');
                            $("#called").val(\'\');
                            break;
                        case \'呼出\':
                            layer.msg(\'正在拨号中...\');
                            validate = data.Validate;
                            // debugger
                            // $("#Phone").val(mobile);
                            break;
                        case \'SIMState\':
                        debugger
                            layer.msg(\'SIMState卡状态!\');
                            break;
                        case \'提交\':

                            break;
                        default:
                            break;
                    }
                };
                socket.onopen = function (event) {
                    layer.msg(\'连接成功!\');
                    console.log("连接成功");
                    conn = true;
                };
                socket.onclose = function (event) {
                    console.log("连接关闭");
                    layer.msg(\'连接关闭!请登录客户端坐席系统\');
                    conn = false;
                    socket.close();
                    setTimeout(function () {
                        initWebSocket();
                    }, 3000);
                };
                socket.onerror = function (event) {
                    //v.value = "出错";
                    
                };
            }
            else {
                layer.msg(\'浏览器不支持\');
            }
        }

        //发送消息
        var send = function (msg) {
            socket.send(msg);
            if (socket.readyState !== 1) {
                alert(socket.readyState);
                socket.close();
                initWebSocket();
                setTimeout(function () {
                    data();
                    console.log(\'a\',data())
                }, 3000);
            }
            else {
                //data();
            };
        }

        function checkConn() {
            if (!conn) {
                layer.msg(\'请登录客户端坐席系统!\');
            }
            return conn;
        }

        //打电话
        function call() {
            if (checkConn()) {
                console.log(mobile);
                var url = "flycall://action=dial&called=" + mobile + "&business=123456789" + \'&validate=\' + flagStr;
                send(url);
                
            }
        }

        //接听
        function answer() {
            if (checkConn()) {
                var url = "flycall://action=answer";
                send(url);
            }
        }

        //挂断
        function hangup() {
            if (flagStr !== validate) {
                return;
            }
            if (checkConn()) {
                var url = "flycall://action=hangup";
                send(url);
            }
        }
        //话后提交
        function commit() {
            var url = "flycall://action=commit";
            send(url);
        }
        
        //空闲
        function ready() {
            var url = "flycall://action=ready";
            send(url);
        }
        
        //置忙
        function busy() {
            var url = "flycall://action=busy";
            send(url);
        }
        
        function SelChange(){
            switch($("#SelState").val())        
            {
                case \'空闲\':
                    ready();
                break;
                case \'置忙\':
                    busy();
                break;
            }
        }
        
        function getRecord(data, phone) {
            let formData = {
                callTime: data.CallTime,
                answerTime: data.AnswerTime,
                hangupTime: data.HangUpTime,
                signalFlag: data.Signal,
                workId: data.Workid,
                mobile: phone,
                userName: data.UserName,
                recordUrl: data.RecordUrl,
                callRebark: data.CallRebark,
                serverIP: data.ServerIP,
                cxid: data.CXID,
                userId: ownerUserId,
                remark: \'\'
            };
            $.ajax({
                contentType: "application/json;charset=UTF-8",
                url: "/services/promo/phone/record/add",
                dataType: \'json\',
                type: "post",
                data: JSON.stringify(formData),
                success: function(result) {
                    console.log(result.msg);
                },
                error: function(data) {
                    console.log(data);
                }
            });
        }

        function getPhone(data, phone) {
            let formData = {
                content: mobileText,
                type: \'mobile\'
            };
            $.ajax({
                contentType: "application/json;charset=UTF-8",
                url: "/services/promo/decode/content",
                dataType: \'json\',
                type: "post",
                data: JSON.stringify(formData),
                success: function(result) {
                    mobile = result.bean;
                    console.log(result.bean);
                },
                error: function(data) {
                    console.log(data);
                }
            });
        }

    </script>
</head>
<body>
    <div class="container-fluid content">
        <div class="row">
            <div class="panel panel-default">
                <div class="panel-body">
                    <div class="col-sm-12">
                        <label class="col-md-12 control-label" for="password-input">呼叫</label>
                        <input type="text" class="form-control" id="Phone" disabled />
                    </div>
                </div>
                <div class="panel-body" style="text-align:center;">
                    <a class="btn btn-primary" onclick="call()">呼叫</a>
                    <a class="btn btn-danger" onclick="hangup()">挂断</a>
                    <!-- <a class="btn btn-success" onclick="answer()">接听</a>
                    <a class="btn btn-warning" onclick="commit()">话后提交</a> -->

                </div>
            </div>
        </div>

    </div>
</body>
</html>

以上是关于打电话的主要内容,如果未能解决你的问题,请参考以下文章

Android代码片段

Android开发常用代码片段

如何重新附加片段(片段未附加到活动 Kotlin)

firebase 的短信代码不匹配

如何从静态片段中显示Admob插页式广告?

Android:在片段中显示列表