324 lines
9.4 KiB
Plaintext
Raw Normal View History

2024-07-02 11:10:33 +08:00
import { voiceService } from '../../common/service/voiceService';
import { faceCompare } from '../../api/userInfo';
import FileUtil from '../../common/utils/File';
import { VideoConfig } from '../interfaces';
2024-06-04 14:18:44 +08:00
import common from '@ohos.app.ability.common';
2024-07-02 11:10:33 +08:00
import { string2Bytes } from '../../common/utils/tools';
import { takePhoto } from '../../common/service/videoService';
import { GlobalConfig } from '../../config/index';
import { VideoConfigData } from '../../mock';
2024-01-05 11:11:15 +08:00
@Component
2024-02-20 10:22:33 +08:00
export default struct FaceCompare {
2024-01-05 11:11:15 +08:00
@State imageBase64: string = 'data:image/jpeg;base64,'
2024-08-10 14:00:18 +08:00
@State base64: string = ''
2024-01-05 11:11:15 +08:00
@Prop sfzh: string;
2024-06-04 14:18:44 +08:00
@Prop lsh: string;
2024-01-05 11:11:15 +08:00
@Prop firstImage: string;
2024-06-04 14:18:44 +08:00
@Link faceCompareSucess: number;
2024-01-05 11:11:15 +08:00
@Link showFaceCompare: boolean;
2024-06-04 14:18:44 +08:00
@Link getqkFlag: boolean;
@Link faceCatchImg: string;
2024-01-05 11:11:15 +08:00
@State imageThumbnail: string = '';
2024-06-04 14:18:44 +08:00
@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;
2024-07-02 11:10:33 +08:00
@State param: VideoConfig = VideoConfigData
private times = 1; //人脸比对失败次数, 超过3次将不会自动比对需要点击重新打开重新触发
private vocObj = null;
private controller: VideoController = new VideoController()
2024-06-04 14:18:44 +08:00
private fileUtil: FileUtil
private interval: any
private context = getContext(this) as common.UIAbilityContext;
2024-06-04 11:19:22 +08:00
2024-07-02 11:10:33 +08:00
constructor() {
super()
}
2024-01-05 11:11:15 +08:00
build() {
Column() {
Column() {
Text('照片比对')
.lineHeight('16%')
.height('16%')
.fontWeight(FontWeight.Bold)
.fontSize(24)
Row() {
Row() {
2024-06-04 14:18:44 +08:00
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,
2024-01-05 11:11:15 +08:00
})
2024-06-04 14:18:44 +08:00
.muted(true)
2024-01-05 11:11:15 +08:00
.width('100%')
.height('100%')
2024-06-04 14:18:44 +08:00
.autoPlay(this.isAutoPlay)
.controls(this.showControls)
2024-01-05 11:11:15 +08:00
}
.width('48%')
.height('100%')
2024-06-04 14:18:44 +08:00
2024-01-05 11:11:15 +08:00
Row() {
2024-08-10 14:00:18 +08:00
Image(this.base64)
2024-01-05 11:11:15 +08:00
.width('100%')
.height('100%')
.backgroundColor(Color.Black)
}
.width('48%')
.height('100%')
}
.width('88.9%')
.height('53.2%')
.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;
2024-06-04 14:18:44 +08:00
2024-01-05 11:11:15 +08:00
})
}
.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(() => {
2024-06-04 14:18:44 +08:00
this.controller.stop()
this.vocObj && this.vocObj.releasePlayer()
this.showFaceCompare = !this.showFaceCompare
2024-07-02 11:10:33 +08:00
this.showFaceCompareFlag = !this.showFaceCompareFlag
2024-06-04 14:18:44 +08:00
this.faceCompareSucess = -1
globalThis.statue = 2
2024-01-05 11:11:15 +08:00
})
}
.width('100%')
.height('100%')
.backgroundColor('rgba(0, 0, 0, 0.8)')
.position({ x: 0, y: 0 })
}
onPageShow() {
}
async aboutToAppear() {
2024-06-04 14:18:44 +08:00
const fileUtil = new FileUtil(this.context)
this.fileUtil = fileUtil
this.getVideoConfig()
2024-01-05 11:11:15 +08:00
}
2024-06-04 14:18:44 +08:00
clearIntervalFn() {
this.callBackFlag = false
clearInterval(this.interval)
this.vocObj && this.vocObj.releasePlayer()
2024-01-05 11:11:15 +08:00
}
2024-06-04 14:18:44 +08:00
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
}
2024-07-09 11:11:31 +08:00
globalThis.udpClient2.sendMsgExt(param, this.context)
2024-01-05 11:11:15 +08:00
}
2024-06-04 14:18:44 +08:00
async faceComparFn() {
2024-08-10 14:00:18 +08:00
console.log('mmmmm0', 2)
2024-08-14 09:18:33 +08:00
this.param.pztd=this.param.rlls
2024-08-10 14:00:18 +08:00
const data=await takePhoto(this.param, this.context, 'jt/', 1,)
this.base64=this.imageBase64 + data.base64
console.log('mmmmt',this.base64)
faceCompare({
sfzh: this.sfzh,
firstImage: this.firstImage.substr(22),
secondImage: data.base64,
type: 2,
verifyType: 1
})
.then(res => {
2024-07-02 11:10:33 +08:00
console.log('mmmmm8', res)
2024-01-05 11:11:15 +08:00
if (res) {
2024-06-04 14:18:44 +08:00
this.controller.stop()
this.showFaceCompare = !this.showFaceCompare
2024-07-02 11:10:33 +08:00
this.showFaceCompareFlag = !this.showFaceCompareFlag
2024-06-04 14:18:44 +08:00
this.faceCompareSucess = 1;
// this.faceCatchImg = result
this.vocObj.playAudio({
type: 1,
name: 'yzcg.wav'
})
2024-01-05 11:11:15 +08:00
} else {
2024-06-04 14:18:44 +08:00
this.times++;
2024-01-05 11:11:15 +08:00
//3s后开始语音提示
2024-06-04 14:18:44 +08:00
this.vocObj.playAudio({
type: 1,
name: 'face_fail.mp3'
})
2024-01-05 11:11:15 +08:00
}
})
2024-07-02 11:10:33 +08:00
console.log('mmmmm8', 9)
2024-06-04 14:18:44 +08:00
}
async heartMsg(context) {
let tmpList = []
const str = this.lsh
2024-07-02 11:10:33 +08:00
for (let i = 0; i < str.length; i++) {
2024-06-04 14:18:44 +08:00
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
}
}
2024-07-09 11:11:31 +08:00
globalThis.udpClient2 && globalThis.udpClient2.sendMsgExt(param, this.context)
2024-06-04 14:18:44 +08:00
clearInterval(this.interval)
this.interval = setInterval(() => {
if (this.callBackFlag) {
const param2 = {
id: 47,
list: tmpList,
carNo: globalThis.carInfo.carNo,
placeId: globalThis.carInfo.examinationRoomId,
}
2024-07-09 11:11:31 +08:00
globalThis.udpClient2 && globalThis.udpClient2.sendMsgExt(param2, this.context)
2024-06-04 14:18:44 +08:00
}
}, 1000)
globalThis.udpClient2.setMsgCallBack((val) => {
if (val.id == '48') {
if (val.body[13] == '1') {
2024-07-02 11:10:33 +08:00
this.showFaceCompareFlag = !this.showFaceCompareFlag
2024-06-04 14:18:44 +08:00
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
2024-07-02 11:10:33 +08:00
this.showFaceCompareFlag = !this.showFaceCompareFlag
2024-06-04 14:18:44 +08:00
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
2024-07-02 11:10:33 +08:00
this.showFaceCompareFlag = !this.showFaceCompareFlag
2024-06-04 14:18:44 +08:00
}
2024-01-05 11:11:15 +08:00
}
});
2024-06-04 14:18:44 +08:00
const data = await this.fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/config3.txt');
2024-07-02 11:10:33 +08:00
console.log('faceEnterIn,data', data)
2024-06-04 14:18:44 +08:00
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()
2024-01-05 11:11:15 +08:00
}
2024-06-04 14:18:44 +08:00
async aboutToDisappear() {
2024-01-05 11:11:15 +08:00
}
}