当前位置:网站首页>PHP实现微信小程序人脸识别刷脸登录功能
PHP实现微信小程序人脸识别刷脸登录功能
2022-07-07 14:07:00 【全栈程序员站长】
首先我们先确认我们的百度云人脸库里已经上传了我们的个人信息照片
然后我们在后台写刷脸登陆的接口login我们要把拍照获取的照片存储到服务器
public function login(){
// 上传文件路径
$dir = "./Uploads/temp/";
if(!file_exists($dir)){
mkdir($dir,0777,true);
}
$upload = new \Think\Upload();
$upload->maxSize = 2048000 ;// 设置附件上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->savepath = '';
$upload->autoSub = false;
$upload->rootPath = $dir; // 设置附件上传根目录
// 上传单个文件
$info = $upload->uploadOne($_FILES['file']);
if(!$info) {
// 上传错误提示错误信息
echo json_encode(array('error'=>true,'msg'=>$upload->getError()),JSON_UNESCAPED_UNICODE);
}else{
// 上传成功 获取上传文件信息
$file = $dir . $info['savepath'].$info['savename'];
$image = base64_encode(file_get_contents($file));
$client = $this->init_face();
$options['liveness_control'] = 'NORMAL';
$options['max_user_num'] = '1';
$ret = $client->search($image,'BASE64','student',$options);
// echo json_encode($ret,JSON_UNESCAPED_UNICODE);
// exit;
if($ret['error_code']==0){
$user = $ret['result']['user_list'][0];
$no = $user['user_id'];
$score = $user['score'];
if($score>=95){
$data = M('student')->where("no = '{$no}'")->find();
$data['score'] = $score;
// $data['name'] = json_decode($data['name'],true);
// $data['sex'] = json_decode($data['sex'],true);
echo '识别成功' . json_encode($data,JSON_UNESCAPED_UNICODE);
}else{
echo '识别失败' . $data['score'];
}
}
}
}
然后进行前台设计
<camera device-position="{
{device?'back':'front'}}" flash="off" binderror="error" style="width: 100%; height: 300px;"></camera>
<view class="weui-cells__title" >开关</view>
<view class="weui-cells weui-cells_after-title">
<view class="weui-cell weui-cell_switch">
<view class="weui-cell__bd">切换摄像头</view>
<view class="weui-cell__ft" >
<switch bindtap="devicePosition" />
</view>
</view>
</view>
<button type="primary" bindtap="takePhoto">刷脸登录</button>
我们还可以控制相机的前后镜头
devicePosition() {
this.setData({
device: !this.data.device,
})
console.log("当前相机摄像头为:", this.data.device ? "后置" : "前置");
camera() {
let { ctx, type, startRecord } = this.data; },
data: {
src: null,
},
在js里面调用接口
takePhoto() {
const ctx = wx.createCameraContext()
ctx.takePhoto({
quality: 'high',
success: (res) => {
this.setData({
src: res.tempImagePath
})
console.log(res)
wx.uploadFile({
url: '', //仅为示例,非真实的接口地址
filePath: this.data.src,
name: 'file',
formData: {
},
success: function (res) {
// var data = res.data
// var json = JSON.parse(data)
console.log(res)
wx.showModal({
title: "提示",
content: res.data,
showCancel: false,
confirmText: "确定"
})
}
})
}
})
},
刷脸登录就成功了
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/113179.html原文链接:https://javaforall.cn
边栏推荐
- AE learning 01: AE complete project summary
- Shandong old age Expo, 2022 China smart elderly care exhibition, smart elderly care and aging technology exhibition
- Logback日志框架第三方jar包 免费获取
- 2022 the 4th China (Jinan) International Smart elderly care industry exhibition, Shandong old age Expo
- How to implement backspace in shell
- 星瑞格数据库入围“2021年度福建省信息技术应用创新典型解决方案”
- Detailed explanation of unity hot update knowledge points and introduction to common solution principles
- leetcode 241. Different ways to add parentheses design priority for operational expressions (medium)
- Sysom case analysis: where is the missing memory| Dragon lizard Technology
- Good news! Kelan sundb database and Hongshu technology privacy data protection management software complete compatibility adaptation
猜你喜欢
20th anniversary of agile: a failed uprising
Shipping companies' AI products are mature, standardized and applied on a large scale. CIMC, the global leader in port and shipping AI / container AI, has built a benchmark for international shipping
Three. JS introductory learning notes 15: threejs frame animation module
You Yuxi, coming!
Numpy -- data cleaning
航運船公司人工智能AI產品成熟化標准化規模應用,全球港航人工智能/集裝箱人工智能領軍者CIMC中集飛瞳,打造國際航運智能化標杆
深度之眼(六)——矩阵的逆(附:logistic模型一些想法)
Postman generate timestamp, future timestamp
航运船公司人工智能AI产品成熟化标准化规模应用,全球港航人工智能/集装箱人工智能领军者CIMC中集飞瞳,打造国际航运智能化标杆
What about the pointer in neural network C language
随机推荐
three.js打造酷炫下雪效果
C Alibaba cloud OSS file upload, download and other operations (unity is available)
Dotween -- ease function
深度之眼(七)——矩阵的初等变换(附:数模一些模型的解释)
如何在shell中实现 backspace
Regular expression string
模仿企业微信会议室选择
Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!
Limit of total fields [1000] in index has been exceeded
SysOM 案例解析:消失的内存都去哪了 !| 龙蜥技术
山东老博会,2022中国智慧养老展会,智能化养老、适老科技展
保证接口数据安全的10种方案
统计学习方法——感知机
MySQL中, 如何查询某一天, 某一月, 某一年的数据
Vs tool word highlight with margin
Apache Doris刚“毕业”:为什么应关注这种SQL数据仓库?
JS array foreach source code parsing
Sysom case analysis: where is the missing memory| Dragon lizard Technology
谈谈 SAP iRPA Studio 创建的本地项目的云端部署问题
iptables只允许指定ip地址访问指定端口