身份证阅读器和社保卡读卡器Harmony鸿蒙系统ArkTS语言SDK开发包

本文主要是介绍身份证阅读器和社保卡读卡器Harmony鸿蒙系统ArkTS语言SDK开发包,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

项目需求,用ArkTS新一代开发语言实现了在Harmony鸿蒙系统上面兼容身份证阅读器和社保卡读卡器,调用了DonseeDeviceLib.har这个读卡库。

需要注意的是,鸿蒙系统的app扩展名为.hap,本项目编译输出的应用为:entry-default-signed.hap

下面是调用身份证阅读器读取身份证信息的接口,支持居民身份证、GAT居民居住证以及外国人永久居留身份证三种证件读取。

ArkTS语言,CSDN这里没有这个选项,选择的TypeScript。

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';
/*** 广东东信智能科技有限公司* EST-100多功能智能卡读写器*/
@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: any = [{id: 1,name: '文本信息'},{id: 2,name: '文本照片'},{id: 3,name: '文本照片指纹'}]@Provide modeId: number = 0 // 当前选中项idbuild() {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)// HexUtil.bytesToHex()// if(obj.result>0){//   console.info("version: " + obj.version)// }// let[result,base64] = this.donseeDevice.Donsee_ReadIDCard()console.info("result: " + idInfo.result)if(idInfo.result==0){// console.info("obj.base64: " + obj.base64)// console.info("imgBase64.length1: " + this.imgBase64.length)// console.log(("中文姓名:"), idInfo.name);// console.log(("英文姓名:"), idInfo.ENfullname);// console.log(("性    别:"), idInfo.sex);// console.log(("民    族:"), idInfo.people);// console.log(("出身日期:"), idInfo.birthday);// console.log(("家庭住址:"), idInfo.address);// console.log(("身份证号:"), idInfo.number);// console.log(("签发单位:"), idInfo.organs);// console.log(("开始有效期限:"), idInfo.signdate);// console.log(("结束有效期限:"), idInfo.validterm);// console.log(("证件类别:"), idInfo.certType);// console.log(("证件版本:"), idInfo.certVersion);// console.log(("通行证号:"), idInfo.passNu);// console.log(("签发数次:"), idInfo.signCount);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.imgBase64this.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[result,data] = DonseeDevice.Donsee_ReadIDCardUid()if(result == 0){this.tvResult =  "Uid:"+ data}else{this.tvResult =  "Uid读取失败:"+ result}}).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 ''}}

以下是社保卡读卡器读取社保卡的代码,支持二代社保卡和三代社保卡读卡。

ArkTS语言,CSDN这里没有这个选项,选择的TypeScript。

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';
/*** 广东东信智能科技有限公司* EST-100多功能智能卡读写器*/
@Component
export struct SSCardComponent {@State tvResult: string = '';@State pKkey: string = '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||' }).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卡返回卡号var nType = 1if (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.namethis.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}})Button("读基本信息").fontSize($r('app.float.submit_button_font_size')).fontWeight(CommonContants.FONT_WEIGHT).height(20).width(95).onClick(() => {let [result, data] = DonseeDevice.Donsee_iReadCardBas(3)if (result == 0) {this.tvResult = "读基本信息成功:" + data} else {this.tvResult = "读基本信息失败:" + result}})}.margin({ top: 10 })Row() {Button("加密步骤1").fontSize($r('app.float.submit_button_font_size')).fontWeight(CommonContants.FONT_WEIGHT).height(20).width(95).onClick(() => {let [result, data] = DonseeDevice.Donsee_iReadCardBas_HSM_Step1(3)if (result == 0) {this.tvResult = "读卡成功:" + data} else {this.tvResult = "读卡失败:" + result}})Button("加密步骤2").fontSize($r('app.float.submit_button_font_size')).fontWeight(CommonContants.FONT_WEIGHT).height(20).width(95).onClick(() => {let [result, data] = DonseeDevice.Donsee_iReadCardBas_HSM_Step2(this.pKkey)if (result == 0) {this.tvResult = "读卡成功:" + data} else {this.tvResult = "读卡失败:" + result}})} .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)}}

