读取身份证开发配置
function readerid鱼住未来科技(){const webUrl = 'http://' + "127.0.0.1:30004" + '/api/info'$.ajax({url: webUrl,type: 'GET',dataType: 'json',success: function (result) {// processContent.text('web api接口:' + webUrl + ' 读取身份证信息成功')const szparam = result身份证渲染_鱼住未来科技(szparam);},error: function (jqXHR, textStatus, errorThrown) {// processContent.text('web api接口:' + webUrl + ' 读取身份证失败,原因:' + hex2a(window.atob(errorThrown)))alert("读取身份证失败"+ hex2a(window.atob(errorThrown)));}})}
身份证解析代码
function 身份证渲染_鱼住未来科技(szparam){// alert(szparam.CardType);if (szparam.CardType == 74){// 切换背景图片 83是台湾cardFront.removeClass()cardBack.removeClass()cardFront.addClass('GAT-card')cardFront.addClass('card-hongkong-macao-taiwan-front')cardBack.addClass('GAT-card')let no = hex2a(window.atob(szparam.CardInfo.No))if (no && no.startsWith('83')){cardBack.addClass('card-taiwan-back')}else{cardBack.addClass('card-hongkong-macao-back')}strLog = '读取 港澳台居民居住证 成功\r\n';strLog += 'SN:' + szparam.CardInfo.SN + '\r\n';strLog += '中文名:' + hex2a(window.atob(szparam.CardInfo.Name)) + '\r\n';strLog += '证件号码:' + no + '\r\n';strLog += '性别:' + hex2a(window.atob(szparam.CardInfo.Sex)) + '\r\n';strLog += '出生日期:' + hex2a(window.atob(szparam.CardInfo.Birthday)) + '\r\n';strLog += '民族:' + hex2a(window.atob(szparam.CardInfo.Nation)) + '\r\n';strLog += '地址:' + hex2a(window.atob(szparam.CardInfo.Address)) + '\r\n';strLog += '签发机关:' + hex2a(window.atob(szparam.CardInfo.SignedDepartment)) + '\r\n';strLog += '开始日期:' + hex2a(window.atob(szparam.CardInfo.ValidityPeriodBegin)) + '\r\n';strLog += '结束日期:' + hex2a(window.atob(szparam.CardInfo.ValidityPeriodEnd)) + '\r\n\r\n';strLog += '通行证号码:' + hex2a(window.atob(szparam.CardInfo.OtherNO)) + '\r\n';strLog += '签发次数:' + hex2a(window.atob(szparam.CardInfo.SignNum)) + '\r\n';//processContent.text(strLog)// 港澳台通行证号码console.log(szparam.CardInfo)// cardFront.find('.name').text(hex2a(window.atob(szparam.CardInfo.Name)))// cardFront.find('.sex').text(hex2a(window.atob(szparam.CardInfo.Sex)) ==='1'? '男':'女')const Birthday = hex2a(window.atob(szparam.CardInfo.Birthday))const birthArr = parseDateString(Birthday , ".", true).split(".")// cardFront.find('.year').text(birthArr[0])// cardFront.find('.month').text(birthArr[1])// cardFront.find('.date').text(birthArr[2])// cardFront.find('.address').text(hex2a(window.atob(szparam.CardInfo.Address)))// cardFront.find('.number').text(hex2a(window.atob(szparam.CardInfo.No)))// cardBack.find('.department').text(hex2a(window.atob(szparam.CardInfo.SignedDepartment)))const ValidityPeriodBegin = hex2a(window.atob(szparam.CardInfo.ValidityPeriodBegin))const ValidityPeriodEnd = hex2a(window.atob(szparam.CardInfo.ValidityPeriodEnd)).trim()const expiryBegin = parseDateString(ValidityPeriodBegin, '.')const expiryEnd = ValidityPeriodEnd !== '长期' ? parseDateString(ValidityPeriodEnd, '.') : ValidityPeriodEnd// cardBack.find('.expiry').text( expiryBegin + '-' + expiryEnd)// cardBack.find('.pass-number').text( hex2a(window.atob(szparam.CardInfo.OtherNO)))}else if (szparam.CardType == 73){// 切换背景图片 83是台湾cardFront.removeClass()cardBack.removeClass()cardFront.addClass('WGR-card-1')cardFront.addClass('card-old-foreigner-front')cardBack.addClass('WGR-card-1')cardBack.addClass('card-old-foreigner-back')strLog = '读取 外国人永久居留身份证(旧版) 成功\r\n';strLog += 'SN:' + szparam.CardInfo.SN + '\r\n';strLog += '中文名:' + hex2a(window.atob(szparam.CardInfo.Name)) + '\r\n';strLog += '英文名:' + hex2a(window.atob(szparam.CardInfo.EnName)) + '\r\n';strLog += '证件号码:' + hex2a(window.atob(szparam.CardInfo.No)) + '\r\n';strLog += '性别:' + hex2a(window.atob(szparam.CardInfo.Sex)) + '\r\n';strLog += '出生日期:' + hex2a(window.atob(szparam.CardInfo.Birthday)) + '\r\n';strLog += '国籍:' + hex2a(window.atob(szparam.CardInfo.Country)) + '\r\n';strLog += '签发机关:中华人民共和国移民管理局\r\n';strLog += '开始日期:' + hex2a(window.atob(szparam.CardInfo.ValidityPeriodBegin)) + '\r\n';strLog += '结束日期:' + hex2a(window.atob(szparam.CardInfo.ValidityPeriodEnd)) + '\r\n\r\n';strLog += '版本号:' + hex2a(window.atob(szparam.CardInfo.Version)) + '\r\n';processContent.text(strLog)let name = hex2a(window.atob(szparam.CardInfo.Name))let enName = hex2a(window.atob(szparam.CardInfo.EnName))let nameText = enName + (name.trim()? ' / '+ name : '')// cardFront.find('.name').text(nameText)// cardFront.find('.sex').text(hex2a(window.atob(szparam.CardInfo.Sex)) === '1'? '男': '女')const Birthday = hex2a(window.atob(szparam.CardInfo.Birthday))const birthArr = parseDateString(Birthday , ".", true).split(".")cardFront.find('.year').text(birthArr.join('-')) //出生年月cardFront.find('.month').text(hex2a(window.atob(szparam.CardInfo.Country)))//国籍const ValidityPeriodBegin = hex2a(window.atob(szparam.CardInfo.ValidityPeriodBegin))const ValidityPeriodEnd = hex2a(window.atob(szparam.CardInfo.ValidityPeriodEnd)).trim()const expiryBegin = parseDateString(ValidityPeriodBegin, '.')const expiryEnd = ValidityPeriodEnd !== '长期' ? parseDateString(ValidityPeriodEnd, '.') : ValidityPeriodEnd// cardFront.find('.date').text(expiryBegin + '-' + expiryEnd)// cardFront.find('.address').text('中华人民共和国移民管理局') //// cardFront.find('.number').text(hex2a(window.atob(szparam.CardInfo.No)))}else if (szparam.CardType == 89){// 切换背景图片 83是台湾cardFront.removeClass()cardBack.removeClass()cardFront.addClass('WGR-card')cardFront.addClass('card-new-foreigner-front')cardBack.addClass('WGR-card')cardBack.addClass('card-new-foreigner-back')strLog = '读取 外国人永久居留身份证(新版) 成功\r\n';strLog += 'SN:' + szparam.CardInfo.SN + '\r\n';strLog += '中文名:' + hex2a(window.atob(szparam.CardInfo.Name)) + '\r\n';strLog += '英文名:' + hex2a(window.atob(szparam.CardInfo.EnName)) + '\r\n';strLog += '证件号码:' + hex2a(window.atob(szparam.CardInfo.No)) + '\r\n';strLog += '性别:' + hex2a(window.atob(szparam.CardInfo.Sex)) + '\r\n';strLog += '出生日期:' + hex2a(window.atob(szparam.CardInfo.Birthday)) + '\r\n';strLog += '国籍:' + hex2a(window.atob(szparam.CardInfo.Country)) + '\r\n';strLog += '签发机关:中华人民共和国移民管理局\r\n';strLog += '开始日期:' + hex2a(window.atob(szparam.CardInfo.ValidityPeriodBegin)) + '\r\n';strLog += '结束日期:' + hex2a(window.atob(szparam.CardInfo.ValidityPeriodEnd)) + '\r\n\r\n';strLog += '通行证号码:' + hex2a(window.atob(szparam.CardInfo.OtherNO)) + '\r\n';strLog += '签发次数:' + hex2a(window.atob(szparam.CardInfo.SignNum)) + '\r\n';// processContent.text(strLog)let name = hex2a(window.atob(szparam.CardInfo.Name))let enName = hex2a(window.atob(szparam.CardInfo.EnName))// cardFront.find('.name').text(name)// cardFront.find('.enName').text(enName)// cardFront.find('.sex').text(hex2a(window.atob(szparam.CardInfo.Sex)) === '1'? '男': '女')const Birthday = hex2a(window.atob(szparam.CardInfo.Birthday))const birthArr = parseDateString(Birthday , ".", true).split(".")// cardFront.find('.year').text(birthArr.join('-')) //出生年月// cardFront.find('.month').text(hex2a(window.atob(szparam.CardInfo.Country)))//国籍const ValidityPeriodBegin = hex2a(window.atob(szparam.CardInfo.ValidityPeriodBegin))const ValidityPeriodEnd = hex2a(window.atob(szparam.CardInfo.ValidityPeriodEnd)).trim()const expiryBegin = parseDateString(ValidityPeriodBegin, '.')const expiryEnd = ValidityPeriodEnd !== '长期' ? parseDateString(ValidityPeriodEnd, '.') : ValidityPeriodEnd// cardFront.find('.date').text(expiryBegin + '-' + expiryEnd)// cardFront.find('.number').text(hex2a(window.atob(szparam.CardInfo.No)))}else{// cardFront.removeClass()// cardBack.removeClass()//cardFront.addClass('ID-card')// cardFront.addClass('card-front')// cardBack.addClass('ID-card')// cardBack.addClass('card-back')strLog = '读取 身份证 成功\r\n';strLog += 'SN:' + szparam.CardInfo.SN + '\r\n';strLog += '中文名:' + hex2a(window.atob(szparam.CardInfo.Name)) + '\r\n';strLog += '证件号码:' + hex2a(window.atob(szparam.CardInfo.No)) + '\r\n';strLog += '性别:' + hex2a(window.atob(szparam.CardInfo.Sex)) + '\r\n';strLog += '出生日期:' + hex2a(window.atob(szparam.CardInfo.Birthday)) + '\r\n';strLog += '民族:' + hex2a(window.atob(szparam.CardInfo.Nation)) + '\r\n';strLog += '地址:' + hex2a(window.atob(szparam.CardInfo.Address)) + '\r\n';strLog += '签发机关:' + hex2a(window.atob(szparam.CardInfo.SignedDepartment)) + '\r\n';strLog += '开始日期:' + hex2a(window.atob(szparam.CardInfo.ValidityPeriodBegin)) + '\r\n';strLog += '结束日期:' + hex2a(window.atob(szparam.CardInfo.ValidityPeriodEnd)) + '\r\n\r\n';strLog += '通行证号码:' + hex2a(window.atob(szparam.CardInfo.OtherNO)) + '\r\n';strLog += '签发次数:' + hex2a(window.atob(szparam.CardInfo.SignNum)) + '\r\n';// alert(strLog);// processContent.text(strLog)// 内容填充// cardFront.find('.name').text(hex2a(window.atob(szparam.CardInfo.Name)))// cardFront.find('.sex').text(hex2a(window.atob(szparam.CardInfo.Sex)))// cardFront.find('.nation').text(hex2a(window.atob(szparam.CardInfo.Nation)))const Birthday = hex2a(window.atob(szparam.CardInfo.Birthday))const birthArr = parseDateString(Birthday , ".", true).split(".")// cardFront.find('.year').text(birthArr[0])// cardFront.find('.month').text(birthArr[1])// cardFront.find('.date').text(birthArr[2])// cardFront.find('.address').text(hex2a(window.atob(szparam.CardInfo.Address)))// cardFront.find('.number').text(hex2a(window.atob(szparam.CardInfo.No)))// cardBack.find('.department').text(hex2a(window.atob(szparam.CardInfo.SignedDepartment)))const ValidityPeriodBegin = hex2a(window.atob(szparam.CardInfo.ValidityPeriodBegin))const ValidityPeriodEnd = hex2a(window.atob(szparam.CardInfo.ValidityPeriodEnd)).trim()const expiryBegin = parseDateString(ValidityPeriodBegin, '.')const expiryEnd = ValidityPeriodEnd !== '长期' ? parseDateString(ValidityPeriodEnd, '.') : ValidityPeriodEnd// cardBack.find('.expiry').text( expiryBegin + '-' + expiryEnd)const 姓名 = hex2a(window.atob(szparam.CardInfo.Name));const 证件号 =hex2a(window.atob(szparam.CardInfo.No));var 性别 =hex2a(window.atob(szparam.CardInfo.Sex)) ;const 地址 = hex2a(window.atob(szparam.CardInfo.Address)); // alert(地址);if(性别 == 1){性别="男";}else{性别="女";}var 身份证信息={username:姓名,userid:证件号,usersex:性别,address:地址};未来之窗_人工智能_前端口_数据渲染到界面(身份证信息,"");}// SNContent.text(szparam.CardInfo.SN)// cardFront.find('.image').attr('src','data:image/jpg;base64,' + szparam.BmpInfo)// if (szparam.CardInfo.Name){// cardFront.find('.name').text(hex2a(window.atob(szparam.CardInfo.Name)))// }// if (szparam.CardInfo.Sex){// cardFront.find('.sex').text(hex2a(window.atob(szparam.CardInfo.Sex)))// }// if (szparam.CardInfo.Nation){// cardFront.find('.nation').text(hex2a(window.atob(szparam.CardInfo.Nation)))// }//// const Birthday = hex2a(window.atob(szparam.CardInfo.Birthday))// const birthArr = parseDateString(Birthday , ".", true).split(".")// cardFront.find('.year').text(birthArr[0])// cardFront.find('.month').text(birthArr[1])// cardFront.find('.date').text(birthArr[2])//// if (szparam.CardInfo.Address){// cardFront.find('.address').text(hex2a(window.atob(szparam.CardInfo.Address)))// }//// if (szparam.CardInfo.No){// cardFront.find('.number').text(hex2a(window.atob(szparam.CardInfo.No)))// }//// if (szparam.CardInfo.SignedDepartment){// cardBack.find('.department').text(hex2a(window.atob(szparam.CardInfo.SignedDepartment)))// }//// const ValidityPeriodBegin = hex2a(window.atob(szparam.CardInfo.ValidityPeriodBegin))// const ValidityPeriodEnd = hex2a(window.atob(szparam.CardInfo.ValidityPeriodEnd)).trim()// const expiryBegin = parseDateString(ValidityPeriodBegin, '.')// const expiryEnd = ValidityPeriodEnd !== '长期' ? parseDateString(ValidityPeriodEnd, '.') : ValidityPeriodEnd// cardBack.find('.expiry').text( expiryBegin + '-' + expiryEnd)}
相关函数
function hex2a(hex) {let str_list = ''for (let i = 0; i < hex.length && hex.substr(i, 2) !== '00'; i += 2) {const a = hex.charCodeAt(i)const b = hex.charCodeAt(i + 1)const c = b * 256 + astr_list += String.fromCharCode(c)}return str_list.toString()}function parseDateString(str, deco, zero) {let year = str.substr(0,4)let month = str.substr(4,2)let date = str.substr(6)if(zero) {month = month.substr(0,1) === "0" ? month.substr(1) : monthdate = date.substr(0,1) === "0" ? date.substr(1) : date}return `${year}${deco}${month}${deco}${date}`}
智能编程
智能编程能大幅提升编程效率,自动完成重复代码编写、精准提供代码建议,还可借助数据分析优化代码性能,并降低编程门槛,让更多人参与开发,加速创新进程
阿雪技术观
让我们积极投身于技术共享的浪潮中,不仅仅是作为受益者,更要成为贡献者。无论是分享自己的代码、撰写技术博客,还是参与开源项目的维护和改进,每一个小小的举动都可能成为推动技术进步的巨大力量
Embrace open source and sharing, witness the miracle of technological progress, and enjoy the happy times of humanity! Let's actively join the wave of technology sharing. Not only as beneficiaries, but also as contributors. Whether sharing our own code, writing technical blogs, or participating in the maintenance and improvement of open source projects, every small action may become a huge force driving technological progress.