vue3实现华视身份证读卡功能

hs_read_card.ts文件

import axios from 'axios'

const sdk: any = new (function () {
  var type = null;
  // 初始化SDK 默认使用华视
  const init_sdk = (qudao = "hs") => {
    type = qudao;
  };

/**
* 链接
*/
const open_device = () => {
  return axios.get("http://localhost:8080/apiProxy/OpenDevicerl")
}

// 读取身份证信息
const read_card = () => {
  return axios.get("http://localhost:8080/apiProxy/readCard")
}

// 断开连接
const close_device = () => {
  return axios.get("http://localhost:8080/apiProxy/CloseDevice")
}

  return { type, init_sdk, close_device, open_device,read_card }
} as any)();

export default sdk;

vue.config.js配置代理跨域

module.exports = {
  publicPath:'/',
  devServer: {
    proxy: {
      '/apiProxy': {
        target: 'http://localhost:19196',
        changeOrigin: true,//用于控制请求头中的host值
        ws: false,
        //真正的服务器没有/api,所以要重写路径置空,否则找不到相应的路径
        pathRewrite: {
          '^/apiProxy': ''
        }
      }
    }
  }
}

页面引入使用

import sdk from '@/api/hs_read_card'

// 连接身份证读卡器
const getOpenDevice = async () => {
  // 调用读取之前调用连接读卡器方法
  const res = await sdk.open_device()
  console.log(res,'身份证连接结果');
  let str = JSON.stringify(res)
  let obj = JSON.parse(str)
  // console.log(obj, '连接身份证结果');
  if (obj.data.resultFlag == 0) {
    console.log('身份证读卡器连接成功');
    // console.log(obj)
  } else {
    console.log('身份证读卡器连接失败')
  }
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

A_ugust__

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值