let displayStatus = true, user = "", userId = "", userSig = "", encryptKey = "", SDKAppID = "", serviceList = []; // 切换列表显示隐藏 $(".contact").click(function () { if (displayStatus) { getServiceList(); $(".contact").animate({ right: "-0px" }, 300); displayStatus = false; } else { $(".contact").animate({ right: "-190" }, 300); displayStatus = true; } }); // 获取客服列表 function getServiceList() { if (serviceList.length) { return; } $.ajax({ url: "buss/bussModel_exeFunc.ms?funcMId=11da3c933d1143d7974bbc4249755c05&FUNC_CODE=F_491b9b4ca864418897012247939b7edf", type: "get", dataType: "json", success: function (data) { encryptKey = data.ajaxMap.ntalk_encrypt_key; SDKAppID = data.ajaxMap.ntalk_sdk_app_id; serviceList = data.ajaxMap.list; renderService(serviceList); }, error: function (err) { utilsFp.confirmIcon(3, "", "", "", err.msg, "", "300", "145"); }, }); } // 渲染客服列表 function renderService(list) { var html = ""; list.forEach((item) => { html += '
' + item.NICK_NAME + "
"; }); $(".contact-list").html(html); } // 加密 function aesEncrypt(word) { let text = CryptoJS.enc.Utf8.parse(word); let key = CryptoJS.enc.Utf8.parse(encryptKey); // 加密模式为ECB,补码方式为PKCS5Padding(也就是PKCS7) let encrypted = CryptoJS.AES.encrypt(text, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7, }); // 返回base64 return CryptoJS.enc.Base64.stringify(encrypted.ciphertext); } // 根据时间戳生成随机数 function randomDigit() { let date = Date.now(); let rund = Math.ceil(Math.random() * 1000); let id = date + "" + rund; return id; } // 获取临时用户 function getTempUser() { user = localStorage.getItem("tempUser"); if (!user) { localStorage.setItem("tempUser", "TEMP_" + randomDigit()); user = localStorage.getItem("tempUser"); } var privateChatId = $(event.currentTarget).attr("data-chatid"); if (userId && userSig) { toChat(userId, userSig, privateChatId); return; } var userData = aesEncrypt(user); $.ajax({ url: getUserSignature() + "/rest/v1/chat/imRestApi/getUserSigByTemp?userData=" + userData, type: "GET", dataType: "json", success: function (res) { if (res.code == "0000001") { userId = res.data.morewisNumber; userSig = res.data.userSig; toChat(userId, userSig, privateChatId); } else { utilsFp.confirmIcon(1, "", "", "", res.msg, "", "300", "145"); } }, error: function (err) { utilsFp.confirmIcon(3, "", "", "", err.msg, "", "300", "145"); }, }); } // 聊天窗口 function toChat(userId, userSig, privateChatId) { initTimModule.getTimExample({ SDKAppID, // 接入腾讯云的SDK ID,联系我们获得 userId, // 登录用户ID,即摩尔号 userSig, // 用户签名串,通过接口获得 privateChatId, // 需要发起对话的目标用户ID timPosition: 5, // 组件初始化位置:1居中,2左上,3左下,4右上,5右下;默认5 baseHead_url: "./buss/reso/mlabel/", // 资源文件路径 }); }