function authenticateAndReadBlocks(pwd1, index, flag) {
var cmd = new Int8Array(12);
cmd[0] = 0x60; // 使用 KEY A 进行认证
cmd[1] = parseInt(index) * 4;
// UID 作为一个字节数组传入命令中
for (var j = 0; j < uid_arr.length; j++) {
cmd[j + 2] = uid_arr.charCodeAt(j); // 将字符串形式的 UID 转为字节
}
// 将主密钥转换为字节
for (var k = 0; k < 6; k++) {
cmd[k + 6] = chipTool.hex2int(pwd1.substring(k * 2, k * 2 + 2));
}
mifare.transceive({
data: cmd.buffer,
success: function (res) {
console.log('认证成功, 接收数据如下:', res);
if (flag == 1) {
readDataFromBlocks(index);
} else {
writeMultipleBlocks(index);
}
},
fail: function (err) {
console.log('认证失败', err);
uNotifyRef.value.show({
type: 'error',
color: '#fff',
message: '认证失败',
duration: 1000 * 3,
fontSize: 18,
})
}
});
}