var produceMessage = function (functionName, Result) {
    console.log(functionName)
}
var device = {
    getIDCard: function (obj) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=2";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: {
                        name: data.username,
                        sex: data.sex,
                        nationality: data.Nation,
                        birthday: data.Born,
                        address: data.address,
                        idcard: data.idcardno,
                        issue: data.GrantDept,
                        startDate: data.UserLifeBegin,
                        endDate: data.UserLifeEnd,
                        pic: data.PhotoBase64String
                    }
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: {}
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, {}, onConnect);
    },
    closeIDCard: function (obj) {
        var url = "http://127.0.0.1/GetHardWareInfo?GetType=2";
        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onCloseIdCard(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: {
                        name: data.username,
                        sex: data.sex,
                        nationality: data.Nation,
                        birthday: data.Born,
                        address: data.address,
                        idcard: data.idcardno,
                        issue: data.GrantDept,
                        startDate: data.UserLifeBegin,
                        endDate: data.UserLifeEnd,
                        pic: data.PhotoBase64String
                    }
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: '00001',
                    message: data.message,
                    ok: false,
                    data: {}
                }
                obj.fail(info);
            }
        }
        callServer(url, {}, onCloseIdCard);
    },
    getNetworkAddr: function (obj) {
        var url = "http://127.0.0.1:8081/GetNetworkAddress";
        if (obj.success == null) {
            obj.success = function () {

            }
        }
        if (obj.fail == null) {
            obj.fail = function () {
            }
        }
        if (obj.complete == null) {
            obj.complete = function () {
            }
        }
        function onEvent(res) {
            var data = JSON.parse(res);
            if (data.ok) {
                obj.success(res);
            }
            else {
                obj.fail(res);
            }
        }
        callServer(url, onEvent);
    },
    voiceBroadcast: function (obj) {
        var url = "http://127.0.0.1:8081/VoiceBroadcast?word=" + encodeURI(obj.word);
        if (obj.success == null) {
            obj.success = function () {

            }
        }
        if (obj.fail == null) {
            obj.fail = function () {
            }
        }
        if (obj.complete == null) {
            obj.complete = function () {
            }
        }
        function onEvent(res) {
            var data = JSON.parse(res);
            if (data.ok) {
                obj.success(res);
            }
            else {
                obj.fail(res);
            }
        }
        callServer(url, onEvent);
    },
    // 获取高拍照片
    // getHighCamera: function (obj) {
    //     var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=3";

    //     if (obj.success == null) {
    //         obj.success = function () {

    //         }
    //     }

    //     if (obj.fail == null) {
    //         obj.fail = function () {
    //         }
    //     }

    //     if (obj.complete == null) {
    //         obj.complete = function () {
    //         }
    //     }

    //     function onConnect(res) {
    //         var data = JSON.parse(res);
    //         if (data.status === '1') {
    //             var printerArr = []
    //             for(var i=0;i<data.filelist.length;++i){
    //                 printerArr.push({filename:data.filelist[i].filename,file:data.filelist[i].Base64String})
    //             }
    //             var info = {
    //                 code:'00000',
    //                 message:'OK',
    //                 ok:true,
    //                 data:printerArr
    //             }
    //             obj.success(info);
    //         }
    //         else {
    //             var info = {
    //                 code:data.status,
    //                 message:data.message,
    //                 ok:false,
    //                 data:[]
    //             }
    //             obj.fail(info);
    //         }
    //     }

    //     callServer(openUrl, {}, onConnect);
    // },

    getHighCamera: function (obj) {

        var _this = this;
        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }
        var isCapture = false;//是否允许拍照
        var isfirst = true;//初始化
        switch (obj.type) {
            // 拍照获取图片
            case 1:
                CaptureBase64(0);//0-jpg,1-bmp,2-png,3-tif格式
                break;
            // 初始化高拍仪
            case 0:
                ConnectServer();//连接后台服务
                StartVideo(0); //开启设备
                ChangeVideoDevice(3)
                break;
            // 直接拍照
            default:
                if (isCapture && !isfirst) {
                    _this.lightControl({
                        light: '12',
                        state: '4',
                        success: function () {
                            CaptureBase64(0);//0-jpg,1-bmp,2-png,3-tif格式
                        }
                    })
                    // CaptureBase64(0);//0-jpg,1-bmp,2-png,3-tif格式
                    return;
                }
                // GetDeviceInfo()
                ConnectServer();//连接后台服务
                StartVideo(0); //开启设备
                ChangeVideoDevice(3)
                break;
        }

        produceMessage = function (functionName, Result) {
            switch (functionName) {
                case 'StartVideo':
                    if (obj.type != undefined) {
                        onConnect(Result)
                    }
                    break;
                case 'ShowVideo':
                    if (obj.type == undefined) {
                        isCapture = true
                        if (isfirst) {
                            setTimeout(function () {
                                _this.lightControl({
                                    light: '12',
                                    state: '4',
                                    success: function () {
                                        CaptureBase64(0);//0-jpg,1-bmp,2-png,3-tif格式
                                    }
                                })
                                // CaptureBase64(0);//0-jpg,1-bmp,2-png,3-tif格式
                            }, 1000)
                            isfirst = false
                        }
                        return
                    } else {
                        try {
                            var myimg = document.getElementById("pic");
                            myimg.src = "data:image/jpeg;base64," + Result;
                        } catch (error) {
                            console.log(error)
                        }
                    }
                    break;
                case 'CaptureBase64':
                    // 拍照成功关灯
                    try {
                        // _this.lightControl({
                        //     light:'12',
                        //     state:'2'
                        // })
                    } catch (error) {
                        console.log(error)
                    }
                    onConnect(Result, 'CaptureBase64')


                    break;
            }
        }

        function onConnect(res, type) {
            var info = {
                code: '00000',
                message: 'OK',
                ok: true,
                data: res
            }
            if (type == 'CaptureBase64') {
                info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: {
                        filename: Math.random() + '.jpg',
                        file: res
                    }
                }
            }
            obj.success(info);
        }
    },


    // 关闭高拍仪
    closeHighCamera: function (obj) {
        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        Stop()
        onConnect()

        function onConnect(res) {
            var info = {
                code: '00000',
                message: 'OK',
                ok: true,
                data: res || ''
            }
            obj.success(info);
        }
    },

    // 摄像头
    getVideoCamera: function (obj) {


        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        switch (obj.type) {
            // 拍照获取图片
            case 1:
                CaptureBase64(0);//0-jpg,1-bmp,2-png,3-tif格式
                break;
            default:
                ConnectServer();//连接后台服务
                StartVideo(1); //开启设备
                break;
        }

        produceMessage = function (functionName, Result) {

            switch (functionName) {
                case 'StartVideo':
                    onConnect(Result, 'StartVideo')
                    break;
                case 'ShowVideo':
                    try {
                        var myimg = document.getElementById("pic1");
                        myimg.src = "data:image/jpeg;base64," + Result;
                    } catch (error) { }
                    onConnect(Result, 'ShowVideo')
                    break;
                case 'CaptureBase64':
                    onConnect(Result, 'CaptureBase64')
                    break;
            }
        }

        function onConnect(res, type) {
            var info = {
                code: '00000',
                message: type,
                ok: true,
                data: res
            }
            if (type == 'CaptureBase64') {
                info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: {
                        filename: "",
                        file: res
                    }
                }
            }
            obj.success(info);
        }
    },
    // 关闭摄像头
    closeVideoCamera: function (obj) {


        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        Stop()
        onConnect()

        function onConnect(res) {
            var info = {
                code: '00000',
                message: 'OK',
                ok: true,
                data: res || ''
            }
            obj.success(info);
        }
    },

    // 双目摄像头
    getDoubleCamera: function (obj) {
        Stop()

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }
        // 活体检测
        StartLiveDetect(5);

        produceMessage = function (functionName, Result) {
            switch (functionName) {
                case 'StartVideo':
                    onConnect(Result, 'StartVideo')
                    break;
                case 'ShowVideo':
                    var myimg = document.getElementById("pic1");
                    myimg.src = "data:image/jpeg;base64," + Result;
                    break;
                // 单目
                case 'StartLiveDetectSingle':
                    onConnect(Result, 'StartLiveDetectSingle')
                    break;
                // 双目
                case 'StartLiveDetect':
                    onConnect(Result, 'StartLiveDetect')
                    break;
                case 'CaptureBase64':
                    onConnect(Result, 'CaptureBase64')
                    break;
            }
        }

        function onConnect(res, type) {
            var info = {
                code: '00001',
                message: type,
                ok: false,
                data: res
            }
            if (type == 'StartLiveDetect' && res === 1) {
                // 活体检测成功拍照
                CaptureBase64(0);//0-jpg,1-bmp,2-png,3-tif格式
            }
            // 拍照成功后返回文件流
            if (type == 'CaptureBase64') {
                info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: {
                        filenameIr: Math.random() + '.jpg',
                        fileIr: res
                    }
                }
            }
            obj.success(info);
        }
    },

    // 关闭双目摄像头
    closeDoubleCamera: function (obj) {


        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        Stop()
        onConnect()

        function onConnect(res) {
            var info = {
                code: '00000',
                message: 'OK',
                ok: true,
                data: res || ''
            }
            obj.success(info);
        }
    },


    getPrinterList: function (obj) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=73";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var printerArr = []
                for (var i = 0; i < data.PrinterList.length; ++i) {
                    printerArr.push({ printerName: data.PrinterList[i].pinter })
                }
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: printerArr
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: []
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, {}, onConnect);
    },
    // 打印文件
    printer: function (obj) {
        var fileType = ""
        if (obj.fileType == 'jpg') {
            fileType = 'data:image/jpg;base64,'
        } else if (obj.fileType == 'pdf') {
            fileType = 'data:application/pdf;base64,'
        }
        var PrinterJson = {
            papertype: obj.papertype || "ticket",    //PrinterJson中增加papertype参数，为空则按以前逻辑处理，为ticket、A3、A4
            printername: obj.printerName,
            printerpaperwidth: "0",
            printertype: obj.printertype || 'base64',//图片格式：jpg，PDF格式：pdf，OFD格式：ofd
            base64: (fileType + obj.fileData) || '',
            contents: obj.contents,
        }
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=71";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: ''
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, { PrinterJson: JSON.stringify(PrinterJson) }, onConnect);
    },
    // 获取打印队列
    getPrintQueue: function (obj) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=74";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var printerArr = []
                for (var i = 0; i < data.QueueList.length; ++i) {
                    printerArr.push({ queue: data.QueueList[i].queueName })
                }
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: printerArr
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: []
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, { printerName: obj.printerName || '' }, onConnect);
    },
    // 设备网络地址
    getNetworkAddr: function (obj) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=888";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: data.data
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: {}
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, {}, onConnect);
    },
    // 播放声音
    voiceBroadcast: function (obj) {
        var jsonString = {
            text: obj.word || '',
            appid: obj.appid || '',
            voice_name: obj.voice_name || '',
            speed: obj.speed || '',
            volume: obj.volume || '',
        }
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=777";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: ''
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, { TextToViceJson: JSON.stringify(jsonString) }, onConnect);
    },
    // 键盘输入
    openKeyboard: function (obj) {
        var model = ""
        if (obj.type == 'string') {
            model = 'mode(py26)'
        } else {
            model = obj.type ? 'mode(' + obj.type + ')' : 'mode(py26)'
        }
        var openUrl = "http://127.0.0.1:1606/show/" + model;

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            // var data = res;
            // if (data.mode === 'ok') {
            //     var info = {
            //         code:'00000',
            //         message:'OK',
            //         ok:true,
            //         data:''
            //     }
            //     obj.success(info);
            // }
            // else {
            //     var info = {
            //         code:data.status,
            //         message:data.message,
            //         ok:false,
            //         data:''
            //     }
            //     obj.fail(info);
            // }
            var info = {
                code: '00000',
                message: 'OK',
                ok: true,
                data: ''
            }
            obj.success(info);
        }

        var info = {
            code: '00000',
            message: 'OK',
            ok: true,
            data: ''
        }
        obj.success(info);

        callServer(openUrl, {}, onConnect);
    },
    // 关闭键盘输入
    closeKeyboard: function (obj) {
        var openUrl = "http://127.0.0.1:1606/hide/";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = res;
            // if (data.mode === 'ok') {
            //     var info = {
            //         code:'00000',
            //         message:'OK',
            //         ok:true,
            //         data:''
            //     }
            //     obj.success(info);
            // }
            // else {
            //     var info = {
            //         code:data.status,
            //         message:data.message,
            //         ok:false,
            //         data:''
            //     }
            //     obj.fail(info);
            // }
            var info = {
                code: '00000',
                message: 'OK',
                ok: true,
                data: ''
            }
            obj.success(info);
        }



        callServer(openUrl, {}, onConnect);
    },
    // 控制灯光
    lightControl: function (obj) {
        var JonsString = {
            "device": "",
            "status": "open",
        }
        switch (obj.light) {
            // 编号 1 社保卡 2 身份证 3 打印机 4 高拍仪绿灯 5 高拍仪红灯 6 证照打印机绿灯 7 证照打印机红灯 8 A4打印机绿灯 9 A4打印机红灯 10 社保卡绿灯 11 社保卡红灯 12 p21高拍仪补光灯 13 p22高拍仪补光灯 14 蜂鸣器  15小票打印机绿灯 16小票打印机红灯
            case '1':
                JonsString.device = 'scardgreen'
                break;
            case '2':
                JonsString.device = 'scardgreen'
                break;
            case '3':
                JonsString.device = 'A4green'
                break;
            case '4':
                JonsString.device = 'docphotogreen'
                break;
            case '5':
                JonsString.device = 'docphotored'
                break;
            case '6':
                JonsString.device = 'certificatgreen'
                break;
            case '7':
                JonsString.device = 'certificatred'
                break;
            case '8':
                JonsString.device = 'A4green'
                break;
            case '9':
                JonsString.device = 'A4red'
                break;
            case '10':
                JonsString.device = 'scardgreen'
                break;
            case '11':
                JonsString.device = 'scardred'
                break;
            case '12':
                JonsString.device = 'p21'
                break;
            case '13':
                JonsString.device = 'p22'
                break;
            case '14':
                JonsString.device = 'bee'
                break;
            case '15':
                JonsString.device = 'ticketgreen'
                break;
            case '16':
                JonsString.device = 'ticketred'
                break;
            case '-1':
                JonsString.device = 'all'
                break;
        }
        switch (obj.state) {
            // 状态 0 常亮 1 闪烁 2 关闭 3一秒闪烁 4两秒闪烁 5零点五秒闪烁
            case '0':
                JonsString.status = 'open'
                break;
            case '1':
                JonsString.status = 'flash'
                break;
            case '2':
                JonsString.status = 'close'
                break;
            case '3':
                JonsString.status = 'flash'
                break;
            case '4':
                JonsString.status = 'flash_slow'
                break;
            case '5':
                JonsString.status = 'flash_fast'
                break;
        }
        var openUrl = "http://192.168.0.249/GetHardWareInfo?GetType=43";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: ''
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, { LightJson: JSON.stringify(JonsString) }, onConnect);
    },
    // 关闭灯光
    closeLight: function (obj) {
        var JonsString = {
            "device": "all",
            "status": "close",
        }
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=43";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: ''
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, { LightJson: JSON.stringify(JonsString) }, onConnect);
    },
    // 签名板
    signatureBoard: function (obj) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=55";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: data.data.Base64String
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, {}, onConnect);
    },
    // 指纹
    fingerprint: function (obj) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=61";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: data.data.Base64String
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, {}, onConnect);
    },
    // 打开营业执照
    openBusinessLicense: function (obj) {
        var CallExeJson = {
            "exeName": "D:\\smile\\BusinessLicense\\webbrowser.exe",
            "exePara": "licenseinfo.html 营业执照打印 450 120 1027 768",
            "waitExeClose": "true",
        }
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=998";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: ''
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, { CallExeJson: JSON.stringify(CallExeJson) }, onConnect);
    },
    // 调用应用程序接口
    callApplicationProgram: function (obj, params) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=998";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: ''
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, { CallExeJson: JSON.stringify(params) }, onConnect);
    },

    // 隐藏任务栏接口
    hiddenTaskbar: function (obj) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=801";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: ''
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, {}, onConnect);
    },

    // 显示任务栏接口
    showTaskbar: function (obj) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=802";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: ''
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, {}, onConnect);
    },
    // 隐藏桌面接口
    hiddenDesktop: function (obj) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=803";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: ''
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, {}, onConnect);
    },
    // 显示桌面接口
    showDesktop: function (obj) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=804";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: ''
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, {}, onConnect);
    },
    // 隐藏任务管理器接口
    hiddenTaskManager: function (obj) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=805";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: ''
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, {}, onConnect);
    },
    // 显示任务管理器接口
    showTaskManager: function (obj) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=806";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: ''
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, {}, onConnect);
    },
    // 屏蔽系统按键
    shieldKey: function (obj) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=807";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: ''
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, {}, onConnect);
    },
    // 允许系统按键
    allowKey: function (obj) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=808";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: ''
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, {}, onConnect);
    },
    // 屏幕截图
    screenCapture: function (obj) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=809";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: ''
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, {}, onConnect);
    },
    // 人脸识别
    faceIdentification: function (obj, params) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=666";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: ''
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, { ArcFaceJson: JSON.stringify(params) }, onConnect);
    },
    // 二维码扫码
    QrCodeScanning: function (obj, params) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=62";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: ''
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, { QrcodeScanJson: JSON.stringify(params) }, onConnect);
    },
    // 取件柜锁控
    cabinetLock: function (obj, params) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=63";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: ''
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, { LockDoorJson: JSON.stringify(params) }, onConnect);
    },
    // 实体社保卡
    stSbcard: function (obj, params) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=22";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);

            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: data
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, { SbcardJson: JSON.stringify(params) }, onConnect);
    },
    // 社保卡基础信息
    SbcradInfo: function (obj) {
        var openUrl = "http://127.0.0.1/GetHardWareInfo?GetType=21";

        if (obj.success == null) {
            obj.success = function () {

            }
        }

        if (obj.fail == null) {
            obj.fail = function () {
            }
        }

        if (obj.complete == null) {
            obj.complete = function () {
            }
        }

        function onConnect(res) {
            var data = JSON.parse(res);
            if (data.status === '1') {
                var info = {
                    code: '00000',
                    message: 'OK',
                    ok: true,
                    data: data
                }
                obj.success(info);
            }
            else {
                var info = {
                    code: data.status,
                    message: data.message,
                    ok: false,
                    data: ''
                }
                obj.fail(info);
            }
        }

        callServer(openUrl, {}, onConnect);
    },
}

