Skip to content

Commit

Permalink
完善所有接口
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanson committed Apr 10, 2017
1 parent c4f3f99 commit 40ad0bd
Show file tree
Hide file tree
Showing 20 changed files with 677 additions and 145 deletions.
32 changes: 25 additions & 7 deletions README.md
@@ -1,20 +1,20 @@
# face-score
# face

face-score 是基于微软小冰接口的颜值检测工具
face 是基于微软小冰接口的颜值检测工具

## Install

```
composer require hanson/face-score
composer require hanson/face
```

## Usage

```php

$score = new \Hanson\FaceScore\FaceScore();
$face = new \Hanson\Face\Foundation\Face();

$result = $score->getScore('https://ws2.sinaimg.cn/large/685b97a1gy1fehkmbi6hvj20u00u07ab.jpg');
$face = $face->score->get('https://ws2.sinaimg.cn/large/685b97a1gy1fehkmbi6hvj20u00u07ab.jpg');

/**

Expand All @@ -27,6 +27,24 @@ $result = [
**/
```

## Relative
## Achievement

项目参考自 https://github.com/FaithPatrick/FaceScore
### Score 颜值分数

![](https://ooo.0o0.ooo/2017/04/10/58eb894b8c36e.jpg)

### Bill 请吃饭

![](https://ooo.0o0.ooo/2017/04/10/58eb8d2e2f1db.jpg)

### Popular 最受欢迎

![](https://ooo.0o0.ooo/2017/04/10/58eb950a6bda9.jpg)

### Relation 关系

![](https://ooo.0o0.ooo/2017/04/10/58eb97d932144.jpg)

### Clothing 穿衣风格

![](https://ooo.0o0.ooo/2017/04/10/58eb99f234213.jpg)
12 changes: 9 additions & 3 deletions composer.json
@@ -1,5 +1,5 @@
{
"name": "hanson/face-score",
"name": "hanson/face",
"description": "A package to check human appearance score",
"license": "MIT",
"authors": [
Expand All @@ -9,14 +9,20 @@
}
],
"require": {
"guzzlehttp/guzzle": "^6.2"
"guzzlehttp/guzzle": "^6.2",
"pimple/pimple": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^6.1"
},
"autoload": {
"psr-4": {
"Hanson\\FaceScore\\": "src/"
"Hanson\\Face\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Hanson\\Face\\Tests\\": "tests/"
}
}
}
56 changes: 54 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions demo/example.php

This file was deleted.

50 changes: 50 additions & 0 deletions src/BaseFace.php
@@ -0,0 +1,50 @@
<?php


namespace Hanson\Face;


use Hanson\Face\Exception\FetchImageException;
use Hanson\Face\Foundation\Api;

class BaseFace
{
const UPLOAD_URL = 'http://kan.msxiaobing.com/Api/Image/UploadBase64';
const SCORE_URL = 'http://kan.msxiaobing.com/Api/ImageAnalyze/Process?service=yanzhi&tid=52a90c91aaeb4af698bec8ae2106cb36';
const BILL_URL = 'https://kan.msxiaobing.com/Api/ImageAnalyze/Process?service=qingke&tid=bc70072cf17e41ac8501a01399ff1c9c';
const POPULAR_URL = 'https://kan.msxiaobing.com/Api/ImageAnalyze/Process?service=beauty&tid=662e823fd7494b63bc707ccd36e4b30e';
const RELATION_URL = 'https://kan.msxiaobing.com/Api/ImageAnalyze/Process?service=beauty&tid=662e823fd7494b63bc707ccd36e4b30e';
const CLOTHING_URL = 'https://kan.msxiaobing.com/Api/ImageAnalyze/Process?service=cosmoclothing&tid=0dc5049c96c04dbe924134d5e3c39ac9';

/**
* upload image and get the resource url
*
* @param $url
* @return bool|string
* @throws FetchImageException
*/
protected function upload($url)
{
$image = base64_encode(file_get_contents($url));

$result = Api::request(self::UPLOAD_URL, $image);

if(count($result) !== 0){
return $result['Host'] . $result['Url'];
}else{
throw new FetchImageException('获取图片失败');
}
}

/**
* generate a time for api
*
* @return float
*/
protected function generateTime()
{
list($s1, $s2) = explode(' ', microtime());

return (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
}
}
36 changes: 36 additions & 0 deletions src/Bill.php
@@ -0,0 +1,36 @@
<?php


namespace Hanson\Face;


use Hanson\Face\Exception\FetchImageException;
use Hanson\Face\Foundation\Api;

class Bill extends BaseFace
{

/**
* get a score info from url
*
* @param $url
* @return array
* @throws FetchImageException
*/
public function get($url)
{
$result = $this->upload($url);

$response = Api::request(self::BILL_URL, [
'msgId' => $this->generateTime(),
'timestamp' => time(),
'content[imageUrl]' => $result
]);

return [
'text' => $response['content']['text'],
'url' => $response['content']['imageUrl']
];
}

}
37 changes: 37 additions & 0 deletions src/Clothing.php
@@ -0,0 +1,37 @@
<?php


namespace Hanson\Face;


use Hanson\Face\Exception\FetchImageException;
use Hanson\Face\Foundation\Api;

class Clothing extends BaseFace
{

/**
* get a score info from url
*
* @param $url
* @return array
* @throws FetchImageException
*/
public function get($url)
{
$result = $this->upload($url);

$response = Api::request(self::CLOTHING_URL, [
'msgId' => $this->generateTime(),
'timestamp' => time(),
'content[imageUrl]' => $result
]);

return [
'text' => $response['content']['text'],
'url' => $response['content']['imageUrl'],
'data' => $response['content']['metadata']
];
}

}
2 changes: 1 addition & 1 deletion src/Exception/FetchImageException.php
@@ -1,7 +1,7 @@
<?php


namespace Hanson\Exception;
namespace Hanson\Face\Exception;


class FetchImageException extends \Exception
Expand Down

0 comments on commit 40ad0bd

Please sign in to comment.