1.下载源码保存本地 并引入
https://cdn.bootcdn.net/ajax/libs/crypto-js/4.0.0/crypto-js.js
2。 在标签上加入参数
check_phone="<% $v[check_phone]%>" to_type="3" data_call_id="<% $v[call_id]%>" data_msg_id="<% $v[msg_id]%>" data_guest_id="<% $v[guest_id]%>" data_talk_id="<% $v[talk_id]%>"
3.定义参数
var current_dom = null;
var guest_record = '<% $guest_record %>';
var type = '<% $vv %>';
var phone_key = '<% $phone_key %>';
var phone_iv = '<% $phone_iv %>';
var company_id = '<% $company_id %>'
4。 移入移出显示查看
var inphone_hover,inphone_timeout;
$(document).on("mouseenter", ".msg_content>.chat_contents>p>span", function (event) {
var check_phone = $(this).attr("check_phone") ? $(this).attr("check_phone") : $(this).parent().attr("check_phone")
var reg = /([0,1][0-9]{2})(\*\*\*\*)[0-9]{4,6}/
if(!reg.test($(this).text()) || check_phone !=1){
return
}
current_dom = this;
clearTimeout(inphone_timeout);
var e = event || window.event;
var d_left = $(this).offset().left;
var d_top = $(this).offset().top;
var window_height = $(window).height();
var window_width = $(window).width();
if (d_top + 25 > window_height) {
d_top = d_top - 25;
}
if (d_left + 60 > window_width) {
d_left = d_left - 60;
}
inphone_hover = setTimeout(() => {
$(".view_btn")
.css({ left: d_left + "px", top: d_top - 30 + "px" })
.show()
.html(`<p class='phone_p' onclick="to_view()">查看</p >`);
}, 100);
});
$(document).on("mouseenter",".view_btn",function(){
clearTimeout(inphone_timeout);
clearTimeout(inphone_hover);
//$('.view_btn').show()
})
$(document).on("mouseleave",".view_btn",function(){
clearTimeout(inphone_timeout);
clearTimeout(inphone_hover);
$('.view_btn').hide()
})
$(document).on("mouseleave", ".msg_content>.chat_contents>p>span", function () {
clearTimeout(inphone_hover);
var reg = /([0,1][0-9]{2})(\*\*\*\*)[0-9]{4,6}/
if(!reg.test($(this).text()) || $(this).attr("check_phone") !=1){
return
}
inphone_timeout = setTimeout(() => {
if ($(".view_btn").is(":visible")) {
$(".view_btn").hide();
}
}, 500);
});
5.点击查看
//点击查看
function to_view(){
//console.log($(current_dom).parents('.fangkemsg').attr('data_guest_id'));
var word;
if(type == 1 || type == 3){
word = company_id.substring(0,6) + parseInt(new Date().getTime()/1000) + $(current_dom).parent().attr('data_guest_id').substring(0,6);
}else{
word = $(current_dom).parent().attr('data_guest_id').substring(0,6) + parseInt(new Date().getTime()/1000) + company_id.substring(0,6);
}
var data = {
guest_record: guest_record,
vv: encryption(word,phone_key,phone_iv,type),
arg: arg,
from: "kfxt",
from_detail: "客服系统后台聊天记录",
type: $(current_dom).parent().attr('to_type'),
guest_id: $(current_dom).parent().attr('data_guest_id'),
msg_id: $(current_dom).parent().attr('data_msg_id'),
call_id: $(current_dom).parent().attr('data_call_id'),
talk_id: $(current_dom).parent().attr('data_talk_id'),
time: parseInt(new Date().getTime()/1000)
}
$.ajax({
url: window.location.origin + '/interface/guest_record_info.php',
type: "post",
data: data,
dataType: "json",
success: function(res){
if(res.code == 200){
if($(current_dom).parent().hasClass("fangkemsg")){
$(current_dom).text(res.msg)
}else{
$(current_dom).parent().html('访客电话: ' + res.msg)
}
}else{
}
}
})
}
6.加密
//加密
function encryption(word, keyStr, ivStr,type){
let key = CryptoJS.enc.Utf8.parse(keyStr);
let iv = CryptoJS.enc.Utf8.parse(ivStr);
let srcs = CryptoJS.enc.Utf8.parse(word);
let encrypted;
//加密方式1或2 走AES加密
if(type == 1||type ==2){
encrypted = CryptoJS.AES.encrypt(srcs, key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
});
//否则走 DES加密
}else{
encrypted = CryptoJS.DES.encrypt(srcs, key, {
iv: iv,
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
});
}
return encrypted.ciphertext.toString();
}