// 关闭视频
function Stop() {
    StopVideo();
}

function GetDeviceInfo() {
    GetVideoDevices();//获取视频设备列表
    SetSavePath("c:\\456");//设置图像保存路径，当采用文件方式拍照时必须设置，base64方式非必须设置
    SetJPGQuality(70);//jpg格式时有效
    SetColorType("彩色");//指定图像色彩模式，“彩色”、“灰度”、“黑白”三个选项
    //SetWaterMark("这是测试水印", "宋体", 5, 150, 255, 128, 0, 0, 0.5, 1);
    SetBoardColor(0);//1灰色底板机型，0或其他值为黑色底板机型
}



function callServer(url, data, func) {

    var options = new Object();
    options.type = "POST";
    options.url = url;
    options.timeout = 500000000000;
    options.onSuccess = func;
    options.data = data;
    ajax(options);
}

function ajax(options) {
    if (options.type == null) {
        options.type = "GET";
    }

    if (options.url == null) {
        options.url = "";
    }

    if (options.timeout == null) {
        options.timeout = 5000;
    }

    if (options.onComplate == null) {
        options.onComplate = function () {

        }
    }

    if (options.onError == null) {
        options.onError = function () {
        }
    }

    if (options.onSuccess == null) {
        options.onSuccess = function () {
        }
    }

    if (options.data) {
        var formData = new FormData();
        for (var key in options.data) {
            formData.append(key, options.data[key]);
        }
        options.data = formData;
    }

    var xml;
    if (typeof ActiveXObject != 'undefined') {
        var aVersions = ["Microsoft.XMLHTTP", "Msxml2.XMLHttp.6.0", "Msxml2.XMLHttp.5.0", "Msxml2.XMLHttp.4.0", "Msxml2.XMLHttp.3.0"];
        for (var i = 0; i < aVersions.length; i++) {
            try {
                xml = new ActiveXObject(aVersions[i]);
            } catch (e) { }
        }
    } else if (typeof XMLHttpRequest != 'undefined') {
        xml = new XMLHttpRequest();
    }

    xml.open(options.type, options.url, true);

    var timeoutLength = options.timeout;

    var requestDone = false;

    setTimeout(function () {
        requestDone = true;
    }, timeoutLength);

    xml.onreadystatechange = function () {

        if (xml.readyState == 4 && !requestDone) {
            if (httpSuccess(xml)) {

                options.onSuccess(httpData(xml));
            }

            else {
                options.onError();
            }

            options.onComplate();

            xml = null;
        }
    };

    xml.send(options.data);

    function httpSuccess(r) {
        try {
            return !r.status && location.protocol == "file:"
                ||
                (r.status >= 200 && r.status <= 300)
                ||
                r.status == 304
                ||

                navigator.userAgent.indexOf("Safari") >= 0
                && typeof r.status == "undefined";
        } catch (e) {
        }
        return false;
    }

    function httpData(r) {
        //var ct = r.getResponseHeader("responseType");
        //alert(r.responseXML);
        //alert(r.responseText);

        var ct = r.getResponseHeader("Content-Type");
        //alert(ct);

        if (ct) {
            if (ct == "script") {
                eval.call(window, data);
            }
            if (ct == "xml") {
                return r.responseXML;
            }
            if (ct == "json") {
                return JSON.parse(r.responseText);
            }
        }
        return r.responseText;
    }
}


