Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

faceauthview

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

faceauthview - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

src/assets/renlian.png

8

package.json
{
"name": "faceauthview",
"version": "1.0.0",
"version": "1.0.1",
"description": "微信小程序自定义人脸识别组件",
"main": "index.js",
"miniprogram": "src",
"files": [
"src",
"package.json"
],
"scripts": {

@@ -12,2 +16,2 @@ "test": "echo \"Error: no test specified\" && exit 1"

"license": "ISC"
}
}
Component({
properties: {
// 这里定义了innerText属性,属性值可以在组件使用时指定
innerText: {
idcard: {
type: String,
value: 'default value',
value: '',
},
name: {
type: String,
value: '',
}
},
lifetimes: {
attached: function () {
this.initCamera()
this.getCode()
},
detached: function () {
// 在组件实例被从页面节点树移除时执行
},
},
data: {
// 这里是一些组件内部数据
someData: {}
isPrepare: true,
RandomNumber: [0, 0, 0, 0],
TokenRandomNumber: '',
//waiting : 未开始 ;starting : 录制中; verify : 认证中; end: 结果
recordStatus: 'waiting',
recordTime: 5
},
methods: {
// 这里是一个自定义方法
customMethod: function(){}
/**
* 初始化摄像头
*/
initCamera: function () {
console.log(`[faceAuthView] : 初始化摄像头`)
this.ctx = wx.createCameraContext()
},
/**
* 设置准备状态
*/
setPrepare: function () {
this.setData({
isPrepare: false
})
},
/**
* 获取四位随机数
*/
async getCode() {
const that = this
wx.request({
method: 'post',
url: 'https://negdev.coolaw.com/api/identityCheck/identity/getRandomNumber',
header: {
'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
},
success: response => {
if (response.data.statusCode === 0) {
console.log(`[faceAuthView] : 请求随机码成功`)
that.setData({
RandomNumber: response.data.data.RandomNumber.split(''),
TokenRandomNumber: response.data.data.TokenRandomNumber
})
} else {
console.log(`[faceAuthView] : 请求随机码异常`)
this.triggerEvent('authFail', {
message: '请求随机码异常'
})
}
}
})
},
/**
* 开始录像
*/
startRecord: function () {
this.ctx.startRecord().then(() => {
this.setData({
recordStatus: 'starting'
})
const recordInterval = setInterval(() => {
const recordTime = this.data.recordTime - 1
if (recordTime === 0) {
clearInterval(recordInterval)
this.setData({
recordStatus: 'verify'
})
this.stopRecord()
} else {
this.setData({
recordTime: recordTime
})
}
}, 1000)
}).catch(error => {
console.log(`[faceAuthView] : 开始录制失败`)
console.log(error)
this.triggerEvent('authFail', {
message: '开始录制失败'
})
})
},
/**
* 结束录制
*/
stopRecord() {
wx.showLoading({
title: '视频处理中',
mask: false
})
this.ctx.stopRecord({
compressed: true
}).then((result) => {
console.log(`[faceAuthView] : 停止录制,获取视频地址 : ${result.tempVideoPath}`)
wx.hideLoading()
this.getVideoBase64(result.tempVideoPath)
}).catch(error => {
wx.hideLoading()
console.log(`[faceAuthView] : 停止录制失败`)
console.log(error)
this.triggerEvent('authFail', {
message: '停止录制失败'
})
})
},
/**
* 验证录制文件
*/
getVideoBase64(tempVideoPath) {
wx.showLoading({
title: '认证中',
mask: true
})
const that = this
const fs = wx.getFileSystemManager()
fs.readFile({
filePath: tempVideoPath,
encoding: 'base64',
position: 0,
success: function (result) {
console.log(`[faceAuthView] : 视频处理成base64格式结束`)
wx.hideLoading()
that.auth(result.data)
},
fail: function (error) {
wx.hideLoading()
wx.showToast({
icon: 'error',
title: '视频处理失败',
})
}
})
},
auth(data) {
console.log(`[faceAuthView] : 调用API认证结果`)
const that = this
wx.request({
url: 'https://negdev.coolaw.com/api/identityCheck/identity/videoValidate',
method: 'post',
data: {
base64VideoStr: data,
tokenRandomNumber: this.data.TokenRandomNumber,
identificationNo: this.data.idcard,
realName: this.data.name
},
success: response => {
if (response.data.statusCode === 0) {
console.log(`[faceAuthView] : 调用API认证成功`)
this.triggerEvent('authSuccess')
} else {
this.triggerEvent('authFail', {
message: '调用认证接口返回异常'
})
this.setData({
recordStatus: 'waiting'
})
wx.showToast({
title: '认证失败',
})
}
},
fail: error => {
console.log(`catch到异常`)
console.log(error)
}
})
}
}
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc