鴻蒙系統身份證閱讀器/社??ㄗx卡器集成參考資料
開源鴻蒙一定要修改這里,要不然重啟后app會無法使用
"products": [
{
"name": "default",
"signingConfig": "default",
"targetSdkVersion": 20,
"compatibleSdkVersion": 20,
"compileSdkVersion": 20,
"runtimeOS": "OpenHarmony",
"buildOption": {
"strictMode": {
"caseSensitiveCheck": true,
"useNormalizedOHMUrl": true
}
}
}
],
以上配置完成后,運行編譯:
如果沒報錯,則可以運行安裝hap
hdc_std install -r entry/build/default/outputs/default/entry-default-signed.hap
接下來,集成東信DonseeDeviceLib.har讀卡庫。
步驟 1:將DonseeDeviceLib.har拷貝到entry/src/libs目錄:
步驟 2:在entry/oh-package.json5里面添加如下代碼:
"donseedevicelib": "file:./src/libs/DonseeDeviceLib.har"
步驟 3:在entry/src/main里面添加如下代碼,申請權限
"requestPermissions": [
{
"name": "ohos.permission.ACCESS_EXTENSIONAL_DEVICE_DRIVER"
},
{
"name": "ohos.permission.ACCESS_DDK_USB",
"reason": "$string:ddk_usb_reason_text",
"usedScene": {
"abilities": [
"DriverExtAbility"
],
"when": "inuse"
}
}
],
步驟 4:讀身份證和社??ùa集成:
支持廣東東信智能科技有限公司EST-100系列產品,支持 EST-100、EST-100GS、EST-J13X、EST-100G、EST-100U等機型。
import DonseeDevice from 'donseedevicelib/src/main/ets/model/DonseeDevice';
import { IDCardInfor } from 'donseedevicelib/src/main/ets/model/IDCardInfor';
@Entry
@Component
struct Index {
@State message: string = '東信智能多功能讀寫器測試';
@State imgBase64: string = '';
@State imageVisible: Visibility = Visibility.None;
@State tvResult: string = '等待操作...';
build() {
Column() {
// 頂部標題
Text(this.message)
.fontSize(20)
.fontWeight(FontWeight.Bold)
.fontColor('#0066CC')
.margin({ top: 10, bottom: 10 });
// 身份證照片展示
Image(this.imgBase64)
.visibility(this.imageVisible)
.width(102)
.height(126)
.borderRadius(10)
.objectFit(ImageFit.Cover)
.backgroundColor('#F5F5F5')
.margin({ bottom: 5 });
// 操作結果卡片
Scroll() {
Text(this.tvResult)
.fontSize(16)
.fontColor('#333333')
.lineHeight(26)
.width('100%')
.padding(20)
}
.width('92%')
.height(260)
.backgroundColor('#FFFFFF')
.borderRadius(16)
.shadow({ radius: 4, color: '#10000000', offsetX: 0, offsetY: 2 })
.margin({ bottom: 10 });
// 功能按鈕區域
Column({ space: 16 }) {
Button("打開設備")
.width('92%')
.height(40)
.fontSize(18)
.fontWeight(FontWeight.Medium)
.backgroundColor('#0066CC')
.borderRadius(26)
.onClick(() => {
let ret: number = DonseeDevice.Donsee_Open("USB");
if (ret == 0) {
DonseeDevice.Donsee_Beep(50);
this.tvResult = "? 設備打開成功";
} else {
this.tvResult = "? 設備打開失敗,錯誤碼:" + ret;
}
});
Button("讀取身份證")
.width('92%')
.height(40)
.fontSize(18)
.fontWeight(FontWeight.Medium)
.backgroundColor('#009966')
.borderRadius(26)
.onClick(() => {
let idInfo: IDCardInfor = DonseeDevice.Donsee_ReadIDCard(1);
console.info("readResult: " + idInfo.result);
if (idInfo.result == 0) {
DonseeDevice.Donsee_Beep(50);
if (idInfo.ENfullnameOther.length > 0) {
idInfo.ENfullname += idInfo.ENfullnameOther;
}
this.tvResult =
"?? 中文姓名:" + idInfo.name + "\n" +
"?? 英文姓名:" + idInfo.ENfullname + "\n" +
"?? 性別:" + idInfo.sex + " 民族:" + idInfo.people + "\n" +
"?? 出生日期:" + idInfo.birthday + "\n" +
"?? 住址:" + idInfo.address + "\n" +
"?? 身份證號:" + idInfo.number + "\n" +
"?? 簽發機關:" + idInfo.organs + "\n" +
"? 有效期:" + idInfo.signdate + " - " + idInfo.validterm;
if (idInfo.imgBase64.length > 0) {
this.imgBase64 = 'data:image/png;base64,' + idInfo.imgBase64;
this.imageVisible = Visibility.Visible;
}
} else {
this.imageVisible = Visibility.None;
this.tvResult = "? 讀取失敗,錯誤碼:" + idInfo.result;
}
});
Button("讀社保卡")
.width('92%')
.height(40)
.fontSize(18)
.fontWeight(FontWeight.Medium)
.backgroundColor('#009966')
.borderRadius(26)
.onClick(() => {
let nSlotPsam = 1
let nType = 1
let ssCardInfor = DonseeDevice.Donsee_ReadSSCard(nSlotPsam, nType)
if (ssCardInfor.result == 0) {
DonseeDevice.Donsee_Beep(50);
this.tvResult = "姓 名:" + ssCardInfor.name + "\n"
+ "性 別:" + ssCardInfor.sex + "\n"
+ "民 族:" + ssCardInfor.nation + "\n"
+ "出身日期:" + ssCardInfor.birthday + "\n"
+ "城市代碼:" + ssCardInfor.city + "\n"
+ "身份證號:" + ssCardInfor.idnumber + "\n"
+ "社??ㄌ枺?quot; + ssCardInfor.cardnumber + "\n"
+ "開始有效期限:" + ssCardInfor.signdate + "\n"
+ "結束有效期限:" + ssCardInfor.validterm + "\n"
+ "社保版本:" + ssCardInfor.cardveVrsion + "\n"
} else {
this.tvResult = "讀卡失?。?quot; + ssCardInfor.result+"\n errMsg = "+ssCardInfor.errMsg.trim()
}
});
Button("讀社??ɑ拘畔?quot;)
.width('92%')
.height(40)
.fontSize(18)
.fontWeight(FontWeight.Medium)
.backgroundColor('#009966')
.borderRadius(26)
.onClick(() => {
let datas = DonseeDevice.Donsee_iReadCardBas(3)
if (datas[0] == 0) {
DonseeDevice.Donsee_Beep(50);
this.tvResult = "讀基本信息成功:" + datas[1]
} else {
this.tvResult = "讀基本信息失敗:" + datas[0]
}
});
}
.width('100%')
}
.width('100%')
.height('100%')
.backgroundColor('#F2F3F5')
.alignItems(HorizontalAlign.Center)
}
}








































