From ca27a8adb921df10c25dcf5afe1756eab2aa4912 Mon Sep 17 00:00:00 2001 From: filesite Date: Sat, 13 Apr 2024 12:27:21 +0800 Subject: [PATCH] HeroUnion api added --- conf/app.php | 12 +++ .../tajian/controller/FrontapiController.php | 82 +++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/conf/app.php b/conf/app.php index 7b07703..1947e04 100644 --- a/conf/app.php +++ b/conf/app.php @@ -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', + ), + ); //自定义配置支持 diff --git a/themes/tajian/controller/FrontapiController.php b/themes/tajian/controller/FrontapiController.php index e02f084..9f05000 100644 --- a/themes/tajian/controller/FrontapiController.php +++ b/themes/tajian/controller/FrontapiController.php @@ -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 { } } + 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'; + } + }