更新记录
1.0.1(2025-12-18)
v1.0.1
1.0.0(2025-12-18)
v1.0.0
平台兼容性
uni-app(4.72)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| √ | √ | - | - | √ | √ | √ | √ | - |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|
| - | - | - | - | - | - | - | - | - | - | - |
uni-app x(4.85)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| - | - | √ | √ | - | - |
ainuo-faceplus
一个基于 UniApp UTS 的离线人脸活体检测插件,适用于考勤打卡、人脸采集等场景独立运行无需依赖第三方平台。
📌 功能特点
- ✅ 离线人脸活体检测
- ✅ 支持多种动作验证(眨眼、张嘴、转头等)
- ✅ 自定义检测步骤和超时时间
- ✅ 返回人脸图片路径
- ✅ 支持 Android 和 iOS 平台
🚀 快速开始
安装插件
将 uni_modules/ainuo-faceplus 目录放入你的项目中。
基础用法
<template>
<view>
<button @click="startDetection">开始人脸检测</button>
</view>
</template>
<script>
import { startLivenessDetection } from '@/uni_modules/ainuo-faceplus'
export default {
methods: {
startDetection() {
startLivenessDetection({
stepCount: 3, // 检测步骤数量
timeoutSeconds: 15, // 超时时间(秒)
stepTypes: [1, 2, 3] // 可选:自定义动作类型
}, (result) => {
if (result.status === 1) {
console.log('检测成功,图片路径:', result.path)
// 处理人脸图片
} else {
console.log('检测失败或取消')
}
})
}
}
}
</script>
📖 API 文档
startLivenessDetection(options, callback)
启动人脸活体检测。
参数说明
options (Object)
| 参数名 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| stepCount | Number | 否 | 3 | 需要完成的检测动作数量,范围 1-5 |
| timeoutSeconds | Number | 否 | 15 | 检测超时时间(秒) |
| stepTypes | Array |
否 | 自动 | 自定义动作序列,不传则随机 |
stepTypes 动作类型说明:
1- 眨眼2- 张嘴3- 左转头4- 右转头5- 点头
callback (Function)
检测完成后的回调函数,接收一个 result 对象:
| 字段 | 类型 | 说明 |
|---|---|---|
| status | Number | 1 成功,0 失败/取消 |
| path | String | 成功时返回人脸图片的本地路径 |
💡 完整示例
<template>
<view class="container">
<button type="primary" @click="quickStart">快速检测(默认配置)</button>
<button type="default" @click="customStart">自定义检测</button>
<image v-if="faceImage" :src="faceImage" mode="aspectFit"></image>
</view>
</template>
<script>
import { startLivenessDetection } from '@/uni_modules/ainuo-faceplus'
export default {
data() {
return {
faceImage: ''
}
},
methods: {
// 快速开始(使用默认参数)
quickStart() {
startLivenessDetection({}, (result) => {
this.handleResult(result)
})
},
// 自定义配置
customStart() {
startLivenessDetection({
stepCount: 4, // 4个动作
timeoutSeconds: 20, // 20秒超时
stepTypes: [1, 2, 3, 4] // 眨眼、张嘴、左转、右转
}, (result) => {
this.handleResult(result)
})
},
// 处理结果
handleResult(result) {
if (result.status === 1) {
this.faceImage = result.path
uni.showToast({
title: '检测成功',
icon: 'success'
})
// 可以将图片上传到服务器
// this.uploadImage(result.path)
} else {
uni.showToast({
title: '检测失败或取消',
icon: 'none'
})
}
},
// 上传图片示例
uploadImage(filePath) {
uni.uploadFile({
url: 'https://your-server.com/api/upload',
filePath: filePath,
name: 'face',
success: (res) => {
console.log('上传成功', res)
}
})
}
}
}
</script>
<style>
.container {
padding: 40rpx;
}
button {
margin-bottom: 20rpx;
}
image {
width: 100%;
height: 500rpx;
margin-top: 40rpx;
}
</style>
🔧 平台配置
iOS 配置
在 manifest.json 中添加相机和麦克风权限:
{
"app-plus": {
"privacy": {
"NSCameraUsageDescription": "需要使用相机进行人脸检测",
"NSMicrophoneUsageDescription": "需要使用麦克风"
}
}
}
Android 配置
Android 平台会自动处理权限请求,无需额外配置。
📱 应用场景
✅ 适用场景
- 企业内部考勤打卡
- 会员注册人脸采集
- 简单的身份验证
- 活动签到
- 社区门禁
❌ 不适用场景
- 金融支付验证(需要更高安全级别)
- 大规模商业部署
- 需要防伪能力的核心业务
- 对准确率有极高要求的场景

收藏人数:
购买源码授权版(
试用
使用 HBuilderX 导入示例项目
赞赏(0)
下载 520
赞赏 0
下载 12411435
赞赏 1829
赞赏
京公网安备:11010802035340号