代码拉取完成,页面将自动刷新
同步操作将从 Bygones/PHP-DouyinRobot 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<?php
class AI
{
protected $appkey="R2tqFEW4gJWY4SSp";
protected $appid = "2117414489";
/**
* Describe:获取图片信息
* @Author: Bygones
* Date: 2019-06-15
* Time: 23:05
* @param string $img
* @return array
*/
public function get(string $img):array
{
$data = file_get_contents($img);
$img = base64_encode($data);
$params = [
'app_id' => $this->appid,
'image' => $img,
'mode' => '1',
'time_stamp' => strval(time()),
'nonce_str' => strval(rand()),
'sign' => '',
];
$params['sign'] = $this->getReqSign((array) $params, (string) $this->appkey);
$url = 'https://api.ai.qq.com/fcgi-bin/face/face_detectface';
$response = $this->doHttpPost((string) $url, (array) $params);
$response = json_decode($response,true);
if($response["ret"] === 0){
$response["data"] = [
"gender"=>$response["data"]["face_list"][0]["gender"],
"age"=>$response["data"]["face_list"][0]["age"],
"beauty"=>$response["data"]["face_list"][0]["beauty"],
];
return ["code"=>1,"data"=>$response["data"],"message"=>"获取成功"];
}
return ["code"=>0,"data"=>$response["data"],"message"=>"未识别"];
}
/**
* Describe:鉴权签名
* @Author: Bygones
* Date: 2019-06-15
* Time: 22:33
* @param array $params
* @param string $appkey
* @return string
*/
public function getReqSign(array $params,string $appkey):string
{
ksort($params);
$str = '';
foreach ($params as $key => $value){
if ($value !== '')
{
$str .= $key . '=' . urlencode($value) . '&';
}
}
$str .= 'app_key=' . $appkey;
$sign = strtoupper(md5($str));
return $sign;
}
/**
* Describe:Post请求API
* @Author: Bygones
* Date: 2019-06-15
* Time: 22:34
* @param string $url
* @param array $params
* @return bool|string
*/
public function doHttpPost(string $url,array $params):string
{
$curl = curl_init();
$response = false;
do
{
curl_setopt($curl, CURLOPT_URL, $url);
$head = [
'Content-Type: application/x-www-form-urlencoded'
];
curl_setopt($curl, CURLOPT_HTTPHEADER, $head);
$body = http_build_query($params);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_NOBODY, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
if ($response === false)
{
$response = false;
break;
}
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($code != 200)
{
$response = false;
break;
}
} while (0);
curl_close($curl);
return $response;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。