Browse Source

HeroUnion api added

master
filesite 8 months ago
parent
commit
ca27a8adb9
  1. 12
      conf/app.php
  2. 82
      themes/tajian/controller/FrontapiController.php

12
conf/app.php

@ -90,6 +90,18 @@ $configs = array( @@ -90,6 +90,18 @@ $configs = array(
),
),
//对接HeroUnion英雄联盟,实现提交任务和接收任务完成回调通知
'heroUnion' => array(
'server_url' => 'https://herounion.filesite.io',
'uuid' => 'machete_tajian',
'token' => 'machete_tajian',
'contract' => 'tajiantv',
'country' => 'cn',
'lang' => 'zh',
'data_mode' => 'json',
'notify_url' => 'https://tajian.tv/frontapi/hunotify',
),
);
//自定义配置支持

82
themes/tajian/controller/FrontapiController.php

@ -138,6 +138,9 @@ Class FrontApiController extends SiteController { @@ -138,6 +138,9 @@ Class FrontApiController extends SiteController {
if (!empty($tagName)) {
$done = $done && $this->saveVideoToTag($shareUrl, $tagName);
}
//调用HeroUnion联盟接口,提交新的数据抓取任务
$this->addHeroUnionTask($shareUrl, $platform);
}
return $done;
@ -185,4 +188,83 @@ Class FrontApiController extends SiteController { @@ -185,4 +188,83 @@ Class FrontApiController extends SiteController {
}
}
protected function sign($params, $token) { //对参数做MD5签名
return md5( json_encode(ksort($params)) . $token );
}
//提交视频抓取任务到HeroUnion英雄联盟
protected function addHeroUnionTask($shareUrl, $platform) {
$heroUnionConfig = FSC::$app['config']['heroUnion'];
$params = array(
'uuid' => $heroUnionConfig['uuid'],
'url' => $shareUrl,
'platform' => $platform,
'contract' => $heroUnionConfig['contract'],
'data_mode' => $heroUnionConfig['contract'],
'country' => $heroUnionConfig['contract'],
'lang' => $heroUnionConfig['contract'],
'notify_url' => $heroUnionConfig['notify_url'],
);
$params['sign'] = $this->sign($params, $heroUnionConfig['token']);
$api = $heroUnionConfig['server_url'] . '/api/newtask/';
$res = this->request($api, $params);
return !empty($res) && $res['status'] == 200 ? $res['result'] : false;
}
//TODO: 保存快捷方式
protected function saveUrlShortCut($task_id, $task_url) {
}
//TODO: 保存描述文件
//TODO: 保存封面图
//TODO: HeroUnion任务数据通知回传接口
/**
* let params = {
"task_id": task.id,
"task_result": task.results,
"timestamp": common.getTimestamp(),
"sign": ""
};
**/
public function actionHuNotify() {
$task_id = $this->post('task_id', '');
$task_result = $this->post('task_result', '');
$timestamp = $this->post('timestamp', '');
$sign = $this->post('sign', '');
$code = 1;
$msg = '';
$err = '';
//参数检查
if (empty($task_id) || empty($task_result) || empty($timestamp) || empty($sign)) {
$code = 0;
$err = '参数缺失!';
}
$heroUnionConfig = FSC::$app['config']['heroUnion'];
//验证签名
if ($code == 1) {
$checkParams = array(
'task_id' => $task_id,
'task_result' => $task_result,
'timestamp' => $timestamp,
);
$mySign = $this->sign($checkParams, $heroUnionConfig['token']);
if (strtolower($mySign) != strtolower($sign)) {
$code = 0;
$err = '签名验证不通过!';
}
}
echo 'Done';
}
}

Loading…
Cancel
Save