创建一个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-