对比了多个平台的颜值分析后,我发现还是微软小冰的最为智能,不仅测试结果较为令人满意,而且还会返回一句有趣的评论,还有图片点评。
http://kan.msxiaobing.com/V3/Portal?task=yanzhi
这个是微软小冰测颜值的网页,通过抓包分析,得到了其api,然后使用PHP封装成二次接口方便调用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | <?php error_reporting(E_ALL || ~E_NOTICE); header('Content-Type: text/html; charset=utf-8'); if(empty($_POST["image"]))echo "{"ret":0,"msg":"Missing parameter"}";//缺少参数报错 //if(0)echo "{"ret":0,"msg":"Missing parameter"}";//测试用,本地测试时可取消注释并将上一行代码注释 else { $url = "http://kan.msxiaobing.com/V3/Portal?task=yanzhi";//主页面 $url2 = "http://kan.msxiaobing.com/Api/Image/UploadBase64";//上传图片接口 $url3 = "http://kan.msxiaobing.com/Api/ImageAnalyze/Process?service=yanzhi";//测颜值接口 $params = ""; $image = $_POST["image"]; //$path = 'image.png';$data = file_get_contents($path);$image = base64_encode($data);//本地编码图片-测试使用,本地测试时可取消注释并将上一行代码注释,注意在同目录下放一张image.png doHttpPost($url, $params);//访问主页面,获取cookies,存入cookie.txt $response = doHttpPost2($url2, $image);//上传图片 $res=array(); $res=json_decode($response,true); $str=$res['Url']; $str=$str."#"; $key=get_between($str, "key=", "#"); //文本处理,得到上传图片返回的关键参数 $time=date_create(); $time10=(string) date_timestamp_get($time);//获取10位时间戳 $time13=(string) getMillisecond(); //获取13位时间戳 $alldata="MsgId=".$time13."&CreateTime=".$time10."&Content%5BimageUrl%5D=https%3A%2F%2Fmediaplatform.msxiaobing.com%2Fimage%2Ffetchimage%3Fkey%3D".$key;//拼接参数 $response3 = doHttpPost2($url3, $alldata);//提交 echo $response3;//输出结果 } function doHttpPost2($url, $params) //curl请求,调用cookies { $curl = curl_init(); $response = false; do { // 1. 设置HTTP URL (API地址) curl_setopt($curl, CURLOPT_URL, $url); // 2. 设置HTTP HEADER (表单POST) $head[] = 'Referer:http://kan.msxiaobing.com/V3/Portal?task=yanzhi'; $head[] = 'User-Agent:Mozilla/5.0 (Windows NT 5.1; zh-CN) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36'; curl_setopt($curl, CURLOPT_HTTPHEADER, $head); // 3. 设置HTTP BODY (URL键值对) $body = $params; curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $body); // 4. 调用API,获取响应结果 curl_setopt($curl, CURLOPT_HEADER, false); $cookie_file = dirname(__FILE__).'/cookie.txt'; curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file); //调用cookies curl_setopt($curl, CURLOPT_NOBODY, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, true); 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; } function doHttpPost($url, $params) //curl请求,存储cookies { $curl = curl_init(); $response = false; do { // 1. 设置HTTP URL (API地址) curl_setopt($curl, CURLOPT_URL, $url); // 2. 设置HTTP HEADER (表单POST) // 3. 设置HTTP BODY (URL键值对) $body = $params; curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $body); // 4. 调用API,获取响应结果 curl_setopt($curl, CURLOPT_HEADER, false); $cookie_file = dirname(__FILE__).'/cookie.txt'; curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file); //存储cookies curl_setopt($curl, CURLOPT_NOBODY, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, true); 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; } function get_between($input, $start, $end) { //文本_取中间 $substr = substr($input, strlen($start)+strpos($input, $start), (strlen($input) - strpos($input, $end))*(-1)); return $substr; } function getMillisecond() { //获取13位时间戳 list($t1, $t2) = explode(' ', microtime()); return (float)sprintf('%.0f',(floatval($t1)+floatval($t2))*1000); } ?> |
https://unsignedzhang.cn/apis/ai/yanzhi/
这是我的接口demo,仅供测试使用,服务器辣鸡还请不要大量调用
调用方式:POST
必要参数:image(URL编码过的图片base64数据)
返回样例:JSON格式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | { "msgId": "4eab09d2882149ac9f31c2b37266bc39", "timestamp": 1560643780900, "receiverId": null, "content": { "text": "不错,7.3分。不多说,给我签名,万一火了我也能沾点光。", "imageUrl": "http://mediaplatform.trafficmanager.cn/image/fetchimage?key=UQAfAC8ABAAAAFcAFgAGABYASgBCAEIARgAwADEANAAzADcAMQAxADAAQwA5ADgAMgAxADcAQwBGADMAMwAwAEYARQA2ADYANABFADYANgA4ADkA", "metadata": { "AnswerFeed": "FaceBeautyRanking", "w": "vNHsht36iuTlVkF6hu3eiuHtrdvovc37h-bXiuTlhtTQhe3JjszRrPPot9Xti_HkgeDphu7ih9_ej-n-rdr6sOrcifvdgtrQhOrAgOXa", "aid": "46E1F7BD9AA5C618C80BF1C78E659AAA" } } } |
错误样例:{"ret":0,"msg":"Missing parameter"}
PS:我PHP水平还比较菜,代码写的有点乱,希望各位不要介意 (/ω\)
当然,你也可以使用其他语言进行开发, 原理都是一样的
还可以接入QQ机器人玩 |ू・ω・` )

Comments | NOTHING