二代身份证读取 中控ID180 二三代身份证阅读器 Vue版本

设备

  • 设备名称:台式身份证阅读机

  • 产品型号:ID180

    • image-20220509232258450
  • 设备驱动和文档

    • 链接:https://pan.baidu.com/s/1nAYkby0smJPSfUcpPVNiLw
      提取码:zhuu

Vue读取身份证信息

  • 得提前安装好上面的驱动、不然无法识别身份证信息
  • 显示效果
  • image-20220509233349894
  • 具体读取代码如下
    /** 读取身份证信息 */
    readCard() {
      // 请求地址
      let url =
        "http://127.0.0.1:24010/ZKIDROnline/ScanReadIdCardInfo?OP-DEV=1&CMD-URL=4&REPEAT=1&common=1&random=1651026716272";

      // 发送请求
      axios({
        url: url,
        method: "get",
        responseType: "json", 
        data: {},
      })
        .then((res) => {
          if (res.data.ret != 0) {
            this.$modal.msgError("读卡失败");
            return;
          }
          let Certificate = res.data.Certificate;
          let form = this.form;  // form表单
          form.name = Certificate.Name; // 姓名
          form.sex = Certificate.Sex == "男" ? 1 : 2; // 性别
          form.nation = Number(Certificate.NationCode); // 民族
          form.birthday = Certificate.Birthday.replace(
            // 出生日期
            /^(\d{4})(\d{2})(\d{2})$/,
            "$1-$2-$3"
          );
          form.identityCard = Certificate.IDNumber; // 身份证号码
          form.issuedOrg = Certificate.IDIssued; // 签发机关
          form.issuedDate = Certificate.IssuedData.replace( // 签发日期
            /^(\d{4})(\d{2})(\d{2})$/,
            "$1-$2-$3"
          );
          let Address = Certificate.Address; // 地址
          form.birthAddress = Address;
          form.householdAddress = Address;
          var nativePlaceReg = /.+?(省|市|自治区|自治州|县|区)/g; // 匹配籍贯
          form.nativePlace = Address.match(nativePlaceReg).toString(); 
          form.issuedValidDate = Certificate.ValidDate.replace(
            /^(\d{4})(\d{2})(\d{2})$/,
            "$1-$2-$3"
          );
          // 获取64位图片 (身份证上的照片)
          let Base64Photo = "data:image/png;base64," + Certificate.Base64Photo; 
           // 将base64图片转为文件类型
          let fileImg = this.base64ToFile(Base64Photo, "avatar");
          // 上传图片文件到服务器
          this.uploadFile(fileImg);
          this.form = form;
        })
        .catch((error) => {
          console.log(error);
        });
    },
    /** 文件上传 */
    uploadFile(file) {
      let formData = new FormData();
      formData.append("file", file);
      uploadImg(formData).then((res) => {
        this.form.avatar = res.url;
      });
    },
    /** base64图片转文件 */
    base64ToFile(urlData, fileName) {
      let arr = urlData.split(",");
      let mime = arr[0].match(/:(.*?);/)[1];
      let bytes = atob(arr[1]); // 解码base64
      let n = bytes.length;
      let ia = new Uint8Array(n);
      while (n--) {
        ia[n] = bytes.charCodeAt(n);
      }
      return new File([ia], fileName, { type: mime });
    },
Logo

前往低代码交流专区

更多推荐