341 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			341 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| import { voiceService } from '../../common/service/voiceService';
 | ||
| import { faceCompare } from '../../api/userInfo';
 | ||
| import FileUtil from '../../common/utils/File';
 | ||
| import { VideoConfig } from '../interfaces';
 | ||
| import common from '@ohos.app.ability.common';
 | ||
| 
 | ||
| import { string2Bytes } from '../../common/utils/tools';
 | ||
| import { takePhoto } from '../../common/service/videoService';
 | ||
| import { GlobalConfig } from '../../config/index';
 | ||
| import { VideoConfigData } from '../../mock';
 | ||
| 
 | ||
| @Component
 | ||
| export default struct FaceCompare {
 | ||
|   @State imageBase64: string = 'data:image/jpeg;base64,'
 | ||
|   @State base64: string = ''
 | ||
|   @Prop sfzh: string;
 | ||
|   @Prop lsh: string;
 | ||
|   @Prop firstImage: string;
 | ||
|   @Link faceCompareSucess: number;
 | ||
|   @Link showFaceCompare: boolean;
 | ||
|   @Link getqkFlag: boolean;
 | ||
|   @Link faceCatchImg: string;
 | ||
|   @State imageThumbnail: string = '';
 | ||
|   @State callBackFlag: boolean = false;
 | ||
|   @State @Watch('clearIntervalFn') showFaceCompareFlag: Boolean = false;
 | ||
|   @State video_url: string = 'rtsp://admin:12345qwe@192.168.5.41:8000/h264/ch2/main/av_stream'
 | ||
|   @State previewUri: Resource = $r('app.media.2_nor')
 | ||
|   @State curRate: PlaybackSpeed = PlaybackSpeed.Speed_Forward_1_00_X
 | ||
|   @State showControls: boolean = false
 | ||
|   @State isAutoPlay: boolean = true
 | ||
|   @State signNum: number = 0;
 | ||
|   @State param: VideoConfig = VideoConfigData
 | ||
|   private times = 1; //人脸比对失败次数, 超过3次将不会自动比对,需要点击重新打开重新触发
 | ||
|   private vocObj = null;
 | ||
|   private controller: VideoController = new VideoController()
 | ||
|   private fileUtil: FileUtil
 | ||
|   private interval: any
 | ||
|   private context = getContext(this) as common.UIAbilityContext;
 | ||
| 
 | ||
|   constructor() {
 | ||
|     super()
 | ||
|   }
 | ||
| 
 | ||
|   build() {
 | ||
|     Column() {
 | ||
|       Column() {
 | ||
|         Text('照片比对')// .lineHeight('16%')
 | ||
|           .height('16%')
 | ||
|           .fontWeight(FontWeight.Bold)
 | ||
|           .fontSize(24)
 | ||
| 
 | ||
|         Row() {
 | ||
|           Row() {
 | ||
|             Video({
 | ||
|               src: this.showFaceCompare ? `rtsp://${this.param.userName}:${this.param.pwd}@${this.param.ip}:${this.param.port}/h264/ch${this.param.rlls}/main/av_stream` : '',
 | ||
|               previewUri: this.previewUri,
 | ||
|               currentProgressRate: PlaybackSpeed.Speed_Forward_1_00_X,
 | ||
|               controller: this.controller,
 | ||
|             })
 | ||
|               .muted(true)
 | ||
|               .width('100%')
 | ||
|               .height('100%')
 | ||
|               .autoPlay(this.isAutoPlay)
 | ||
|               .controls(this.showControls)
 | ||
|           }
 | ||
|           .width('48%')
 | ||
|           .height('100%')
 | ||
| 
 | ||
| 
 | ||
|           Row() {
 | ||
|             Image(this.base64)
 | ||
|               .width('100%')
 | ||
|               .height('100%')
 | ||
|               .backgroundColor(Color.Black)
 | ||
|           }
 | ||
|           .width('48%')
 | ||
|           .height('100%')
 | ||
|         }
 | ||
|         .width('88.9%')
 | ||
|         .height('52%')
 | ||
|         .justifyContent(FlexAlign.SpaceBetween)
 | ||
| 
 | ||
|         Text('正在等待拍照…')// .lineHeight('16%')
 | ||
|           .height('16%')
 | ||
|           .fontWeight(FontWeight.Bold)
 | ||
|           .fontColor('#CC7E00')
 | ||
| 
 | ||
|         Column() {
 | ||
|           Row() {
 | ||
|             Text('若验证无响应,点击此处')
 | ||
|               .lineHeight('100%')
 | ||
|               .height('100%')
 | ||
|               .fontColor('#000000')
 | ||
| 
 | ||
|             Column() {
 | ||
|               Text('重新打开')
 | ||
|                 .lineHeight('100%')
 | ||
|                 .height('100%')
 | ||
|                 .fontColor(Color.White)
 | ||
|                 .fontSize(23)
 | ||
|             }
 | ||
|             .width('22.8%')
 | ||
|             .height('89.9%')
 | ||
|             .backgroundImage($r('app.media.nor'))
 | ||
|             .backgroundImageSize({ width: '100%', height: '100%' })
 | ||
|             .onClick(async () => {
 | ||
|               this.times = 1;
 | ||
|               this.controller.stop()
 | ||
|               this.vocObj && this.vocObj.releasePlayer()
 | ||
|               this.showFaceCompare = !this.showFaceCompare
 | ||
|               this.showFaceCompareFlag = !this.showFaceCompareFlag
 | ||
|               this.faceCompareSucess = -1
 | ||
|               globalThis.statue = 2
 | ||
|             })
 | ||
|           }
 | ||
|           .width('88.9%')
 | ||
|           .height('100%')
 | ||
|           .justifyContent(FlexAlign.SpaceBetween)
 | ||
|         }
 | ||
|         .width('100%')
 | ||
|         .height('16%')
 | ||
|         .position({ y: '84%' })
 | ||
|         .borderRadius({ topLeft: 0, topRight: 0, bottomLeft: 15, bottomRight: 15 })
 | ||
|         .backgroundColor('#CCC4B8')
 | ||
|       }
 | ||
|       .width('68.75%')
 | ||
|       .height('73.2%')
 | ||
|       .backgroundColor('#E5E3DF')
 | ||
|       .borderRadius(15)
 | ||
|       .margin({ top: '4%' })
 | ||
| 
 | ||
|       Column() {
 | ||
|       }
 | ||
|       .width('8.5%')
 | ||
|       .height('15.1%')
 | ||
|       .backgroundImage($r('app.media.close'))
 | ||
|       .backgroundImageSize({ width: '100%', height: '100%' })
 | ||
|       .onClick(() => {
 | ||
|         this.controller.stop()
 | ||
|         clearInterval(this.interval)
 | ||
|         this.vocObj && this.vocObj.releasePlayer()
 | ||
|         this.showFaceCompare = !this.showFaceCompare
 | ||
|         this.showFaceCompareFlag = !this.showFaceCompareFlag
 | ||
|         this.faceCompareSucess = -1
 | ||
|         globalThis.statue = 2
 | ||
| 
 | ||
| 
 | ||
|       })
 | ||
|     }
 | ||
|     .width('100%')
 | ||
|     .height('100%')
 | ||
|     .backgroundColor('rgba(0, 0, 0, 0.8)')
 | ||
|     .position({ x: 0, y: 0 })
 | ||
|   }
 | ||
| 
 | ||
|   onPageShow() {
 | ||
|   }
 | ||
| 
 | ||
|   async aboutToAppear() {
 | ||
|     const fileUtil = new FileUtil(this.context)
 | ||
|     this.fileUtil = fileUtil
 | ||
|     this.getVideoConfig()
 | ||
|   }
 | ||
| 
 | ||
|   clearIntervalFn() {
 | ||
|     this.callBackFlag = false
 | ||
|     clearInterval(this.interval)
 | ||
|     this.vocObj && this.vocObj.releasePlayer()
 | ||
|   }
 | ||
| 
 | ||
|   getqkFn() {
 | ||
|     let tmpList = [];
 | ||
|     tmpList.push(string2Bytes(globalThis.signNum, 1 * 8)[0])
 | ||
|     const param = {
 | ||
|       id: 41,
 | ||
|       list: tmpList,
 | ||
|       carNo: globalThis.carInfo.carNo,
 | ||
|       placeId: globalThis.carInfo.examinationRoomId
 | ||
|     }
 | ||
|     globalThis.udpClient2.sendMsgExt(param, this.context)
 | ||
|   }
 | ||
| 
 | ||
|   async faceComparFn() {
 | ||
|     console.log('mmmmm0', 2)
 | ||
|     this.param.pztd = this.param.rlls
 | ||
|     const data = await takePhoto(this.param, this.context, 'jt/', 1,)
 | ||
|     this.base64 = this.imageBase64 + data.base64
 | ||
|     faceCompare({
 | ||
|       sfzh: this.sfzh,
 | ||
|       secondImage:data.base64,
 | ||
|       firstImage: this.firstImage.substr(22),
 | ||
|       type: 2,
 | ||
|       verifyType: 1
 | ||
|     })
 | ||
|       .then(res => {
 | ||
|         console.log('mmmmm8', JSON.stringify(res))
 | ||
|         // @ts-ignore
 | ||
|         if (res.imageCompareRsp.head.resultCode == '0') {
 | ||
|           this.controller.stop()
 | ||
|           this.showFaceCompare = !this.showFaceCompare
 | ||
|           this.showFaceCompareFlag = !this.showFaceCompareFlag
 | ||
|           this.faceCompareSucess = 1;
 | ||
|           // this.faceCatchImg = result
 | ||
|           this.vocObj.playAudio({
 | ||
|             type: 1,
 | ||
|             name: 'yzcg.wav'
 | ||
|           })
 | ||
|         } else {
 | ||
|           this.times++;
 | ||
|           //3s后开始语音提示
 | ||
|           this.vocObj.playAudio({
 | ||
|             type: 1,
 | ||
|             name: 'face_fail.mp3'
 | ||
|           })
 | ||
| 
 | ||
|         }
 | ||
|       }).catch((err) => {
 | ||
|       console.log(err)
 | ||
|       this.times++;
 | ||
|       //3s后开始语音提示
 | ||
|       this.vocObj.playAudio({
 | ||
|         type: 1,
 | ||
|         name: 'face_fail.mp3'
 | ||
|       })
 | ||
|     })
 | ||
|     console.log('mmmmm8', 9)
 | ||
| 
 | ||
| 
 | ||
|   }
 | ||
| 
 | ||
|   async heartMsg(context) {
 | ||
|     let tmpList = []
 | ||
|     const str = this.lsh
 | ||
|     console.log('this.lshbitbit', this.lsh, globalThis.carInfo.carNo, globalThis.carInfo.examinationRoomId)
 | ||
|     for (let i = 0; i < str.length; i++) {
 | ||
|       tmpList.push(string2Bytes(str.charCodeAt(i), 1 * 8)[0])
 | ||
|     }
 | ||
|     const param = {
 | ||
|       id: 46,
 | ||
|       list: tmpList,
 | ||
|       carNo: globalThis.carInfo.carNo,
 | ||
|       placeId: globalThis.carInfo.examinationRoomId,
 | ||
|       sendCallback: () => {
 | ||
|         this.callBackFlag = true
 | ||
|       }
 | ||
|     }
 | ||
|     globalThis.udpClient2 && globalThis.udpClient2.sendMsgExt(param, this.context)
 | ||
|     clearInterval(this.interval)
 | ||
|     this.interval = setInterval(() => {
 | ||
|       if (this.callBackFlag) {
 | ||
|         const param2 = {
 | ||
|           id: 47,
 | ||
|           list: tmpList,
 | ||
|           carNo: globalThis.carInfo.carNo,
 | ||
|           placeId: globalThis.carInfo.examinationRoomId,
 | ||
|         }
 | ||
|         globalThis.udpClient2 && globalThis.udpClient2.sendMsgExt(param2, this.context)
 | ||
|       }
 | ||
|     }, 1000)
 | ||
|     globalThis.udpClient2.setMsgCallBack((val) => {
 | ||
|       console.log('valvalval', globalThis.statue, JSON.stringify(val))
 | ||
|       if (globalThis.statue != 3) {
 | ||
|         return
 | ||
|       }
 | ||
|       if (val.id == '48') {
 | ||
|         if (val.body[13] == '1') {
 | ||
|           this.showFaceCompareFlag = !this.showFaceCompareFlag
 | ||
|           this.showFaceCompare = !this.showFaceCompare
 | ||
|           this.vocObj && this.vocObj.releasePlayer()
 | ||
|           this.faceCompareSucess = 1
 | ||
|           clearInterval(this.interval)
 | ||
|         } else if (val.body[13] == '0' && this.callBackFlag) {
 | ||
|           globalThis.statue = 2
 | ||
|           this.vocObj && this.vocObj.playAudio({
 | ||
|             type: 1,
 | ||
|             name: 'face_chekc_fail.wav'
 | ||
|           })
 | ||
|         }
 | ||
|       }
 | ||
|     })
 | ||
| 
 | ||
|   }
 | ||
| 
 | ||
|   async getVideoConfig() {
 | ||
|     console.log('faceEnterIn')
 | ||
|     this.vocObj = new voiceService(async (status, val, next) => {
 | ||
|       if (status == 'idle') {
 | ||
|         if (val == 'face_check.mp3' || val == 'face_fail.mp3') {
 | ||
|           if (this.times >= 3) {
 | ||
|             globalThis.statue = 3
 | ||
|             this.faceCompareSucess = -1;
 | ||
|             this.vocObj && this.vocObj.playAudio({
 | ||
|               type: 1,
 | ||
|               name: 'face_checking.wav'
 | ||
|             })
 | ||
|             this.heartMsg(this.context)
 | ||
|           } else {
 | ||
|             setTimeout(() => {
 | ||
|               this.faceComparFn()
 | ||
|             }, 2000)
 | ||
|           }
 | ||
|         } else if (val == 'yzcg.wav') {
 | ||
|           this.showFaceCompare = !this.showFaceCompare
 | ||
|           this.showFaceCompareFlag = !this.showFaceCompareFlag
 | ||
|           globalThis.statue = 4
 | ||
|           this.faceCompareSucess = 1;
 | ||
|           this.vocObj && this.vocObj.releasePlayer()
 | ||
| 
 | ||
|         } else if (val == 'face_chekc_fail.wav') {
 | ||
|           this.vocObj && this.vocObj.releasePlayer()
 | ||
|           this.faceCompareSucess = -1
 | ||
|           this.showFaceCompare = !this.showFaceCompare
 | ||
|           this.showFaceCompareFlag = !this.showFaceCompareFlag
 | ||
|         }
 | ||
|       }
 | ||
|     });
 | ||
| 
 | ||
|     const data = await this.fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/config3.txt');
 | ||
|     console.log('faceEnterIn,data', data)
 | ||
| 
 | ||
|     setTimeout(() => {
 | ||
|       this.vocObj && this.vocObj.playAudio({
 | ||
|         type: 1,
 | ||
|         name: 'face_check.mp3'
 | ||
|       })
 | ||
|     }, 1000)
 | ||
|     this.param = JSON.parse(data)
 | ||
|     this.param.userName = JSON.parse(data).userName
 | ||
|     this.param.ip = this.param.ip
 | ||
|     this.param.pwd = this.param.pwd
 | ||
|     this.param.port = this.param.port
 | ||
|     this.param.rlls = this.param.rlls
 | ||
|     this.controller.start()
 | ||
|   }
 | ||
| 
 | ||
|   async aboutToDisappear() {
 | ||
|     clearInterval(this.interval)
 | ||
|   }
 | ||
| }
 | ||
| 
 |