手机号加密 CryptoJS

本文介绍了如何使用CryptoJS库来实现手机号的加密操作。首先从CDN下载并引入CryptoJS源码,接着定义加密参数,然后在需要的元素上添加触发事件,实现在鼠标移入移出时显示或隐藏加密后的手机号,最后详细阐述了加密过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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();
	  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值