微信小程序--刷脸认证(人脸识别入百度云人脸库)

本文介绍了如何在ThinkPHP3框架下开发微信小程序,实现了人脸识别功能并接入百度云人脸库。首先,创建了一个TP3的项目,并在其中编写了公共函数,接着在IndexController中初始化人脸识别流程。内容涵盖获取小组、删除小组的操作,以及人脸识别、上传文件和小程序页面的开发,包括小程序首页和上传照片页面的实现。
摘要由CSDN通过智能技术生成

创建一个thinkphp3的框架,创建一个小程序。

在tp3框架里创建公共文件,function.php,生成guid

//生成guid
function guid(){
	if(function_exists('com_create_guid')){
		return com_create_guid();
	}else{
		mt_srand((double)microtime()*10000);
		$charid = strtoupper(md5(uniqid(rand(),true)));
		$hyphen = chr(45);
		$uuid   = chr(123)
		         .substr($charid,0,8).$hyphen
		         .substr($charid,8,4).$hyphen
		         .substr($charid,12,4).$hyphen
		         .substr($charid,16,4).$hyphen
		         .substr($charid,20,12)
		         .chr(125);
		return $uuid;
	}
}

//生成变种guid
function myguid(){
	$guid = guid();
	$guid = trim($guid,'{}');
	$guid = str_replace('-', '_', $guid);
	return $guid;
}

然后创建indexcontroller.class.php

初始化人脸识别

//初始化人脸识别
	private function init_face(){
        $APP_ID='*****';
        $API_KEY='*****';
        $SECRET_KEY='****';
        $dir=APP_PATH . '/face_sdk/';
        require_once $dir . 'AipFace.php';
        return new \AipFace($APP_ID,$API_KEY,$SECRET_KEY);
	}
	public function index($no,$name,$sex,$age){
		$data['no']=$no;
		$data['name']=$name;
		$data['sex']=$sex;
		$data['age']=$age;
		$data['guid'] = myguid();
		$id=M('student')->add($data);
		if($id){
			return $this->ajaxReturn(array('error'=>false,'msg'=>'添加成功!','guid'=>$student['guid']));
		}else{
			return $this->ajaxReturn(array('error'=>true,'msg'=>'添加出错'));
		}
	}

获取小组

private function face_group(){
   	//组名
   	$groupname='1002';

   	$client=$this->init_face();
   	$ret=$client-
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值