中软高科微信小程序NFC读卡插件,支持多种证卡识读与活体识别

2024-12-07 14:51:35 0点赞 1收藏 0评论

​海飞思NFC身份证云解码,由中软高科出品,可以对身份证、外国人永居证、护照、港澳台通行证等证件进行识读,也可以进行活体检测

 1、引入插件

在小程序的app.json中,加入插件。

"plugins": { "readcard-plugin": { "version": "2.3.2", "provider": "wxa2583ebacdb87a6a" } }

2、基础库

调试基础库 2.18.1及以上 微信版本: iOS 暂不支持NFC(微信官方未支持),可使用蓝牙外设读卡器 Android 8.0.6及以上版本,同时支持NFC、蓝牙外设读卡器

3、使用插件功能

3.1、读取身份证件信息功能

在需要使用身份证读卡的页面中,使用插件示例。

const plugin = requirePlugin('readcard-plugin'); var StatusCode = null; var that = this; var initSuccess = false; Page({ data: { idCardInfo: null, }, onLoad() { that = this; StatusCode = plugin.StatusCodeEnum(); console.log("对照状态码:", StatusCode); // 设置APPID (开始读卡之前,必须设置) plugin.setAppId("appid联系我司商务获取"); // 设置读卡SDK参数 that.readSetting(); // 初始化读卡 that.initRead(); }, // 设置读卡SDK参数 readSetting(){ // 日志保存目录 // 默认在 Android/data/com.tencent.mm/MicroMsg/wxanewfiles目录下 搜索 zrgk_mini_log // 不需要日志时,可以不设置 plugin.setShowLog(wx.getFileSystemManager(), wx.env.USER_DATA_PATH); // 读卡参数设置,根据需要自行修改参数值,参数名称及类型不可修改。 var _Setting = { decodeImageType: "dn1", // dn0: 无照片 dn1: 平台解码照片 readCardType: 2, // 2:NFC 7:蓝牙外设读卡器 9: NFC读护照/通行证 saveLog: true, // 是否保存日志文件。设置true时,必须调用以上的 plugin.setShowLog(); 设置日志保存的目录 openLocalCache: true, // 是否开启本地缓存 // 解码服务器配置。 // 默认第1个为主服务器,优先使用。 // 其余皆为备用服务器,主服务器异常时自动切换启用 ipPortArray: [{ address: 'yfs4.sfzydq.com', port: 9999, canUse: true }, { address: 'test.sfzydq.com', port: 18180, canUse: true }] }; // 将参数设置给插件 plugin.readSetting(_Setting); }, // 初始化 读卡示例代码 initRead() { if (initSuccess == true) { wx.showToast({ title: '已经初始化过了', icon: 'none' }); return; } // 初始化并开始读卡 plugin.startReadCard(function (code, msg, value, cardType) { let code_msg = "code:" + code + "n" + "msg:" + msg; that.setData({ msg: code_msg, }); switch (code) { case StatusCode.ININ_ING.code: // 初始化中 wx.showLoading({ title: '初始化中...', mask: true }); break; case StatusCode.ININ_OK.code: // 初始化成功 initSuccess = true; wx.hideLoading(); wx.showToast({ title: '初始化成功', icon: 'success' }) break; case StatusCode.ININ_FAILE.code: // 初始化失败 initSuccess = false; wx.hideLoading(); if (msg.indexOf("13000") != -1) { wx.showModal({ title: '温馨提示', content: '设备不支持NFC', complete: (res) => {} }); } else if (msg.indexOf("13001") != -1) { wx.showModal({ title: '温馨提示', content: '系统NFC开关未打开', complete: (res) => {} }); } else { wx.showToast({ title: msg, icon: 'error' }) } break; case StatusCode.FIND_CARD_START.code: // 开始寻卡 wx.showToast({ title: '开始寻卡', icon: 'success' }) break; case StatusCode.FIND_CARD_SUCCESS.code: // 寻卡成功 allCount += 1; wx.showToast({ title: '寻卡成功', icon: 'success' }) break; case StatusCode.READCARD_START.code: // 开始解码 wx.showLoading({ title: '请勿移动卡片', mask: true }) break; case StatusCode.READCARD_SUCCESS.code: // 解码成功 wx.hideLoading(); wx.showToast({ title: '解码成功', icon: 'success' }) switch (cardType) { case StatusCode.CARD_IC.code: // IC卡 console.log("IC卡:" , value); break; case StatusCode.CARD_LCT_STUDENT.code: // 绿城通学生卡 console.log("绿城通学生卡:" , value); break; case StatusCode.CARD_LCT_NORMAL.code: // 绿城通普通卡 console.log("绿城通普通卡:" , value); break; case StatusCode.CARD_LCT_OLD.code: // 绿城通老年卡 console.log("绿城通老年卡:" , value); break; case StatusCode.CARD_IDCARD.code: // 身份证 // 读取到的身份证信息 // 详细字段说明,详见文档下发的附录 var idCardInfo = JSON.parse(value); console.log("身份证信息:" , idCardInfo); // 当设置平台解码身份证照片时, // idCardInfo.image字段,为base64编码的照片字符串,可直接用于显示 // idCardInfo.type=1080 中国居民身份证 // idCardInfo.type=1081 新版外国永久居住证 // idCardInfo.type=1082 港澳台居住证 // idCardInfo.type=1083 旧版外国永久居住证 break; case StatusCode.CARD_EPASSPORT.code: // 护照/通行证 // 读取到的护照/通行证信息 // 详细字段说明,详见文档下发的附录 var cardInfo = JSON.parse(value); console.log("证件信息:" , cardInfo); // cardInfo.image字段,为base64编码的照片字符串,可直接用于显示 break; } break; case StatusCode.READCARD_FAILE.code: // 解码失败 wx.hideLoading(); wx.showToast({ title: '解码失败' + msg, icon: 'error' }) that.readFa(); break; } }); }, onUnload() { console.log("onUnload", "界面销毁,需要停止读卡"); plugin.stopReadCard(); } })

3.2、活体检测/人脸比对功能

  • 在界面的 **.wxml 添加camera

界面的其余样式,自行定义

  • 在界面 **.js 配置使用插件

const plugin = requirePlugin('readcard-plugin'); var that = this; Page({ /** * 页面的初始数据 */ data: { type: 1, // 1:仅活体检测 2:活体 + 人脸1:1比对 outTimeMs: 5000, // 超时时间 毫秒(最小3秒) photoData: null, // (照片数据的字节数组)仅活体检测不需要传比对的照片,人脸人脸1:1比对时,需要传入比对的照片 appid: "", // appid联系我司商务获取 _Setting: { saveLog: true, // 是否保存日志文件 // 服务器配置 ipPortArray: [{ address: 'test.sfzydq.com', port: 18181, canUse: true }] } }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { that = this; that.authorize(); }, /** * 向用户申请相机权限 */ authorize() { wx.getSetting({ success(res) { if (!res.authSetting['scope.camera']) { wx.authorize({ scope: 'scope.camera', success() { // 用户已经同意 that.faceLive(); }, fail() { wx.openSetting({ success(res) { that.authorize(); } }) } }) } else { that.faceLive(); } } }) }, /** * 开始活体检测 */ faceLive() { // 设置APPID plugin.setAppId(that.data.appid); // 设置其他检测参数 plugin.settingFacelive(that.data._Setting); // 帧数据回调 const context = wx.createCameraContext() const listener = context.onCameraFrame((frame) => { plugin.onCameraFrame(frame); }); // 开始检测 plugin.startFacelive(listener, that.data.type, that.data.outTimeMs, that.data.photoData) .then((bean) => { console.log(bean); var content = ""; if (bean.code != "00") { // 失败 content = bean.msg; } else { content = "结果:" + bean.code + "n活体分值:" + bean.liveGrade; if (that.data.type == 2) { content += "n人脸比对分值:" + bean.faceGrade; } } wx.showModal({ title: '温馨提示', content: content, showCancel: false, success: (res) => { if (res.confirm) { // 用户点击确定 wx.navigateBack(); } } }); }).catch((err) => { console.log(err); var content = ""; try { if (typeof err == "object") { let bean = err; content = bean.msg; content += "n活体分值:" + bean.liveGrade; if (that.data.type == 2) { content += "n人脸比对分值:" + bean.faceGrade; } } else { content = err; } } catch (error) { content = JSON.stringify(error); } wx.showModal({ title: '温馨提示', content: content, showCancel: false, success: (res) => { if (res.confirm) { // 用户点击确定 wx.navigateBack(); } } }); }); }, /** * 生命周期函数--监听页面卸载 */ onUnload() { plugin.stopFacelive(); } })

4、配置TCP合法域名

必须将参数配置时,配置的 ipPortArray 参数中的所有服务器地址,加入到合法的TCP域名,
否则无法访问到服务器。
如配置:

tcp://yfs4.sfzydq.com tcp://test.sfzydq.com tcp://yjm2.sfzydq.com tcp://yfs3.sfzydq.com

5、附录

附录附录

作者声明本文存在利益相关性,请大家尊重作者及分享的内容,友善沟通,理性决策~

展开 收起

微软在线发 多年office365家庭版个人版续费新订microsoft365订阅密钥 Microsoft365 个人版 一年 密钥-在线直发咚咚聊天窗口领取

微软在线发 多年office365家庭版个人版续费新订microsoft365订阅密钥 Microsoft365 个人版 一年 密钥-在线直发咚咚聊天窗口领取

209元起

微软微软win10win11专业版授权解决企业化office copilot订阅 授权 copilot订阅服务含税

微软微软win10win11专业版授权解决企业化office copilot订阅 授权 copilot订阅服务含税

3099元起

Microsoft 微软 618一次付款终身使用苹果M1M2办公软件 Office2016小型企业版 MAC专用

Microsoft 微软 618一次付款终身使用苹果M1M2办公软件 Office2016小型企业版 MAC专用

159元起

Microsoft 微软 365 家庭版 30月

Microsoft 微软 365 家庭版 30月

558元起

微软支持重装绑 office2021永久激活码2019终身版macoffice软件 Office2021小型企业版for Mac

微软支持重装绑 office2021永久激活码2019终身版macoffice软件 Office2021小型企业版for Mac

499元起

Microsoft 微软 15月 微软office365家庭版microsoft365增强版

Microsoft 微软 15月 微软office365家庭版microsoft365增强版

279元起

Microsoft 微软 618活动大促中 office永久激活码office2019增强版终身版outlook密钥

Microsoft 微软 618活动大促中 office永久激活码office2019增强版终身版outlook密钥

349元起

Microsoft 微软 618活动大券加跨店满减 微软 MAC专用办公软件office2019永久版

Microsoft 微软 618活动大券加跨店满减 微软 MAC专用办公软件office2019永久版

229元起

Microsoft 微软 Office 365 个人版

Microsoft 微软 Office 365 个人版

239元起

Microsoft 微软 365/Office 家庭版 文档自动保存 各设备通用 1年盒装版 6人同享

Microsoft 微软 365/Office 家庭版 文档自动保存 各设备通用 1年盒装版 6人同享

329元起

任天堂Nintendo Switch 塞尔达传说 天空之剑 盒装版游戏实体卡带 海外版卡带

任天堂Nintendo Switch 塞尔达传说 天空之剑 盒装版游戏实体卡带 海外版卡带

198元起

深信服科技(SANGFOR)终端管理系统 (aES)

深信服科技(SANGFOR)终端管理系统 (aES)

300元起

Nintendo 任天堂 Switch游戏卡带《大航海时代4 威力加强版 HD》 中文

Nintendo 任天堂 Switch游戏卡带《大航海时代4 威力加强版 HD》 中文

196元起

深信服科技(SANGFOR) OSM-1000-B1150运维管理系统

深信服科技(SANGFOR) OSM-1000-B1150运维管理系统

暂无报价

微软(Microsoft)365/Office 个人版 文档自动保存 各设备通用 1年盒装 5设备同享

微软(Microsoft)365/Office 个人版 文档自动保存 各设备通用 1年盒装 5设备同享

249元起

Microsoft 微软 618活动开始到手15元/月 office365个人版续费新订microsoft365个

Microsoft 微软 618活动开始到手15元/月 office365个人版续费新订microsoft365个

暂无报价
0评论

当前文章无评论,是时候发表评论了
提示信息

取消
确认
评论举报

相关好价推荐
查看更多好价

相关文章推荐

更多精彩文章
更多精彩文章
最新文章 热门文章
1
扫一下,分享更方便,购买更轻松