123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490 |
- import {
- viceBroadcast
- } from '../../utils/index/callAmpe'
- import {
- receiptPrinting
- } from '../../utils/index/receiptPrinting'
- import {
- encryptAndSign
- } from '../../utils/index/getSM4'
- import {
- desensitization,
- getWaterDrop
- } from '../../utils/index/index'
- import {
- userInfoQuery,
- } from '../../utils/api/api'
- const app = getApp()
- Page({
- data: {
- result: '',
- timer: 5,
- // 刷身份证信息
- brushingCardUserIInfo: {
- name: '',
- sex: '',
- nation: '',
- birthDate: '',
- address: '',
- idNum: '',
- photoBase64: '',
- },
- showFaceScan: false,
- // 签离成功信息
- signOffUserInfo: {},
- //刷脸倒计时
- intervalId1: null,
- count: 0,
- remainingTime: '',
- printVisitorList: false,
- timer1: null,
- timer2: null,
- clickRetryNum: 0,
- isShowRetry: false,
- },
- onLoad(e) {
- my.hideBackHome();
- this.setData({
- result: e.result || '结果页超时',
- resultText: e.resultText || '请重试',
- timer: e.timer ? parseInt(e.timer) : 5,
- clickRetryNum: app.data.clickRetryNum,
- isShowRetry: e.isShowRetry || false,
- })
- if (e.result && e.result == '刷脸登记') {
- this.setData({
- showFaceScan: true,
- remainingTime: '操作时间 ' + app.globalData.snDisposition.faceTimeout + ' 秒',
- timer: app.globalData.snDisposition.faceTimeout
- })
- this.startCountdown()
- this.clickFaceScan()
- return
- }
- if (e.result && e.result == '1:1比对') {
- this.setData({
- showFaceScan: true,
- remainingTime: '操作时间 ' + app.globalData.snDisposition.oneToOneTimeout + ' 秒',
- timer: app.globalData.snDisposition.oneToOneTimeout
- })
- this.startCountdown()
- this.getFaceInfoPersonCard(app.data.brushingCardUserIInfo)
- return
- }
- if (e.result && e.result == '联网查询') {
- console.log('联网查询');
- this.setData({
- timer: app.globalData.snDisposition.connectSearchTimeout
- })
- this.userInfoQuery()
- return
- }
- if (e.result && e.result == '签离成功') {
- this.setData({
- signOffUserInfo: app.data.signOffMsg
- })
- return
- }
- if (e.result && e.result == '首页刷证') {
- this.setData({
- timer: 15
- })
- this.showMsg(app.data.brushingCardUserIInfo)
- this.data.timer1 = setTimeout(function () {
- // 是否人证比对
- if (app.globalData.snDisposition.usePersonCard) {
- console.log('1:1比对-首页刷证');
- my.reLaunch({
- url: '/pages/resultPage/index?result=1:1比对',
- })
- } else {
- this.getUserInfo(app.data.brushingCardUserIInfo)
- }
- }, 1000)
- return
- }
- if (e.result && e.result == '登记成功') {
- switch (app.globalData.riskResult) {
- case 1:
- this.setData({
- printVisitorList: app.globalData.snDisposition.printVisitorList
- })
- if (app.globalData.snDisposition.printVisitorList) {
- this.printFun(app.data.visitoMsgData)
- }
- break;
- case 2:
- this.setData({
- result: '逃犯',
- })
- break;
- case 3:
- this.setData({
- result: '有前科',
- })
- break;
- default:
- break;
- }
- return
- }
- },
- // 倒计时
- startCountdown() {
- let that = this
- let {
- count
- } = that.data
- count = that.data.timer
- if (count) {
- if (that.data.intervalId1) {
- clearInterval(that.data.intervalId1);
- }
- that.data.intervalId1 = setInterval(() => {
- count--
- let remainingTime = '操作时间 ' + count + ' 秒'
- that.setData({
- remainingTime
- })
- if (count <= 0) {
- // 倒计时结束,清除定时器
- clearInterval(that.data.intervalId1)
- my.reLaunch({
- url: '/pages/home/index',
- })
- }
- }, 1000) // 每秒更新一次倒计时数字
- }
- },
- clickAudio() {
- getWaterDrop()
- },
- // 刷脸登记
- clickFaceScan() {
- let params1 = {
- "action": "getFaceInfo",
- "event": "open",
- "taskId": "2"
- }
- my.showLoading();
- try {
- my.call("ampeHHCommunication", params1, res => {
- console.log(res.data);
- // 倒计时结束1004 点击关闭1003 没认出来1001
- my.hideLoading()
- this.data.showFaceScan = false
- clearInterval(this.data.intervalId1);
- if (res.success && res.data.idNum) {
- let form = {
- xm: res.data.name,
- sfzh: res.data.idNum,
- phone: res.data.mobile,
- avatar: res.data.photoBase64,
- }
- app.data.userInfo = form
- viceBroadcast(app.globalData.snDisposition.successVoice)
- let isOpneTips = my.getStorageSync({
- key: 'isOpneTips'
- }).data;
- // 是否跳转到提示页
- if (isOpneTips) {
- my.reLaunch({
- url: '/pages/tipsPage/index'
- })
- } else {
- my.reLaunch({
- url: '/pages/interviewee/index'
- })
- }
- } else {
- if (!res.data || !res.data.originFaceInfo) {
- my.reLaunch({
- url: '/pages/resultPage/index?result=结果页超时&&timer=' + app.globalData.snDisposition.resultPageTimeout,
- })
- return
- }
- let originFaceInfo = JSON.parse(res.data.originFaceInfo)
- console.log(originFaceInfo.code);
- // 1003关闭,1004超时
- if (originFaceInfo.code == '1003' || originFaceInfo.code == '1004') {
- my.reLaunch({
- url: '/pages/home/index',
- })
- } else {
- // 启用无证登记和刷脸失败跳转手输,跳转输入身份证页面
- if (app.globalData.snDisposition.faceFailHandInput && app.globalData.snDisposition.noIdcardRegister) {
- my.reLaunch({
- url: '/pages/inputIDCard/index',
- })
- } else {
- viceBroadcast(app.globalData.snDisposition.failVoice)
- my.reLaunch({
- url: '/pages/resultPage/index?result=结果页超时&&timer=' + app.globalData.snDisposition.resultPageTimeout,
- })
- }
- }
- }
- });
- } catch (error) {
- my.hideLoading()
- clearInterval(this.data.intervalId1)
- my.reLaunch({
- url: '/pages/home/index',
- })
- this.setData({
- showFaceScan: false
- })
- }
- },
- // 联网查询获取用户信息
- async userInfoQuery() {
- var that = this;
- viceBroadcast(app.globalData.snDisposition.connectSearchVoice)
- try {
- that.handleValue(app.data.userInfo.xm)
- } catch (error) {
- console.log(error);
- }
- },
- handleValue(val) {
- clearTimeout(this.data.timer2)
- var that = this;
- // console.log(val);
- if (val) {
- let form = {
- name: app.data.userInfo.xm,
- idNum: app.data.userInfo.sfzh,
- photoBase64: app.data.userInfo.avatar,
- }
- app.data.brushingCardUserIInfo = form
- console.log('1:1比对-联网查询', val);
- my.reLaunch({
- url: '/pages/resultPage/index?result=1:1比对',
- })
- } else {
- that.data.timer2 = setTimeout(function () {
- clearTimeout(that.data.timer2)
- // 捕获到联网查询错误,跳转到重试页面
- if (app.data.isNetworkQueryError == false) {
- let resultText = app.data.clickRetryNum == 0 ? '查询超时,可点击重试' : '查询超时~'
- my.reLaunch({
- url: '/pages/resultPage/index?result=结果页超时&timer=' + app.globalData.snDisposition.resultPageTimeout + '&resultText=' + resultText + '&isShowRetry=' + true,
- })
- } else {
- that.handleValue(app.data.userInfo.xm)
- }
- }, 1000)
- }
- },
- // 重试
- retryFun() {
- this.getRetryUserInfo()
- app.data.clickRetryNum = app.data.clickRetryNum + 1
- app.data.isNetworkQueryError = null
- my.reLaunch({
- url: '/pages/resultPage/index?result=联网查询&timer=' + app.globalData.snDisposition.connectSearchTimeout,
- })
- },
- // 重试-联网查询用户信息
- async getRetryUserInfo() {
- try {
- let appKey = app.globalData.appKey
- let appSecret = app.globalData.appSecret
- let privateKey = app.globalData.privateKey
- let content = {
- sfzh: app.data.inputIdCard
- }
- content = JSON.stringify(content)
- let sm4 = encryptAndSign(appKey, appSecret, privateKey, content, "encrypted")
- // console.log(sm4);
- let data = {
- "appId": app.globalData.appId,
- "bizContent": sm4.encrypted,
- "reqTimestamp": sm4.timestamp,
- "sign": sm4.sign
- }
- let res = await userInfoQuery(data)
- app.data.isNetworkQueryError = true
- // 解密
- let decryptedData = encryptAndSign(appKey, appSecret, privateKey, res.data.bizContent, "decrypt")
- if (!decryptedData.decrypted) {
- return
- }
- let decrypted = JSON.parse(decryptedData.decrypted)
- app.data.userInfo = decrypted
- app.data.userInfo.avatar = decrypted.xp
- // this.handleValue(app.data.userInfo.xm)
- } catch (error) {
- app.data.isNetworkQueryError = false
- // this.handleValue(app.data.userInfo.xm)
- }
- },
- // 身份证信息展示
- showMsg(data) {
- let brushingCardUserIInfo = JSON.parse(JSON.stringify(data))
- brushingCardUserIInfo.sex = brushingCardUserIInfo.sex[0]
- var fruits = brushingCardUserIInfo.birthDate.split(".");
- brushingCardUserIInfo.year = fruits[0]
- brushingCardUserIInfo.month = fruits[1]
- brushingCardUserIInfo.day = fruits[2]
- app.data.brushingCardUserIInfo = brushingCardUserIInfo
- this.setData({
- brushingCardUserIInfo
- })
- },
- // 1:1比对
- getFaceInfoPersonCard(form) {
- let params1 = {
- "action": "getFaceInfoPersonCard",
- "event": "open",
- "taskId": "7",
- "params": {
- "certName": form.name,
- "certNo": form.idNum,
- "certPhotoBase64Str": form.photoBase64
- }
- }
- let that = this
- console.log(params1.params);
- try {
- my.call('ampeHHCommunication', params1, res => {
- clearInterval(that.data.intervalId1);
- // console.log(res.data);
- that.setData({
- showFaceScan: false
- })
- if (res.success) {
- that.getUserInfo(res.data)
- } else {
- if (!res.data || !res.data.originFaceInfo) {
- my.reLaunch({
- url: '/pages/resultPage/index?result=结果页超时&&timer=' + app.globalData.snDisposition.resultPageTimeout,
- })
- return
- }
- let originFaceInfo = JSON.parse(res.data.originFaceInfo)
- console.log(originFaceInfo);
- if (originFaceInfo.code == '1001' || originFaceInfo.code == '2006') {
- my.reLaunch({
- url: '/pages/resultPage/index?result=结果页超时&&timer=' + app.globalData.snDisposition.resultPageTimeout,
- })
- } else {
- my.reLaunch({
- url: '/pages/home/index',
- })
- my.showToast({
- content: (originFaceInfo && originFaceInfo.subMessage) ? originFaceInfo.subMessage : '请重试',
- duration: 2000
- });
- }
- }
- });
- } catch (error) {
- clearInterval(that.data.intervalId1);
- my.reLaunch({
- url: '/pages/home/index',
- })
- that.setData({
- showFaceScan: false
- })
- }
- },
- // 用户信息赋值
- getUserInfo(data) {
- app.data.userInfo.avatar = data.photoBase64 || ''
- app.data.userInfo.xm = data.name
- app.data.userInfo.sfzh = data.idNum
- my.reLaunch({
- url: '/pages/interviewee/index',
- })
- },
- // 打印小票
- printFun(form) {
- if (form.name) {
- form.name = desensitization(form.name, 1, 2)
- }
- if (form.phone) {
- form.phone = desensitization(form.phone, 3, 7)
- }
- let data = receiptPrinting(form)
- if (app.data.visitoMsgData.commonQrCode) {
- data.printList.push({
- "text": " " + app.globalData.snDisposition.generalQrcodeTitle,
- "textSize": 25,
- "bold": false,
- "algin": "center"
- }, {
- "width": 376,
- "height": 376,
- "qrCodeText": app.data.visitoMsgData.commonQrCode
- })
- }
- if (app.globalData.snDisposition.ethQrcode && app.data.visitoMsgData.ladderQrCode) {
- data.printList.push({
- "text": " " + app.globalData.snDisposition.ethQrcodeTitle,
- "textSize": 25,
- "bold": false,
- "algin": "center"
- }, {
- "width": 376,
- "height": 376,
- "qrCodeText": app.data.visitoMsgData.ladderQrCode
- })
- }
- let params = {
- "action": "receiptPrinting",
- "event": "open",
- "taskId": "10",
- "params": data
- }
- console.log(params);
- try {
- my.call('ampeHHCommunication', params, res => {
- console.log(res);
- if (!res.success) {
- my.showToast({
- content: res.message ? res.message : '打印失败,请重试',
- duration: 2000
- });
- }
- })
- } catch (error) {
- my.showToast({
- content: res.message ? res.message : '打印失败,请重试',
- duration: 2000
- });
- }
- },
- // 倒计时结束
- finish() {
- let {
- result
- } = this.data
- // 操作超时
- if (result == '扫码签离' || result == '刷身份证' || result == '联网查询' || result == '1:1比对') {
- my.reLaunch({
- url: '/pages/resultPage/index?result=结果页超时&&timer=' + app.globalData.snDisposition.resultPageTimeout,
- })
- }
- // 结果页自动退回首页
- if (result == '签离成功' || result == '签离失败' || result == '结果页超时' || result == '逃犯' || result == '有前科' || result == '登记成功') {
- clearInterval(this.data.intervalId1)
- my.reLaunch({
- url: '/pages/home/index',
- })
- }
- },
- sure() {
- clearInterval(this.data.intervalId1)
- my.reLaunch({
- url: '/pages/home/index',
- })
- },
- });
|