Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
677 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'] | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'] | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
|
||
|
||
namespace Hanson\Exception; | ||
namespace Hanson\Face\Exception; | ||
|
||
|
||
class FetchImageException extends \Exception | ||
|
Oops, something went wrong.