// 美洽客服
(function(m, ei, q, i, a, j, s) {
    m[i] = m[i] || function() {
        (m[i].a = m[i].a || []).push(arguments)
    };
    j = ei.createElement(q),
        s = ei.getElementsByTagName(q)[0];
    j.async = true;
    j.charset = 'UTF-8';
    j.src = 'https://static.meiqia.com/dist/meiqia.js';
    s.parentNode.insertBefore(j, s);
})(window, document, 'script', '_MEIQIA');
// entID dx1
_MEIQIA('entId', 'eac7e92391e5b9b057311d353e411e8f');//dx1
_MEIQIA('withoutBtn');
function mqkf() {
    _MEIQIA('withoutBtn');
    _MEIQIA('init');
    _MEIQIA('showPanel');
}


// live客服
function md5(string) {
    return CryptoJS.MD5(string).toString();
}

function generateSign(userID, userName, timestamp, secret) {
    var stringToSign = `userID=${userID}&userName=${userName}&timestamp=${timestamp}&secret=${secret}`;
    return md5(stringToSign);
}

function livekf() {
    var userID = ''; // 请根据实际情况设置
    var userName = ''; // 请根据实际情况设置
    var timestamp = new Date().toISOString().replace(/[-:.TZ]/g, ''); // 格式化时间
    var secret = 'bd1ea8581a946656448d91c108d9f0e3';//dx1
    var sign = generateSign(userID, userName, timestamp, secret);
    var url = `https://www.agcpdb.republican/Chat/Chat?userID=${userID}&userName=${userName}&timestamp=${timestamp}&sign=${sign}`;

    var iframe = document.createElement('iframe');
    iframe.src = url;
    iframe.style.border = 'none';
    iframe.id = 'kfIframe';

    var closeButton = document.createElement('button');
            closeButton.innerText = '×';
            closeButton.style.zIndex = '1002';
            closeButton.id = 'kfCloseButton';
            closeButton.style.color = 'white';
            closeButton.style.fontWeight = 'bold';
            closeButton.style.border = 'none';
            closeButton.style.padding = '10px 20px';
            closeButton.style.cursor = 'pointer';
            closeButton.style.borderRadius = '5px';
            closeButton.onclick = function() {
                document.body.removeChild(iframe);
                document.body.removeChild(closeButton);
            };

    var isAndroid = /android/i.test(navigator.userAgent);
    var isiOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;

    if (isAndroid || isiOS) {
        iframe.style.position = 'fixed';
        iframe.style.top = '0';
        iframe.style.left = '0';
        iframe.style.width = '100%';
        iframe.style.height = '100%';
        iframe.style.zIndex = '1000';

        closeButton.style.position = 'fixed';
        closeButton.style.top = '10px';
        closeButton.style.left = '10px';
    } else {
        iframe.style.position = 'fixed';
        iframe.style.bottom = '0';
        iframe.style.right = '0';
        iframe.style.width = '500px';
        iframe.style.height = '700px';
        iframe.style.zIndex = '1000';

        closeButton.style.position = 'fixed';
        closeButton.style.top = 'calc(100% - 700px)';
        closeButton.style.left = 'calc(100% - 500px)';
    }

    var existingIframe = document.getElementById('kfIframe');
    if (existingIframe) {
        existingIframe.parentNode.removeChild(existingIframe);
    }
    var existingCloseButton = document.getElementById('kfCloseButton');
    if (existingCloseButton) {
        existingCloseButton.parentNode.removeChild(existingCloseButton);
    }

    document.body.appendChild(iframe);
    document.body.appendChild(closeButton);
}


