信呼OA版本v2.3.8

This commit is contained in:
雨中磐石
2022-08-14 16:47:40 +08:00
parent 4640677d27
commit e3fcd913e3
1405 changed files with 133635 additions and 73 deletions

View File

@@ -0,0 +1,164 @@
<?php
class txcloud_renlianClassModel extends txcloudModel
{
public function inittxCloud()
{
$this->settable('wxtx_renlian');
$this->groupid = $this->option->getval('txcloud_rlroupid');
}
/**
* 人脸检测
*/
public function DetectFace($url)
{
$chul = $this->DetectFaceInit($url);
$barr = $this->send('DetectFace', $chul[0], $chul[1]);
return $barr;
}
private function DetectFaceInit($url)
{
$chul = $chul1 = array();
if(substr($url,0,4)=='http'){
$chul['Url'] = $url;
}else{
$chul['Image'] = base64_encode(file_get_contents($url));
$chul1['Image'] = $chul['Image'];
}
return array($chul, $chul1);
}
/**
* 获取
*/
public function GetPersonList()
{
$barr = $this->send('GetPersonList', array(
'GroupId' => $this->groupid,
'Limit' => 1000
));
if($barr['success']){
$data = $barr['data'];
$PersonInfos = $data['PersonInfos'];
$ids = '0';
$ren = 0;
foreach($PersonInfos as $k=>$rs){
$ren++;
$PersonId = $rs['PersonId'];
$where = "`personid`='$PersonId'";
$id1 = (int)$this->getmou('id', $where);
if($id1==0)$where='';
$this->record(array(
'personid' => $PersonId,
'personname' => $rs['PersonName'],
'gender' => $rs['Gender'],
'faceids' => join(',', $rs['FaceIds'])
), $where);
if($id1==0)$id1 = $this->db->insert_id();
$ids .= ','.$id1.'';
}
$this->delete("`id` not in($ids)");
return returnsuccess('共获取到'.$ren.'人');
}
return $barr;
}
public function GetGroupList()
{
$barr = $this->send('GetGroupList');
return $barr;
}
/**
* 删除人脸用户
*/
public function deleteRenlian($id)
{
$rs = $this->getone("`id`='$id'");
if(!$rs)return returnerror('不存在');
$barr = $this->send('DeletePerson', array(
'PersonId' => $rs['personid']
));
if($barr['success']){
$this->delete($id);
}
return $barr;
}
/**
* 创建人脸用户
*/
public function createUser($arr)
{
$id = $arr['id'];
$uid = $arr['uid'];
$personname = $arr['personname'];
$imgurl = $arr['imgurl'];
if($this->rows("`uid`='$uid' and `id`<>'$id'")>0)return returnerror('该用户已经创建过了');
$urs = m('admin')->getone("`id`='$uid' and `status`=1");
if(!$urs)return returnerror('该用户不存在/停用了,请到用户管理查看');
if($id==0 && isempt($imgurl))return returnerror('请选择人脸图片地址');
if(!isempt($imgurl) && substr($imgurl,0,4)!='http'){
if(!file_exists($imgurl))return returnerror('人脸图片不存在');
list($width, $height) = getimagesize($imgurl);
if($width< 60 || $height<60)return returnerror('人脸图片像素至少60x60当前:'.$width.'x'.$height.'');
$size = filesize($imgurl);
if($size>1*1024*1024)return returnerror('人脸图片不能大于1M');
}
//检测人脸是否可以
$barr = $this->DetectFace($imgurl);
if(!$barr['success'])return $barr;
if($id==0){
$can = $this->DetectFaceInit($imgurl);
$params = $can[0];
$params['GroupId'] = $this->groupid;
$params['PersonName'] = $personname;//姓名
$params['PersonId'] = 'xinhu'.$urs['user'].'';
$params['Gender'] = $urs['sex']=='男' ? '1': '2';
//接口创建
$barr = $this->send('CreatePerson',$params, $can[1]);
if(!$barr)return $barr;
$id = $this->insert(array(
'personname'=> $personname,
'personid' => $params['PersonId'],
'gender' => $params['Gender'],
'uid' => $uid,
'imgurl' => $imgurl,
'faceids' => $barr['data']['FaceId'],
));
}else{
}
return returnsuccess();
}
/**
* 人脸搜索,用刷脸登录
*/
public function SearchFaces()
{
$can = $this->DetectFaceInit('images/wo.png');
$params = $can[0];
$params['GroupIds.0'] = $this->groupid;
$barr = $this->send('SearchFaces', $params, $can[1]);
return $barr;
}
}

View File

@@ -0,0 +1,72 @@
<?php
class txcloudModel extends Model
{
private $SecretId = '';
private $SecretKey = '';
//api地址[这个是人脸识别上的]
public $apiurl = 'iai.tencentcloudapi.com';
public function inittxCloud(){}
public function initModel()
{
$this->option = m('option');
$this->SecretId = $this->rock->jm->uncrypt($this->option->getval('txcloud_secretid'));
$this->SecretKey = $this->rock->jm->uncrypt($this->option->getval('txcloud_secretkey'));
$this->inittxCloud();
}
//创建签名和参数
private function createAuth($can = array())
{
$barr['Action'] = '';
$barr['Region'] = ''; //地区
$barr['SecretId'] = $this->SecretId;
$barr['Timestamp'] = time();
$barr['Nonce'] = rand(10000,99999);
$barr['Version'] = '2018-03-01';
foreach($can as $k=>$v)$barr[$k] = $v;
ksort($barr);
$str = '';
foreach($barr as $k=>$v)$str.='&'.$k.'='.$v.'';
$str = substr($str, 1);
$srcStr = 'POST'.$this->apiurl.'/?'.$str.'';
$signStr = base64_encode(hash_hmac('sha1', $srcStr, $this->SecretKey, true));
$barr['Signature'] = urlencode($signStr);
return $barr;
}
/**
* 发送请求 $Action方法其他参数
*/
public function send($Action, $can = array(), $njcan=array())
{
if(isempt($this->SecretId) || isempt($this->SecretKey))return returnerror('没有完整配置腾讯云api密钥');
$can['Action'] = $Action;
$params = $this->createAuth($can);
$url = 'https://'.$this->apiurl.'';
foreach($njcan as $k=>$v)$params[$k]= urlencode($v);
$result = c('curl')->postjson($url, $params);
if(isempt($result))return returnerror('无法访问接口');
$barr = json_decode($result, true);
if(!isset($barr['Response']))return returnerror('返回出错'.$result.'');
$Response = $barr['Response'];
if(isset($Response['Error'])){
$error = $Response['Error'];
return returnerror('error:'.$error['Message'].','.$error['Code'].'');
}
return returnsuccess($Response);
}
}