鸿蒙hap非调试模式无法直接安装到开发板中,需要udid签名才能安装。
上架到商城之后就可以任意设备安装使用。
SDK需要厂商提前预置USB设备读写权限,如果您的鸿蒙设备是定制设备,遇到找不到设备时,请询问设备定制方是否开放了USB接口的系统层权限。
ArkTS是HarmonyOS应用开发语言。它在保持TypeScript(简称TS)基本语法风格的基础上,对TS的动态类型特性施加更严格的约束,引入静态类型。同时,提供了声明式UI、状态管理等相应的能力,让开发者可以以更简洁、更自然的方式开发高性能应用。 [2]
2.2身份证
class IDCardInfo {
public result: number /*返回值*/
public name: string /*中文姓名*/
public ENfullname: string /*英文姓名*/
public ENfullnameOther: string /*英文姓名备用*/
public changCount: string /*签发数次*/
public sex: string /*性别*/
public people: string /*民族*/
public birthday: string /*出生日期(YYYYMMDD)*/
public address: string /*地址*/
public number: string /*证件号码*/
public organs: string /*发证机关(或外国人永久居住正-当次申请受理机关)*/
public signdate: string/*发证日期(YYYYMMDD)*/
public validterm: string/*有效日期(YYYYMMDD)*/
public certType: string /*卡片类型,0:居民身份证,I:外国人,J:港澳台,Y:新版外国人*/
public certVersion: string /*证件版本*/
public oldNumber: string /*既往版本永居证号码*/
public nationality: string /*国籍*/
public passNu: string /*通行证号*/
public signCount: string /*签发数次*/
public imgBase64: string /*读取二代证电子信息时保存照片数据信息Base64格式*/
public figData: string /*指纹信息*/
}
2.2.1 Donsee_ReadIDCard读取身份证信息
定义:读取身份证信息
原型:IDCardInfo Donsee_ReadIDCard (int nType);
参数:
nType: 设置身份证读卡类型:0,文本信息;1,文本+照片;2,文本+照片+指纹
返回值:IDCardInfo对象
IDCardInfo.result 0: 读取身份证信息成功;
IDCardInfo.result 非0: 读取身份证信息失败,参考状态码
以下是ArkTS代码:
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';
/**
* Harmony鸿蒙系统SDK开发包
* EST-100多功能智能卡读写器
* date:2023-11-15
* 广东东信智能
*/
@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 // 当前选中项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)
// 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.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[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 ''
}
}