// 紫图服务
var url = "ws://127.0.0.1:8341";
var websocket;
var connected = false;

//初始化WebSocket连接
function ConnectServer(callback, value) {
    if ('WebSocket' in window) {
        websocket = new WebSocket(url);
    }
    else if (window.WebSocket) {
        websocket = new WebSocket(url);
    }
    else if ('MozWebSocket' in window) {
        websocket = new MozWebSocket(url);
    }
    else {
        alert("浏览器版本太低！请使用Chrome、Firefox、IE10+浏览器！");
    }

    websocket.onopen = function () {
        connected = true;
        callback && callback(value);
    }
    websocket.onclose = function (e) {
        connected = false;
        onMessage({ data: JSON.stringify({ FuncName: 'Connect', result: 0 }) });
    }
    websocket.onmessage = function (e) {
        onMessage(e);
    }
    websocket.onerror = function (e) {
        //if (websocket.readyState != WebSocket.OPEN||websocket.readyState == WebSocket.CLOSED) {
        //    onMessage({ data: JSON.stringify({ FuncName: 'Connect', result: 0 }) });
        //}
    };
}

//接收服务器发送的信息
function onMessage(event) {
    try {
        if (typeof (event.data) == "string") {
            var str = event.data;
            var jsonOBJ = JSON.parse(str);
            var name = jsonOBJ.FuncName;
            var re = jsonOBJ.result;
            if (name == "Connect" && re == 1) {
                connected = true;
            }
            produceMessage(name, re);
        }
    } catch (error) {
        // console.log(error)
    }

}

