鸿蒙系统使用ArkTS开发语言支持身份证阅读器、社保卡读卡器等调用二次开发SDK

news2025/5/11 17:15:54

har库导入:

{
  "license": "",
  "devDependencies": {},
  "author": "",
  "name": "entry",
  "description": "Please describe the basic information.",
  "main": "",
  "version": "1.0.0",
  "dependencies": {
    "@ohos/DonseeDevice": "file:./src/libs/DonseeDeviceLib.har"
  }
}

导入身份证阅读器相关类:

import CommonContants from '../common/CommonContants';
import DonseeDevice from '@ohos/DonseeDevice/src/main/ets/model/DonseeDevice';
import { IDCardInfor } from '@ohos/DonseeDevice/src/main/ets/model/IDCardInfor';

导入社保卡读卡器相关类:

import CommonContants from '../common/CommonContants';
import DonseeDevice from '@ohos/DonseeDevice/src/main/ets/model/DonseeDevice';
import { IDCardInfor } from '@ohos/DonseeDevice/src/main/ets/model/IDCardInfor';
import { SSCardInfor } from '@ohos/DonseeDevice/src/main/ets/model/SSCardInfor';

身份证阅读器调用相关代码:

import CommonContants from '../common/CommonContants';
import DonseeDevice from '@ohos/DonseeDevice/src/main/ets/model/DonseeDevice';
import { IDCardInfor } from '@ohos/DonseeDevice/src/main/ets/model/IDCardInfor';
/**
 * Card content contains the information list.
 */
@Component
export struct IDCardComponent {
  @State tvResult: string = '';
  @State imgBase64: string = '';
  @State imageVisible: Visibility = Visibility.None;
  @State nType : number =  1;//0,文本信息;1,文本+照片;2,文本+照片+指纹
  @Provide showSelector: boolean = false // 是否展开下拉菜单
  // @Provide modesData: [number,string] = [{id: 1,name: '文本信息'},{id: 2,name: '文本照片'},{id: 3,name: '文本照片指纹'}]
  @Provide modeId: number = 0 // 当前选中项id
  build() {
        Column() {

          Row() {
            Column() {
            Image(this.imgBase64)
              .visibility(this.imageVisible)
              .width(51)
              .height(63)
              .objectFit(ImageFit.Contain)
            Text(this.tvResult)
              .fontSize(10)
              .margin({ top: 2 })

            }
            .layoutWeight(1)
            .margin({left:10})
            .alignItems(HorizontalAlign.Start)
            Column() {
              Column() {
                Row() {
                  Radio({ value: "文本", group: "1234" })
                    .checked(this.nType === 0 ? true : false)
                    .height(20)
                    .width(20)
                    .onClick(() => {
                      this.nType = 0;
                    })
                  Text('文本')

                }.margin({ left: 10 })

                Row() {
                  Radio({ value: "文本照片", group: "1234" })
                    .checked(this.nType === 1 ? true : false)
                    .height(20)
                    .width(20)
                    .onClick(() => {
                      this.nType = 1;
                      console.info("Radio  onClick")
                    })
                  Text('文本照片')

                }.margin({ left: 10 })

                Row() {
                  Radio({ value: "文本照片指纹", group: "1234" })
                    .checked(this.nType === 2 ? true : false)
                    .height(20)
                    .width(20)
                    .onClick(() => {
                      this.nType = 2;
                      console.info("Radio  onClick")
                    })
                  Text('文本照片指纹')

                }.margin({ left: 10 })

              }.justifyContent(FlexAlign.Start)
              .alignItems(HorizontalAlign.Start)
              Button("读身份证")
                .fontSize($r('app.float.submit_button_font_size'))
                .fontWeight(CommonContants.FONT_WEIGHT)
                .height(30)
                .width(120)
                .onClick(() => {
                  let idInfo:IDCardInfor = DonseeDevice.Donsee_ReadIDCard(this.nType)

                    if(idInfo.ENfullnameOther.length>0){
                      idInfo.ENfullname += idInfo.ENfullnameOther
                    }
                    this.tvResult =
                     "中文姓名:"+ idInfo.name+"   "
                    +"英文姓名:"+ idInfo.ENfullname+"\n"
                    +"性    别:"+ idInfo.sex+"      "
                    +"民    族:"+ idInfo.people+"  "
                    +"出生日期:"+ idInfo.birthday+"\n"
                    +"家庭住址:"+ idInfo.address+"\n"
                    +"身份证号:"+ idInfo.number+"\n"
                    +"签发单位:"+ idInfo.organs+"    "
                    +"国籍代码:"+ idInfo.nationality+"\n"
                    +"有效期限:"+ idInfo.signdate+" - "+ idInfo.validterm+"\n"
                    +"证件类别:"+ idInfo.certType+"    "
                    +"证件版本:"+ idInfo.certVersion+"\n"
                    +"通行证号:"+ idInfo.passNu+"    "
                    +"换证次数:"+ idInfo.changCount+"\n"
                    +"签发数次:"+ idInfo.signCount+"     "
                    +"既往版本:"+ idInfo.oldNumber+"\n"
                    +"指纹:"+ idInfo.figData+"\n"
                    if(idInfo.imgBase64.length>0){
                      this.imgBase64 = 'data:image/png;base64,'+idInfo.imgBase64
                      this.imageVisible = Visibility.Visible
                    }else{
                      this.imageVisible = Visibility.None
                    }
                  }else{
                    this.imgBase64 = ''
                    this.tvResult =    "读取失败:"+ idInfo.result
                  }
                }).margin({top:10})
              Button("身份证ID")
                .fontSize($r('app.float.submit_button_font_size'))
                .fontWeight(CommonContants.FONT_WEIGHT)
                .height(30)
                .width(120)
                .onClick(() => {
                  let datas:[number,string] = DonseeDevice.Donsee_ReadIDCardUid()
                  if(datas[0] == 0){
                    this.tvResult =  "Uid:"+ datas[1]
                  }else{
                    this.tvResult =  "Uid读取失败:"+ datas[0]
                  }
                }).margin({top:10})

            }.justifyContent(FlexAlign.End)
            .margin({right:10})
          }.justifyContent(FlexAlign.Start)
          .width(CommonContants.FULL_PARENT)
        }.justifyContent(FlexAlign.Start)
        .backgroundColor($r('app.color.card_background'))
        .width(CommonContants.FULL_PARENT)
        .height(CommonContants.FULL_PARENT)
      }

  // 获取选中项的内容
  // getSelectedText() {
  //   const selectedItem = this.modesData.find(item => {
  //     console.info('this.modeId==='+this.modeId)
  //     console.info('item.id==='+item.id)
  //     return item.id == this.modeId
  //   })
  //   if (selectedItem) {
  //     console.info('selectedItem.name==='+selectedItem.name)
  //     return selectedItem.name
  //   }
  //   return ''
  // }


}

