当前位置:网站首页>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
边栏推荐
- 招标公告:福建省农村信用社联合社数据库审计系统采购项目(重新招标)
- torch. Numel action
- A link opens the applet code. After compilation, it is easy to understand
- Strengthen real-time data management, and the British software helps the security construction of the medical insurance platform
- 深度之眼(六)——矩阵的逆(附:logistic模型一些想法)
- 如何在shell中实现 backspace
- Talk about the cloud deployment of local projects created by SAP IRPA studio
- SysOM 案例解析:消失的内存都去哪了 !| 龙蜥技术
- js中复选框checkbox如何判定为被选中
- Mysql database backup script
猜你喜欢
The unity vector rotates at a point
企业级日志分析系统ELK
Logback logging framework third-party jar package is available for free
记一次项目的迁移过程
Xcode Revoke certificate
What are compiled languages and interpreted languages?
95. (cesium chapter) cesium dynamic monomer-3d building (building)
Rongyun won the 2022 China Xinchuang digital office portal excellence product award!
Eye of depth (VII) -- Elementary Transformation of matrix (attachment: explanation of some mathematical models)
Continuous creation depends on it!
随机推荐
95. (cesium chapter) cesium dynamic monomer-3d building (building)
Vs tool word highlight with margin
SPI master RX time out interrupt
thinkphp3.2.3中设置路由,优化url
记一次项目的迁移过程
Is it reliable to open an account on Tongda letter with your mobile phone? Is there any potential safety hazard in such stock speculation
Detailed explanation of several ideas for implementing timed tasks in PHP
过度依赖补助,大客户收款难,冲刺“国产数据库第一股”的达梦后劲有多足?
2022第四届中国(济南)国际智慧养老产业展览会,山东老博会
如何在shell中实现 backspace
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
How does laravel run composer dump autoload without emptying the classmap mapping relationship?
laravel怎么获取到public路径
AE learning 02: timeline
How to query the data of a certain day, a certain month, and a certain year in MySQL
深度之眼(六)——矩阵的逆(附:logistic模型一些想法)
10 schemes to ensure interface data security
Bidding announcement: Panjin people's Hospital Panjin hospital database maintenance project
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
Statistical learning method -- perceptron