<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FM1208CPU卡读写DEMO</title>
<script language="javascript">
var iswsrun = false;
var ws;
var received_msg = "";
var mytimer;
var strls = "";
var errorno = "";
var wsUri = "ws://127.0.0.1:39189"; //端口号必须与RFIDWebServer端口一致
function isUIntNum(val) {
var testval = /^\d+$/; // 非负整数
return (testval.test(val));
}
function isHex(val) {
var testval = /^(\d|[A-F]|[a-f])+$/; // 十六进制数
return (testval.test(val));
}
function ButtonDisable() { //删除按键的 onclick 事件,防止重复执行指令
document.getElementById("butt_beep").setAttribute("onclick", null);
document.getElementById("butt_getdevnum").setAttribute("onclick", null);
document.getElementById("butt_request").setAttribute("onclick", null);
document.getElementById("butt_cpu_init").setAttribute("onclick", null);
document.getElementById("butt_cpu_fileadd_s").setAttribute("onclick", null);
document.getElementById("butt_cpu_filekeychg").setAttribute("onclick", null);
document.getElementById("butt_readfile").setAttribute("onclick", null);
document.getElementById("butt_writefile_s").setAttribute("onclick", null);
document.getElementById("butt_sendapdu").setAttribute("onclick", null);
document.getElementById("butt_calcexauthkey").setAttribute("onclick", null);
}
function beep() { //驱动发卡器响声令
ButtonDisable();
textarea.value = "";
WebSocketRun("pcdbeep,30");
}
function getdevicenumber() { //读取发卡器唯一出厂序号,可以当加密狗使用
ButtonDisable();
textarea.value = "";
WebSocketRun("pcdgetdevicenumber");
}
function cpu_request() { //激活发卡器感应区内的CPU卡,获取CPU卡卡号
ButtonDisable();
textarea.value = "";
carduid.value="";
WebSocketRun("cpurequest,");
}
function cpu_init() { //初始化CPU卡
ButtonDisable();
textarea.value = "";
if (che_clearcard.checked) { //1表示先将卡片清空再初始化,0表示直接初始化
ClearCardYenNo = 1;
}else{ClearCardYenNo = 0}
CardKey = cardkey.value.trim(); //16进制的卡密码,卡密码和文件没有任何关系,卡密码只是用来清空卡,读和写文件是无效的。一般不需要修改
if (!isHex(CardKey) || CardKey.length!=32) {
textarea.value = "卡密钥输入错误,请输入正确的32位16进制卡密钥!";
cardkey.focus();
cardkey.select();
return;
}
KeyLen = CardKey.length/2; //卡密码长度
spacesize = cardspace.value.trim(); //设定本次应用空间大小,单位是字节
var CpuInitComm = "cpursinit," + ClearCardYenNo + "," + CardKey + "," + KeyLen + "," + spacesize;
WebSocketRun(CpuInitComm);
}
function cpu_fileadd_s() { //创建易写文件
ButtonDisable();
textarea.value = "";
FileNo = creatfile.selectedIndex; //取值范围0-5,创建好的文件不能删除,只能重新初始化卡来清除所有文件
ReadKey = readkey0.value.trim(); //16进制的只读密码
if (!isHex(ReadKey) || ReadKey.length!=32) {
textarea.value = "文件只读密钥输入错误,请输入正确的32位16进制文件只读密钥!";
readkey0.focus();
readkey0.select();
return;
}
ReadKeyLen = ReadKey.length/2; //只读密码长度
WriteKey = writekey0.value.trim(); //16进制的读写密码
if (!isHex(WriteKey) || WriteKey.length!=32) {
textarea.value = "文件读写密钥输入错误,请输入正确的32位16进制文件读写密钥!";
writekey0.focus();
writekey0.select();
return;
}
WriteKeyLen = WriteKey.length/2; //读写密码长度
spacesize = creatfilesize.value.trim(); //文件空间大小,要小于初始化时定义的空间,单位是字节
var CpuFileAddComm = "cpursfileadd_s," + FileNo + "," + ReadKey + "," + ReadKeyLen + "," + WriteKey + "," + WriteKeyLen + "," + spacesize;
WebSocketRun(CpuFileAddComm);
}
function cpu_filekeychg() { //修改文件密钥
ButtonDisable();
textarea.value = "";
FileNo = changkeyfile.selectedIndex; //需要更改密码的文件号,取值范围0-5,
var myctrlword =0;
if (selenewkey.selectedIndex==0){
myctrlword =0; //0 更改CPU卡文件只读密钥
} else {myctrlword =1;} //1 更改CPU卡文件读写密钥
if (changeauthkey.selectedIndex==0){
myctrlword=myctrlword+0; //0 用CPU卡文件只读密码认证
} else {myctrlword=myctrlword+2} //2 用CPU卡文件读写密钥认证
OldKey = authkey0.value.trim(); //16进制的旧密码
if (!isHex(OldKey) || OldKey.length!=32) {
textarea.value = "文件认证密钥输入错误,请输入正确的32位16进制文件认证密钥!";
authkey0.focus();
authkey0.select();
return;
}
OldKeyLen = OldKey.length/2; //旧密码长度
NewKey = newkey.value.trim(); //16进制的新密码
if (!isHex(NewKey) || NewKey.length!=32) {
textarea.value = "文件新密钥输入错误,请输入正确的32位16进制文件新密钥!";
newkey.focus();
newkey.select();
return;
}
NewKeyLen = NewKey.length/2; //新密码长度
var CpuFileKeyChgComm = "cpursfilekeychg," + FileNo + "," + myctrlword + "," + OldKey + "," + OldKeyLen + "," + NewKey + "," + NewKeyLen;
WebSocketRun(CpuFileKeyChgComm);
}
function cpu_filedataread() { //读取文件内数据
ButtonDisable();
textarea.value = "";
rwtext.value="";
FileNo = rwfile.selectedIndex; //需要读取数据的文件号,取值范围0-5,
if (rwauthmode.selectedIndex==0){
myctrlword = 0; //OLDKEYR:0 用CPU卡文件只读密码认证,OLDKEYWR:2 用CPU卡文件读写密码认证
}else {myctrlword = 2;}
FileKey = rwauthkey.value.trim(); //16进制的文件认证密码
if (!isHex(FileKey) || FileKey.length!=32) {
textarea.value = "文件认证密钥输入错误,请输入正确的32位16进制文件认证密钥!";
rwauthkey.focus();
rwauthkey.select();
return;
}
FileKeyLen = FileKey.length/2; //密码长度
DataStart = rwbegin.value.trim(); //读文件的起始地址
DataLen = rwlen.value.trim(); //读取数据长度
var CpuFileDataReadComm = "cpursfiledataread," + FileNo + "," + myctrlword + "," + FileKey + "," + FileKeyLen + "," + DataStart + "," + DataL
WEB浏览器读写NFC、RFID、NDEF智能海报JavaScript源码
需积分: 0 158 浏览量
2024-02-28
08:00:36
上传
评论
收藏 40KB RAR 举报
津津有味道
- 粉丝: 403
- 资源: 173
最新资源
- yolo目标检测项目实验
- downloadFile-1.hc
- Centos7.9环境下离线安装开源版Nginx(亲测版)
- C++课程设计:基于Qt的航班信息管理系统
- ADS7822UVerilog驱动,前面传的有点问题
- 基于python的高性能爬虫程序,使用了多线程+缓存+xpath实现的,这里以彼-岸图库为例,实现,仅用于学习交流
- 中分辨率成像光谱仪(MODIS)烧毁面积产品信息MODIS-C6-BA-User-Guide-1.2.pdf
- Screenshot_20240427_172613_com.huawei.browser.jpg
- 关于学习Python的相关资源网站链接及相关介绍.docx
- (HAL库)基于STM32F103C8T6的温控PID系统[Dht11、ESP8266、无线透传、L298N……]
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