社保卡读卡器相关调用代码:

import CommonContants from '../common/CommonContants';
import DonseeDevice from '@ohos/DonseeDevice/src/main/ets/model/DonseeDevice';
import { IDCardInfor } from '@ohos/DonseeDevice/src/main/ets/model/IDCardInfor';
import { SSCardInfor } from '@ohos/DonseeDevice/src/main/ets/model/SSCardInfor';
import util from '@ohos.util';
/**
 * Card content contains the information list.
 */
@Component
export struct SSCardComponent {
  @State tvResult: string = '';
  @State pKkey: string = '01020304050607080102030405060708|01020304050607080102030405060708|';
  @State slot : number =  0;//卡座
  private textInputController: TextInputController = new TextInputController();
  build() {
        Column() {

          Row() {
            Column() {
              Row() {
                Text("pkey:")
                  .fontSize(18)
                TextInput({ controller: this.textInputController,text:'01020304050607080102030405060708|01020304050607080102030405060708|' })
                  .type(InputType.Normal)
                  .height(32)
                  .margin({ left: $r('app.float.text_input_margin_left') })
                  .layoutWeight(CommonContants.TEXTINPUT_LAYOUT_WEIGHT)
                  .onChange(value => {
                    this.pKkey = value
                  })

              }
            Text(this.tvResult)
              .fontSize(18)
              Text("").layoutWeight(1)
            }
            .layoutWeight(1)
            .margin({left:10})
            .alignItems(HorizontalAlign.Start)
            Column() {
              Column() {
                Row() {
                  Text('SAM卡座选择:')

                }.margin({ left: 10 })

                Row() {
                  Radio({ value: "SCard", group: "3" })
                    .checked(this.slot === 1 ? true : false)
                    .height(20)
                    .width(20)
                    .onClick(() => {
                      this.slot = 1;
                      console.info("Radio  onClick")
                    })
                  Text('SAM1')

                  Radio({ value: "SCard", group: "3" })
                    .checked(this.slot === 2 ? true : false)
                    .height(20)
                    .width(20)
                    .onClick(() => {
                      this.slot = 2;
                      console.info("Radio  onClick")
                    }).margin({ left: 10 })
                  Text('SAM2')

                }.margin({ left: 10 })

                Row() {
                  Radio({ value: "SCard", group: "3" })
                    .checked(this.slot === 3 ? true : false)
                    .height(20)
                    .width(20)
                    .onClick(() => {
                      this.slot = 3;
                      console.info("Radio  onClick")
                    })
                  Text('SAM3')

                  Radio({ value: "SCard", group: "3" })
                    .checked(this.slot === 4 ? true : false)
                    .height(20)
                    .width(20)
                    .onClick(() => {
                      this.slot = 4;
                      console.info("Radio  onClick")
                    }).margin({ left: 10 })
                  Text('SAM4')

                }.margin({ left: 10 })

                Row() {
                  Radio({ value: "SCard", group: "3" })
                    .checked(this.slot === 0 ? true : false)
                    .height(20)
                    .width(20)
                    .onClick(() => {
                      this.slot = 0;
                      console.info("Radio  onClick")
                    }).margin({ left: 15 })
                  Text('无').margin({ left: 10 })
                }

              }.justifyContent(FlexAlign.Start)
              .alignItems(HorizontalAlign.Start)
              Row() {
                Button("读取社保卡")
                  .fontSize($r('app.float.submit_button_font_size'))
                  .fontWeight(CommonContants.FONT_WEIGHT)
                  .height(20)
                  .width(95)
                  .onClick(() => {
                    //nType 1,    有SAM卡返回全部信息   2,    无SAM卡返回卡号
                    let nType:number = 1
                    if (this.slot == 0) {
                      nType = 2
                    }
                    console.info("nType = " + nType)
                    console.info("this.slot = " + this.slot)
                    let ssCardInfor: SSCardInfor = DonseeDevice.Donsee_ReadSSCardPre(this.slot, nType)
                    console.info("ssCardInfor.result = " + ssCardInfor.result)
                    if (ssCardInfor.result == 0) {

                      // const str = new util.TextDecoder('gbk').decode(ssCardInfor.name)
                      // let gbkDecoder = new util.TextDecoder("gbk",{ignoreBOM: true});
                      console.info("ssCardInfor.name = " + ssCardInfor.nation)
                      console.info("ssCardInfor.name = " + ssCardInfor.name)
                      // this.tvResult =    "姓    名:"+ ssCardInfor.name
                      this.tvResult = "姓    名:" + ssCardInfor.name + "\n"
                      + "性    别:" + ssCardInfor.sex + "\n"
                      + "民    族:" + ssCardInfor.nation + "\n"
                      + "出身日期:" + ssCardInfor.birthday + "\n"
                      + "城市代码:" + ssCardInfor.city + "\n"
                      + "身份证号:" + ssCardInfor.idnumber + "\n"
                      + "社保卡号:" + ssCardInfor.cardnumber + "\n"
                      + "开始有效期限:" + ssCardInfor.signdate + "\n"
                      + "结束有效期限:" + ssCardInfor.validterm + "\n"
                      + "社保版本:" + ssCardInfor.cardveVrsion + "\n"
                    } else {
                      this.tvResult = "读卡失败:" + ssCardInfor.result+"\n errMsg = "+ssCardInfor.errMsg.trim()
                    }
                  })

                Button("读基本信息")
                  .fontSize($r('app.float.submit_button_font_size'))
                  .fontWeight(CommonContants.FONT_WEIGHT)
                  .height(20)
                  .width(95)
                  .onClick(() => {
                    let datas:[number, string] = DonseeDevice.Donsee_iReadCardBas(3)
                    if (datas[0] == 0) {
                      this.tvResult = "读基本信息成功:" + datas[1]
                    } else {
                      this.tvResult = "读基本信息失败:" + datas[0]
                    }
                  })

              }.margin({ top: 10 })
              Row() {
                Button("加密步骤1")
                  .fontSize($r('app.float.submit_button_font_size'))
                  .fontWeight(CommonContants.FONT_WEIGHT)
                  .height(20)
                  .width(95)
                  .onClick(() => {
                    let datas:[number, string] = DonseeDevice.Donsee_iReadCardBas_HSM_Step1(3)
                    if (datas[0] == 0) {
                      this.tvResult = "读卡成功:" + datas[1]
                    } else {
                      this.tvResult = "读卡失败:" + datas[0]
                    }
                  })

                Button("加密步骤2")
                  .fontSize($r('app.float.submit_button_font_size'))
                  .fontWeight(CommonContants.FONT_WEIGHT)
                  .height(20)
                  .width(95)
                  .onClick(() => {
                    let datas:[number, string] = DonseeDevice.Donsee_iReadCardBas_HSM_Step2(this.pKkey)
                    if (datas[0] == 0) {
                      this.tvResult = "读卡成功:" + datas[1]
                    } else {
                      this.tvResult = "读卡失败:" + datas[0]
                    }
                  })
              } .margin({ top: 10 })
            }.justifyContent(FlexAlign.End)
            .margin({right:10})

          }.justifyContent(FlexAlign.Start)
          .width(CommonContants.FULL_PARENT)
        }.justifyContent(FlexAlign.Start)
        .backgroundColor($r('app.color.card_background'))
        .width(CommonContants.FULL_PARENT)
        .height(CommonContants.FULL_PARENT)
      }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2373281.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

《Python星球日记》 第54天:卷积神经网络进阶

名人说:路漫漫其修远兮,吾将上下而求索。—— 屈原《离骚》 创作者:Code_流苏(CSDN)(一个喜欢古诗词和编程的Coder😊) 目录 一、深度CNN架构解析1. LeNet-5(1998)2. AlexNet&#x…

《AI大模型应知应会100篇》第53篇:Hugging Face生态系统入门

第53篇:Hugging Face生态系统入门 ——从模型获取到部署的全流程实战指南 📌 摘要 在人工智能快速发展的今天,Hugging Face已成为自然语言处理(NLP)领域最具影响力的开源平台之一。它不仅提供丰富的预训练模型、强大…

【基于 LangChain 的异步天气查询2】GeoNames实现地区实时气温查询

目录 功能简介 一、创建GeoNames账号 1、进入官网 2、创建账号 二、运行代码 weather_runnable.py main.py 运行结果 功能简介 本文主要通过Langchain,结合GeoNames实现了地区温度的实时查询,并通过GPT-4o对温度进行一段简短的描述。 一、创建Ge…

服务器数据恢复—硬盘坏道导致EqualLogic存储不可用的数据恢复

服务器存储数据恢复环境&故障: 一台EqualLogic某型号存储中有一组由16块SAS硬盘组建的RAID5阵列。上层采用VMFS文件系统,存放虚拟机文件,上层一共分了4个卷。 磁盘故障导致存储不可用,且设备已经过保。 服务器存储数据恢复过程…

JAVA实战开源项目:智能学习平台系统 (Vue+SpringBoot) 附源码

本文项目编号 T 181 ,文末自助获取源码 \color{red}{T181,文末自助获取源码} T181,文末自助获取源码 目录 一、系统介绍二、数据库设计三、配套教程3.1 启动教程3.2 讲解视频3.3 二次开发教程 四、功能截图五、文案资料5.1 选题背景5.2 国内…

傅利叶十周年,升级核心战略:“有温度”的具身智能蓝图

5月9日,傅利叶十周年庆典暨首届具身智能生态峰会在上海正式召开。本次大会以“十年共创,具身成翼”为主题,汇聚了来自通用机器人与医疗康复领域的顶尖专家学者、合作伙伴与投资机构,共同探索具身智能在未来十年的技术应用与生态发…

AI安全之对抗样本攻击---FGSM实战脚本解析

一、对抗样本与FGSM的背景 在深度学习安全领域,对抗样本(Adversarial Examples)因其特殊的生成机制备受关注。2015年ICLR会议收录的里程碑式论文《Explaining and Harnessing Adversarial Examples》中,Goodfellow等学者首次系统…

《Python星球日记》 第50天:深度学习概述与环境搭建

名人说:路漫漫其修远兮,吾将上下而求索。—— 屈原《离骚》 创作者:Code_流苏(CSDN)(一个喜欢古诗词和编程的Coder😊) 目录 一、什么是深度学习?它与传统机器学习的区别1. 深度学习的定义2. 深…

linux搭建hadoop学习

linux搭建hadoop学习 下载安装包: 海外资源可能需要翻墙或者找国内资源 cd /opt wget https://dlcdn.apache.org/hadoop/common/hadoop-2.10.2/hadoop-2.10.2.tar.gz tar -zxvf hadoop-2.10.2.tar.gz mv hadoop-2.10.2 hadoop配置环境变量 # 在/etc/profile文件中添加下面内…

PyTorch API 8 - 工具集、onnx、option、复数、DDP、量化、分布式 RPC、NeMo

文章目录 torch.nn.inittorch.nn.attention工具集子模块 torch.onnx概述基于 TorchDynamo 的 ONNX 导出器基于TorchScript的ONNX导出器贡献与开发 torch.optim如何使用优化器构建优化器每个参数的选项执行优化步骤optimizer.step()optimizer.step(closure) 基类算法如何调整学习…

0基础 | STM32 | TB6612电机驱动使用

TB6612介绍及使用 单片机通过驱动板连接至电机 原因:单品机I/O口输出电流I小 驱动板:从外部引入高电压,控制电机驱动 电源部分 VM:电机驱动电源输入,输入电压范围建议为3.7~12V GND:逻辑电…

【Linux】POSIX 线程信号量与互斥锁▲

代码要求:高内聚,低耦合 高内聚:元素之间具有很强的关联性,模块的功能单一且集中 低耦合:代码之间的依赖关系尽可能简单,相互之间的影响和交互尽可能少 线程安全问题:多线程访问共享数据&…

USR-M100采集数据并提交MQTT服务器

本文为记录备忘,不做过多解释。 模块自身带有2路数字量输入,2路模拟量输入,2路485接口 数字量接报警输入,模拟量接压力传感器,液位传感器,485接口分别接流量计,温湿度传感器。 正确接线&…

内网穿透系列三:开源本地服务公网映射工具 tunnelmole

以下是对 tunnelmole 简要介绍: tunnelmole 是一款开源的内网穿透工具,一行命令就能把本地http服务映射成公网可访问的链接提供公共免费的网络服务,直接下载运行命令即可使用,也支持自行配置搭建私有客户端、服务端参考开源地址&…

数据集-目标检测系列- 冥想 检测数据集 close_eye>> DataBall

数据集-目标检测系列- 冥想 检测数据集 close * 相关项目 1)数据集可视化项目:gitcode: https://gitcode.com/DataBall/DataBall-detections-100s/overview 2)数据集训练、推理相关项目:GitHub - XIAN-HHappy/ultralytics-yolo-…

