<?php
/**
* 人脸识别测颜值、测脸龄、测相似度微信接口
* @Created by MOS.Ving.
* @Author: MOS.Ving
* @Mail 904679843@qq.com
* @Date: 2016-01-31
*/
define("TOKEN", 'weixin'); //设置token
//FACE++ 参数 自行到face++官网注册并创建应用
define("API_KEY", "api_key=你的api_key"); //你的face++应用 api_key
define("API_SECRET", "&api_secret=你的api_secret");//你的face++应用 api_secret
define("ATTRIBUTE", "&attribute=glass,pose,gender,age,race,smiling");//需要返回的内容的参数
define("DETECT_URL", "http://apicn.faceplusplus.com/v2/detection/detect?");//检测给定图片(Image)中的所有人脸(Face)的位置和相应的面部属性api地址
define("LANDMARK_URL", "http://api.faceplusplus.com/detection/landmark?");//检测给定人脸(Face)相应的面部轮廓,五官等关键点的位置,包括25点和83点两种模式api地址
define("COMPARE_URL", "https://apicn.faceplusplus.com/v2/recognition/compare?");//计算两个Face的相似性以及五官相似度api地址
define("TYPE","&type=83p");//83点模式
define("MESSAGE_URL", "");//放回图文消息被点击需要跳转的地址,不需要跳转可不填
$wechatObj = new wechatCallbackapiTest();
if($_GET['echostr']){
$wechatObj->valid();
}else{
$wechatObj->responseMsg();
}
class wechatCallbackapiTest{
public function valid(){
$echoStr = $_GET["echostr"];
//valid signature , option
if($this->checkSignature()){
echo $echoStr;
exit;
}
}
public function responseMsg(){
//get post data, May be due to the different environments
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
//extract post data
if (!empty($postStr)){
/* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,
the best way is to check the validity of xml by yourself */
libxml_disable_entity_loader(true);
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$keyword = trim($postObj->Content);
$imgUrl = $postObj->PicUrl;
$Event = $postObj->Event;
$EventKey = $postObj->EventKey;
$MsgType = $postObj->MsgType;
$time = time();
$itemTpl = "<item>
<Title><![CDATA[%s]]></Title>
<Description><![CDATA[%s]]></Description>
<PicUrl><![CDATA[%s]]></PicUrl>
<Url><![CDATA[%s]]></Url>
</item>";
if($MsgType == "image"){
$item_str = sprintf($itemTpl
颜值计算器(含微信接口)
最新推荐文章于 2023-04-09 16:24:17 发布
这是一个使用PHP实现的微信接口,通过Face++ API进行人脸识别,计算上传图片中人脸的颜值、性别、年龄、种族和微笑程度。当用户上传照片时,程序返回一个包含颜值报告的图文消息。
摘要由CSDN通过智能技术生成