//向服务器发送信息的共享方法
function sendMessage(data) {
    if (websocket.readyState == 0) {
        setTimeout(function () {
            var jsData = JSON.stringify(data);
            websocket.send(jsData);
        }, 50);
    }
    else if (websocket.readyState == 1) {
        var jsData = JSON.stringify(data);
        websocket.send(jsData);
    }
    else {
        alert("未连接websocket服务器，请确保已运行服务端！");
    }
}

/*==============以下是扫描仪功能======================================================*/
//设置保存路径
function SetSavePath(savePath) {
    var data = { "Func": "SetSavePath", "arg": savePath };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}

//设置文件前缀
function SetFilePre(pre) {
    var data = { "Func": "SetFilePre", "arg": pre };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}

//设置Twain源名称
function SetDevice(twainName) {
    var data = { "Func": "SetDevice", "arg": twainName };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//获取所有twain源名称
function GetDeviceList() {
    var data = { "Func": "GetDeviceList", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//设置色彩模式
function SetColorType(colorType) {
    var data = { "Func": "SetColorType", "arg": colorType };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//设置底板颜色
function SetBoardColor(colorType) {
    var data = { "Func": "SetBoardColor", "arg": colorType };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//设置分辨率
function SetDPI(dpi) {
    var data = { "Func": "SetDPI", "arg": dpi };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//设置是否弹出twainui
function ShowTwainUI(showUI) {
    var data = { "Func": "ShowTwainUI", "arg": showUI };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}

//设置文件类型
function SetFileType(fileType) {
    var data = { "Func": "SetFileType", "arg": fileType };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}

//设置单双面
function SetDuplex(duplex) {
    var data = { "Func": "SetDuplex", "arg": duplex };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//设置是否传输每一张图像的base64
function SetTransPerPageBase64(trans) {
    var data = { "Func": "SetTransPerPageBase64", "arg": trans };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//设置JPG图片压缩率
function SetJPGQuality(quality) {
    var data = { "Func": "SetJPGQuality", "arg": quality };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//获取扫描仪序列号
function GetScannerSN() {
    var data = { "Func": "GetScannerSN", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//开始扫描
function StartScan(pageNum) {
    var data = { "Func": "StartScan", "arg": pageNum };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//获取本次扫描的文件列表
function GetFilesList() {
    var data = { "Func": "GetFilesList", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//图片转BASE64
function ImageToBase64(filePath) {
    var data = { "Func": "ImageToBase64", "arg": filePath };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//文件转BASE64
function FileToBase64(filePath) {
    var data = { "Func": "FileToBase64", "arg": filePath };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//图片http上传
function httpUpload(serverAddress, filePath, del) {
    var data = { "Func": "httpUpload", "arg": { "serverAddress": serverAddress, "filePath": filePath, "del": del } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//图片ftp上传
function ftpUpload(ftpServerIP, ftpRemotePath, ftpUserID, ftpPassword, filename, del, passive) {
    var data = { "Func": "ftpUpload", "arg": { "ftpServerIP": ftpServerIP, "ftpRemotePath": ftpRemotePath, "ftpUserID": ftpUserID, "ftpPassword": ftpPassword, "filename": filename, "del": del, "passive": passive } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//图片转pdf
function ImagesToPDF(imageList, pdfFile) {
    var data = { "Func": "ImagesToPDF", "arg": { "imageList": imageList, "pdfFile": pdfFile } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//图片转pdf base64方式
function ImagesToPDFBase64(base64Str) {
    var data = { "Func": "ImagesToPDFBase64", "arg": base64Str };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//开始活体检测双目，参数为超时时间，单位秒
function StartLiveDetect(outtime) {
    var data = { "Func": "StartLiveDetect", "arg": outtime };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//开始活体检测单目，参数为超时时间，单位秒
function StartLiveDetectSingle(outtime) {
    var data = { "Func": "StartLiveDetectSingle", "arg": outtime };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//获取指定文件夹下的文件列表
function GetFolderFileListJson(folderPath) {
    var data = { "Func": "GetFolderFileListJson", "arg": folderPath };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}

//删除指定文件夹下的所有文件
function DeleteImagesInFolder(folderPath) {
    var data = { "Func": "DeleteImagesInFolder", "arg": folderPath };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//删除指定文件
function DeleteImage(filePath) {
    var data = { "Func": "DeleteImage", "arg": filePath };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
/*==============以下是读卡\指纹功能======================================================*/

//读身份证
function ReadIDCard() {
    var data = { "Func": "ReadIDCard", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//读二代社保卡
function Read2thSSCard() {
    var data = { "Func": "Read2thSSCard", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//读三代社保卡（PSAM）
function Read3thSSCardBasPSAM(type) {
    var data = { "Func": "Read3thSSCardBasPSAM", "arg": type };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//读三代社保卡步骤1（加密机）
function Read3thSSCardBasHSM1(type) {
    var data = { "Func": "Read3thSSCardBasHSM1", "arg": type };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//读三代社保卡步骤2（加密机）
function Read3thSSCardBasHSM2(key) {
    var data = { "Func": "Read3thSSCardBasHSM2", "arg": key };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//读IC银行卡
function ReadICCard() {
    var data = { "Func": "ReadICCard", "arg": 0 };
    sendMessage(data);
}
//读磁条银行卡
function ReadMagCard() {
    var data = { "Func": "ReadMagCard", "arg": 0 };
    sendMessage(data);
}
//采集指纹-文件方式
function CapFingerFile(fingerPic) {
    var data = { "Func": "CapFingerFile", "arg": fingerPic };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//采集指纹-base64方式
function CapFingerBASE64() {
    var data = { "Func": "CapFingerBASE64", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//比对指纹-文件方式
function MatchFingerByFile(fingerPic1, fingerPic2) {
    var data = { "Func": "MatchFingerByFile", "arg": { "fingerPic1": fingerPic1, "fingerPic2": fingerPic2 } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//比对指纹-base64方式
function MatchFingerByBASE64(fingerPic1, fingerPic2) {
    var data = { "Func": "MatchFingerByBASE64", "arg": { "fingerPic1": fingerPic1, "fingerPic2": fingerPic2 } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//与身份证比对指纹-文件方式
function MatchCardFingerByFile(fingerPic1) {
    var data = { "Func": "MatchCardFingerByFile", "arg": { "fingerPic1": fingerPic1 } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}

//与身份证比对指纹-base64方式
function MatchCardFingerByBase64(fingerBase64) {
    var data = { "Func": "MatchCardFingerByBase64", "arg": fingerBase64 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}

/*==============以下是手写屏功能======================================================*/
//开始签字
function StartSign(title) {
    var data = { "Func": "StartSign", "arg": title };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//开启评价器
function StartEvalute() {
    var data = { "Func": "StartEvalute", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//展示工牌
function StartStaff(headPic, staffName, staffNum, staffStar) {
    var data = { "Func": "StartStaff", "arg": { "headPic": headPic, "staffName": staffName, "staffNum": staffNum, "staffStar": staffStar } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//关闭工牌
function CloseStaff() {
    var data = { "Func": "CloseStaff", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//打开PDF
function OpenPDF(filePath, withSign) {
    var data = { "Func": "OpenPDF", "arg": { "filePath": filePath, "withSign": withSign } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//关闭PDF窗口
function ClosePDF() {
    var data = { "Func": "ClosePDF", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//打开网页
function OpenWebPage(url) {
    var data = { "Func": "OpenWebPage", "arg": url };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//关闭网页
function CloseWebPage() {
    var data = { "Func": "CloseWebPage", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}

/*==============以下是高拍仪功能======================================================*/
function GetVideoDevInfo() {
    var a = { Func: "GetVideoDevInfo", arg: 0 };
    connected ? sendMessage(a) : ConnectServer(sendMessage, a)
}
function CheckLicense() {
    var a = { Func: "CheckLicense", arg: 0 };
    connected ? sendMessage(a) : ConnectServer(sendMessage, a)
}
function GetSpecialFolder(index) {
    var a = { Func: "GetSpecialFolder", arg: index };
    connected ? sendMessage(a) : ConnectServer(sendMessage, a)
}
function GetCurrentResolutionIndex() {
    var a = { Func: "GetCurrentResolutionIndex", arg: 0 };
    connected ? sendMessage(a) : ConnectServer(sendMessage, a)
}
//打开视频窗口
function StartVideo(camIndex) {
    var data = { "Func": "StartVideo", "arg": camIndex };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//打开主头视频窗口
function StartRunMain() {
    var data = { "Func": "StartRunMain", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//打开副头视频窗口
function StartRunSub() {
    var data = { "Func": "StartRunSub", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//按指定PID\VID打开设备
function StartRunByID(vid, pid) {
    var data = { "Func": "StartRunByID", "arg": { "VID": vid, "PID": pid } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
function ZoomIn() {
    var data = { "Func": "ZoomIn", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
function ZoomOut() {
    var data = { "Func": "ZoomOut", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//左旋转
function RotateLeft() {
    var data = { "Func": "RotateLeft", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//右旋转
function RotateRight() {
    var data = {
        "Func": "RotateRight", "arg": 0
    };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//关闭视频窗口
function StopVideo() {
    var data = { "Func": "StopVideo", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//获取视频设备列表
function GetVideoDevices() {
    var data = { "Func": "GetVideoDevices", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//获取音频设备列表
function GetAudioDevices() {
    var data = { "Func": "GetAudioDevices", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//开始录像
function StartRecord(videoIndex, audioIndex, fileName, resolution, fps) {
    var data = { "Func": "StartRecord", "arg": { "videoIndex": videoIndex, "audioIndex": audioIndex, "fileName": fileName, "resolution": resolution, "fps": fps } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//停止录像
function StopRecord() {
    var data = { "Func": "StopRecord", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//切换视频设备
function ChangeVideoDevice(camIndex) {
    var data = { "Func": "ChangeVideoDevice", "arg": camIndex };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//切换视频分辨率
function ChangeVideoResolution(resIndex) {
    var data = { "Func": "ChangeVideoResolution", "arg": resIndex };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//切换裁剪方式
function ChangeCutType(type) {
    var data = { "Func": "ChangeCutType", "arg": type };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//获取高拍仪序列号
function GetVideoDeviceSN() {
    var data = { "Func": "GetVideoDeviceSN", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}

//文件方式拍照
function CaptureFile(fileName) {
    var data = { "Func": "CaptureFile", "arg": fileName };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//base64方式拍照
function CaptureBase64(format) {
    var data = { "Func": "CaptureBase64", "arg": format };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//采集发票二维码
function CaptureTaxQR() {
    var data = { "Func": "CaptureTaxQR", "arg": 0 };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}

//人脸比对
function VerifyFace(face1, face2) {
    var data = { "Func": "VerifyFace", "arg": { "face1": face1, "face2": face2 } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//人脸比对-Base64
function VerifyFaceByBase64(face1, face2) {
    var data = { "Func": "VerifyFaceByBase64", "arg": { "face1": face1, "face2": face2 } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//人脸比对
function VerifyFacePro(face1, face2) {
    var data = { "Func": "VerifyFacePro", "arg": { "face1": face1, "face2": face2 } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//人脸比对-Base64
function VerifyFaceByBase64Pro(face1, face2) {
    var data = { "Func": "VerifyFaceByBase64Pro", "arg": { "face1": face1, "face2": face2 } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//OCR识别文件
function OCRImage(fileName) {
    var data = { "Func": "OCRImage", "arg": fileName };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//OCR识别文件Pro
function OCRImagePro(fileName, txt, json, rtf, pdf) {
    var data = { "Func": "OCRImagePro", "arg": { "fileName": fileName, "txt": txt, "json": json, "rtf": rtf, "pdf": pdf } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//打印图片文件
function PrintImage(fileName) {
    var data = { "Func": "PrintImage", "arg": fileName };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//设置水印
function SetWaterMark(watertext, waterfont, position, fontsize, rvalue, gvalue, bvalue, sapceing, Opacity, open) {
    var data = { "Func": "SetWaterMark", "arg": { "watertext": watertext, "waterfont": waterfont, "position": position, "fontsize": fontsize, "rvalue": rvalue, "gvalue": gvalue, "bvalue": bvalue, "sapceing": sapceing, "Opacity": Opacity, "open": open } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//合并图片
function CombineImages(pic1, pic2, savePic, type) {
    var data = { "Func": "CombineImages", "arg": { "pic1": pic1, "pic2": pic2, "savePic": savePic, "type": type } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//合并图片
function CombineImagesPro(picList, savePic, type) {
    var data = { "Func": "CombineImagesPro", "arg": { "picList": picList, "savePic": savePic, "type": type } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//合并图片-base64
function CombineImagesProByBase64(picList, type) {
    var data = { "Func": "CombineImagesProByBase64", "arg": { "picList": picList, "type": type } };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
//识别二维码、一维码
function GetBarCode(fileName) {
    var data = { "Func": "GetBarCode", "arg": fileName };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}
function GetBarCodeBase64(base64Str) {
    var data = { "Func": "GetBarCodeBase64", "arg": base64Str };
    connected ? sendMessage(data) : ConnectServer(sendMessage, data);
}