论文精读:YOLOE: Real-Time Seeing Anything

文章目录 前言1、背景2、方法2.1.重参Region-Text对齐模块2.2.VisualPrompt模块2.3.PromptFree 2.4.损失函数3、实验3.1.训练集3.2.实验结果 总结 前言 本文介绍一篇来自清华的开放词汇检测论文:YOLOE;源码链接。 1、背景 本文在yolo-world基础上&#x…

以影像为笔,劳润智在世界舞台上书写艺术之路

在光影交织中,摄影师劳润智的镜头仿佛能穿透喧嚣,捕捉人类情感最细腻的脉动。从疫情下洛杉矶裁缝日常的温馨瞬间,到象征自由与解脱的飞鸟影像,再到探索时间与空间交错的抽象作品,每一幅作品都展现了他对艺术的深度追求与对生活的温柔洞察。 劳润智的作品为他赢得了多个国际奖项…

LLMs之ChatGPT:《Connecting GitHub to ChatGPT deep research》翻译与解读

LLMs之ChatGPT:《Connecting GitHub to ChatGPT deep research》翻译与解读 导读:这篇OpenAI帮助文档全面介绍了将GitHub连接到ChatGPT进行深度代码研究的方法、优势和注意事项。通过连接GitHub,用户可以充分利用ChatGPT强大的代码理解和生成…

【桌面】【输入法】常见问题汇总

目录 一、麒麟桌面系统输入法概述 1、输入法介绍 2、输入法相关组件与服务 3、输入法调试相关命令 3.1、输入法诊断命令 3.2、输入法配置重新加载命令 3.3、启动fcitx输入法 3.4、查看输入法有哪些版本,并安装指定版本 3.5、重启输入法 3.6、查看fcitx进程…

QT的初始代码解读及其布局和弹簧

this指的是真正的当前正在显示的窗口 main函数: Widget w是生成了一个主窗口,QT Designer是在这个主窗口里塞组件 w.show()用来展示这个主窗口 头文件: namespace Ui{class Widget;}中的class Widget和下面的class Widget不是一个东西 Ui…