这篇关于身份证阅读器和社保卡读卡器Harmony鸿蒙系统ArkTS语言SDK开发包的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/397275

相关文章

CSS3 最强二维布局系统之Grid 网格布局

《CSS3最强二维布局系统之Grid网格布局》CS3的Grid网格布局是目前最强的二维布局系统,可以同时对列和行进行处理,将网页划分成一个个网格,可以任意组合不同的网格,做出各种各样的布局,本文介... 深入学习 css3 目前最强大的布局系统 Grid 网格布局Grid 网格布局的基本认识Grid 网

使用Go语言开发一个命令行文件管理工具

《使用Go语言开发一个命令行文件管理工具》这篇文章主要为大家详细介绍了如何使用Go语言开发一款命令行文件管理工具,支持批量重命名,删除,创建,移动文件,需要的小伙伴可以了解下... 目录一、工具功能一览二、核心代码解析1. 主程序结构2. 批量重命名3. 批量删除4. 创建文件/目录5. 批量移动三、如何安

python使用fastapi实现多语言国际化的操作指南

《python使用fastapi实现多语言国际化的操作指南》本文介绍了使用Python和FastAPI实现多语言国际化的操作指南,包括多语言架构技术栈、翻译管理、前端本地化、语言切换机制以及常见陷阱和... 目录多语言国际化实现指南项目多语言架构技术栈目录结构翻译工作流1. 翻译数据存储2. 翻译生成脚本

如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别详解

《如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别详解》:本文主要介绍如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别的相关资料,描述了如何使用海康威视设备网络SD... 目录前言开发流程问题和解决方案dll库加载不到的问题老旧版本sdk不兼容的问题关键实现流程总结前言作为

在不同系统间迁移Python程序的方法与教程

《在不同系统间迁移Python程序的方法与教程》本文介绍了几种将Windows上编写的Python程序迁移到Linux服务器上的方法,包括使用虚拟环境和依赖冻结、容器化技术(如Docker)、使用An... 目录使用虚拟环境和依赖冻结1. 创建虚拟环境2. 冻结依赖使用容器化技术(如 docker)1. 创

Go语言中三种容器类型的数据结构详解

《Go语言中三种容器类型的数据结构详解》在Go语言中,有三种主要的容器类型用于存储和操作集合数据:本文主要介绍三者的使用与区别,感兴趣的小伙伴可以跟随小编一起学习一下... 目录基本概念1. 数组(Array)2. 切片(Slice)3. 映射(Map)对比总结注意事项基本概念在 Go 语言中,有三种主要

C语言中自动与强制转换全解析

《C语言中自动与强制转换全解析》在编写C程序时,类型转换是确保数据正确性和一致性的关键环节,无论是隐式转换还是显式转换,都各有特点和应用场景,本文将详细探讨C语言中的类型转换机制,帮助您更好地理解并在... 目录类型转换的重要性自动类型转换(隐式转换)强制类型转换(显式转换)常见错误与注意事项总结与建议类型

CentOS系统Maven安装教程分享

《CentOS系统Maven安装教程分享》本文介绍了如何在CentOS系统中安装Maven,并提供了一个简单的实际应用案例,安装Maven需要先安装Java和设置环境变量,Maven可以自动管理项目的... 目录准备工作下载并安装Maven常见问题及解决方法实际应用案例总结Maven是一个流行的项目管理工具

Go语言利用泛型封装常见的Map操作

《Go语言利用泛型封装常见的Map操作》Go语言在1.18版本中引入了泛型,这是Go语言发展的一个重要里程碑,它极大地增强了语言的表达能力和灵活性,本文将通过泛型实现封装常见的Map操作,感... 目录什么是泛型泛型解决了什么问题Go泛型基于泛型的常见Map操作代码合集总结什么是泛型泛型是一种编程范式,允

Android kotlin语言实现删除文件的解决方案

《Androidkotlin语言实现删除文件的解决方案》:本文主要介绍Androidkotlin语言实现删除文件的解决方案,在项目开发过程中,尤其是需要跨平台协作的项目,那么删除用户指定的文件的... 目录一、前言二、适用环境三、模板内容1.权限申请2.Activity中的模板一、前言在项目开发过程中,尤