当前位置:网站首页>PHP realizes wechat applet face recognition and face brushing login function
PHP realizes wechat applet face recognition and face brushing login function
2022-07-07 16:21:00 【Full stack programmer webmaster】
First, we confirm that our personal information photos have been uploaded in our Baidu cloud face database
Then we write the interface of face brushing login in the background login We need to store the photos taken to the server
public function login(){
// Upload file path
$dir = "./Uploads/temp/";
if(!file_exists($dir)){
mkdir($dir,0777,true);
}
$upload = new \Think\Upload();
$upload->maxSize = 2048000 ;// Set attachment upload size
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// Set attachment upload type
$upload->savepath = '';
$upload->autoSub = false;
$upload->rootPath = $dir; // Set the attachment upload root
// Upload a single file
$info = $upload->uploadOne($_FILES['file']);
if(!$info) {
// Upload error message
echo json_encode(array('error'=>true,'msg'=>$upload->getError()),JSON_UNESCAPED_UNICODE);
}else{
// Upload successful Get upload file information
$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 ' Recognition success ' . json_encode($data,JSON_UNESCAPED_UNICODE);
}else{
echo ' Recognition failed ' . $data['score'];
}
}
}
}Then carry out the front desk design
<camera device-position="{
{device?'back':'front'}}" flash="off" binderror="error" style="width: 100%; height: 300px;"></camera>
<view class="weui-cells__title" > switch </view>
<view class="weui-cells weui-cells_after-title">
<view class="weui-cell weui-cell_switch">
<view class="weui-cell__bd"> Switch cameras </view>
<view class="weui-cell__ft" >
<switch bindtap="devicePosition" />
</view>
</view>
</view>
<button type="primary" bindtap="takePhoto"> Swipe your face and log in </button>We can also control the front and rear lenses of the camera
devicePosition() {
this.setData({
device: !this.data.device,
})
console.log(" The current camera is :", this.data.device ? " After " : " In front of ");
camera() {
let { ctx, type, startRecord } = this.data; },
data: {
src: null,
},stay js It calls the interface
takePhoto() {
const ctx = wx.createCameraContext()
ctx.takePhoto({
quality: 'high',
success: (res) => {
this.setData({
src: res.tempImagePath
})
console.log(res)
wx.uploadFile({
url: '', // Just for the sample , Unreal interface address
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: " Tips ",
content: res.data,
showCancel: false,
confirmText: " determine "
})
}
})
}
})
},You can log in successfully by brushing your face
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/113179.html Link to the original text :https://javaforall.cn
边栏推荐
- 【知识小结】PHP使用svn笔记总结
- Numpy -- data cleaning
- Notification uses full resolution
- Unity的三种单例模式(饿汉,懒汉,MonoBehaviour)
- Unity3D_ Class fishing project, control the distance between collision walls to adapt to different models
- 深度之眼(七)——矩阵的初等变换(附:数模一些模型的解释)
- Leetcode-231-2的幂
- Sysom case analysis: where is the missing memory| Dragon lizard Technology
- 安科瑞电网智能化发展的必然趋势电力系统采用微机保护装置是
- TiDB For PostgreSQL和YugabyteDB在Sysbench上的性能对比
猜你喜欢

记一次项目的迁移过程

Strengthen real-time data management, and the British software helps the security construction of the medical insurance platform

统计学习方法——感知机

平衡二叉树(AVL)

Xingruige database was shortlisted as the "typical solution for information technology application and innovation in Fujian Province in 2021"

2022 the 4th China (Jinan) International Smart elderly care industry exhibition, Shandong old age Expo

过度依赖补助,大客户收款难,冲刺“国产数据库第一股”的达梦后劲有多足?

星瑞格数据库入围“2021年度福建省信息技术应用创新典型解决方案”

模仿企业微信会议室选择

Continuous creation depends on it!
随机推荐
Three. JS introductory learning notes 19: how to import FBX static model
iptables只允许指定ip地址访问指定端口
Laravel 中config的用法
星瑞格数据库入围“2021年度福建省信息技术应用创新典型解决方案”
谈谈 SAP iRPA Studio 创建的本地项目的云端部署问题
C4D learning notes 2- animation - timeline and time function
You Yuxi, coming!
Step by step monitoring platform ZABBIX
Bidding announcement: Fujian Rural Credit Union database audit system procurement project (re bidding)
Shader basic UV operations, translation, rotation, scaling
Performance measure of classification model
Xcode Revoke certificate
Three singleton modes of unity (hungry man, lazy man, monobehavior)
JS modularization
Shader_ Animation sequence frame
一个普通人除了去工厂上班赚钱,还能干什么工作?
Talk about the cloud deployment of local projects created by SAP IRPA studio
Is it reliable to open an account on Tongda letter with your mobile phone? Is there any potential safety hazard in such stock speculation
[hcsd celebrity live broadcast] teach the interview tips of big companies in person - brief notes
three.js打造酷炫下雪效果