字符串字数检测及支付秘钥生成

之前有一次,因为微信支付秘钥长度问题,一直导致支付对接不上,最后专门自己写了一个字符串长度检测及生成的,供大家参考下,做了防止f12进入开发调试及复制操作,需要的直接复制即可。

<!DOCTYPE html>
<html>
<head>
	<title>字符串位数检测及随机数生成</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width">
	<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
	<style type="text/css">
		*{
			margin:0;
			padding: 0;
			border: 0;
		}
		body,html{
			max-width: 750px;
			margin: 5rem auto 0;
		}
		.txt,#sub,#sub1{
			display:block;
			float: left;
			height: 50px;
			line-height: 50px;
			border: 1px solid red;
			box-sizing: border-box;
			margin-bottom: 15px;
		}
		.txt{
			width: 75%;
			margin-left: 2.5%;
			padding-left:5%;
			border-right:none;
			border-bottom-left-radius:20px;
			border-top-left-radius: 20px; 			
		}
		#sub,#sub1{
			width: 20%;
			text-align: center;
			border-bottom-right-radius:20px;
			border-top-right-radius: 20px;
			background-color: red;
			color: #fff;
			cursor: pointer; 	
		}
	</style>
</head>
<body>
	<input placeholder="请输入字符串并点确定" class="txt" id="txt"/>
	<span id="sub" onclick="sub()">确定</span>
	<input placeholder="点击生成将生成32位随机数" class="txt" id="txt1" disabled="disabled"/>
	<span id="sub1" onclick="sub1(32)">生成</span>
</body>
<script type="text/javascript">
	var txt = document.getElementById('txt');
	function sub(){
		if(!txt.value.length){
			alert('请输入字符串');
		}else{
			alert(txt.value.length);
		}
		
	};
	function sub1(n) {
      var chars = ['0','1','2','3','4','5','6','7','8','9',
                  'a','B','b','c','E','f','G','H','i','J','k','l','M',
                  'N','O','P','q','R','s','T','u','V','W','x','Y','z'];
      var res = "";
      for(var i = 0; i < n ; i++) {
         var id = Math.floor(Math.random()*36);
         res += chars[id];
      }
      document.getElementById('txt1').value=res;
    }
	//江湖中人2022年5月5日22:13:51 屏蔽右键-不包含IE浏览器
	document.oncontextmenu = function (event){
	    if(window.event){
	    event = window.event;
	    }
	    try{
	    var the = event.srcElement;
	        if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
	        return false;
	        }
	        return true;
	    }
	    catch (e){
	        return false;
	    }
	};
	// 江湖中人2022年5月5日22:13:42屏蔽f12-不包含IE浏览器
	window.onkeydown = window.onkeyup = window.onkeypress = function (event) {
    if (event.keyCode == 123) {
	    event.preventDefault(); // 阻止默认事件行为
	    window.event.returnValue = false;
	    }
	}
</script>
</html>
  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值