当前位置:网站首页>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
边栏推荐
- 谈谈 SAP iRPA Studio 创建的本地项目的云端部署问题
- TiDB For PostgreSQL和YugabyteDB在Sysbench上的性能对比
- Tragedy caused by deleting the console statement
- 【花雕体验】15 尝试搭建Beetle ESP32 C3之Arduino开发环境
- What is the difference between IP address and physical address
- 星瑞格数据库入围“2021年度福建省信息技术应用创新典型解决方案”
- 航運船公司人工智能AI產品成熟化標准化規模應用,全球港航人工智能/集裝箱人工智能領軍者CIMC中集飛瞳,打造國際航運智能化標杆
- Enterprise log analysis system elk
- Statistical learning method -- perceptron
- C4D learning notes 2- animation - timeline and time function
猜你喜欢
torch. Numel action
What are compiled languages and interpreted languages?
Xingruige database was shortlisted as the "typical solution for information technology application and innovation in Fujian Province in 2021"
深度之眼(六)——矩阵的逆(附:logistic模型一些想法)
L'application à l'échelle de la normalisation mature des produits ai des compagnies maritimes, cimc, leader mondial de l'intelligence artificielle portuaire et maritime / intelligence artificielle des
Xcode Revoke certificate
AE learning 01: AE complete project summary
C4D learning notes 1- animation - animation key frames
喜讯!科蓝SUNDB数据库与鸿数科技隐私数据保护管理软件完成兼容性适配
星瑞格数据库入围“2021年度福建省信息技术应用创新典型解决方案”
随机推荐
Three. Introduction to JS learning notes 17: mouse control of 3D model rotation of JSON file
分步式監控平臺zabbix
Multiplication in pytorch: mul (), multiply (), matmul (), mm (), MV (), dot ()
Step by step monitoring platform ZABBIX
Odoo integrated plausible embedded code monitoring platform
通知Notification使用全解析
TCP framework___ Unity
Particle effect for ugui
hellogolang
Laravel5.1 路由 -路由分组
JS 模块化
How to query the data of a certain day, a certain month, and a certain year in MySQL
如何在shell中实现 backspace
2022 the 4th China (Jinan) International Smart elderly care industry exhibition, Shandong old age Expo
AE learning 01: AE complete project summary
three.js打造酷炫下雪效果
Is it reliable to open an account on Tongda letter with your mobile phone? Is there any potential safety hazard in such stock speculation
Odoo集成Plausible埋码监控平台
Application example of infinite list [uigridview]
TiDB For PostgreSQL和YugabyteDB在Sysbench上的性能对比