瀏覽代碼

接口调整

lizhen_gitee 5 月之前
父節點
當前提交
20d05d33bb
共有 3 個文件被更改,包括 74 次插入4 次删除
  1. 20 3
      application/api/controller/Subject.php
  2. 1 1
      application/common/controller/Api.php
  3. 53 0
      application/common/library/Video.php

+ 20 - 3
application/api/controller/Subject.php

@@ -5,6 +5,8 @@ namespace app\api\controller;
 use app\common\controller\Api;
 use think\Db;
 use think\cache;
+use app\utils\RedisKeyEnum;
+use app\utils\RedisUtil;
 /**
  * 投票
  */
@@ -19,6 +21,7 @@ class Subject extends Api
     public function info(){
 
         $find = Db::name('vote_subject')->where('id',1)->find();
+        $find['image'] = localpath_to_netpath($find['image']);
         if(!$find){
             $this->error('没有进行中的投票活动');
         }
@@ -56,6 +59,7 @@ class Subject extends Api
         //以上两者都没有,按钮:投票
 
         foreach($lists as $key => $val){
+            $val['video_file'] = localpath_to_netpath($val['video_file']);
 
             $val['video_thumb'] = '';
             if(!empty($val['video_file'])){
@@ -80,7 +84,7 @@ class Subject extends Api
         }
 
         $map = [
-            'player_id' => $player_id,
+            'id' => $player_id,
         ];
 
         $info = Db::name('vote_player')->where($map)->find();
@@ -91,6 +95,14 @@ class Subject extends Api
             $info['video_thumb'] = $info['video_file'].'?x-oss-process=video/snapshot,t_0,m_fast,f_jpg';
         }
 
+        //获取播放地址和秒数
+        $videoVod = new \app\common\library\Video();
+        $video_PlayInfo = $videoVod->getPlayInfo($info['vodid']);
+        $video_PlayInfo = $video_PlayInfo->PlayInfoList->PlayInfo;
+
+        $info['video_file'] = $video_PlayInfo[0]->PlayURL;
+        $info['video_seconds'] = ceil($video_PlayInfo[0]->Duration);
+
         //名次
         /*$players = Db::name('vote_player')->where(['subject_id'=>$info['subject_id'],'status'=>1])->order('votes desc,id desc')->column('id,votes');
         $id_arr = array_keys($players);
@@ -113,12 +125,17 @@ class Subject extends Api
         //今天,用户答对的次数,也就是答题获得的票数
         $question_vote  = RedisUtil::getInstance(RedisKeyEnum::EAXM_RIGHT.date('Y-m-d').':'.$this->auth->id)->get();
 
-        //基础票数,答题票数
+        //基础票数
         $jcps = $gift_votes - $today_record;
         if($jcps < 0){
             $jcps = 0;
         }
+
+        //答题票数
         $dtps = $question_vote - ( ($today_record - $gift_votes) <= 0 ? 0 : ($today_record - $gift_votes) );
+        if($dtps < 0){
+            $dtps = 0;
+        }
 
         //今日投票记录
         $player_ids = Db::name('vote_record')->where('user_id',$this->auth->id)->where('createdate',strtotime(date('Y-m-d')))->column('player_id');
@@ -129,7 +146,7 @@ class Subject extends Api
         $lists = Db::name('vote_player')->field('id,title,votes')
             ->where($map)->order('votes desc,id desc')->select();
 
-
+        //
         $result = [
             'info' => $info,
             'jcps' => $jcps,

+ 1 - 1
application/common/controller/Api.php

@@ -384,7 +384,7 @@ class Api
             $key = strtolower($controller) . '_' . strtolower($action) . '_' . $userId;
         }
 
-        if (!RedisUtil::getInstance($key)->tryTimes($apiLimit,intval($apiLimitTime))){
+        if (!RedisUtil::getInstance($key)->tryTimes(intval($apiLimit),intval($apiLimitTime))){
             return false;
         }
         return true;

+ 53 - 0
application/common/library/Video.php

@@ -0,0 +1,53 @@
+<?php
+namespace app\common\library;
+
+use AlibabaCloud\Client\AlibabaCloud;
+use AlibabaCloud\Vod\Vod;
+
+use AlibabaCloud\Client\Exception\ClientException;
+use AlibabaCloud\Client\Exception\ServerException;
+
+class Video
+{
+    protected $accessKeyId = '';
+    protected $accessKeySecret = '';
+    public function __construct(){
+        define("VOD_CLIENT_NAME", 'AliyunVodClientDemo');
+        $this->accessKeyId = 'LTAI5tCmhmtpkP45oPnM73fb';
+        $this->accessKeySecret = 'ba4MhM2Qs4lbiCacKtR54ATVInfxVo';
+        $this->initVodClient();
+    }
+
+    //初始化
+    public function initVodClient() {
+        $regionId = 'cn-shanghai';
+        //填入AccessKey信息
+        AlibabaCloud::accessKeyClient($this->accessKeyId, $this->accessKeySecret)
+            ->regionId($regionId)
+            ->connectTimeout(1)
+            ->timeout(3)
+            ->name(VOD_CLIENT_NAME);
+    }
+
+    //GetPlayInfo
+    public function getPlayInfo($videoId) {
+        return Vod::v20170321()->getPlayInfo()->client(VOD_CLIENT_NAME)
+            ->withVideoId($videoId)    // 指定接口参数
+            ->withAuthTimeout(3600*24)
+            ->format('JSON')  // 指定返回格式
+            ->request();      // 执行请求
+    }
+
+    /**
+     * @throws ClientException
+     * @throws ServerException
+     */
+    public function getVideoPlayAuth($videoId) {
+        return Vod::v20170321()->getVideoPlayAuth()->client(VOD_CLIENT_NAME)
+            ->withVideoId($videoId)    // 指定音/视频ID
+            ->withAuthInfoTimeout(3600)
+            ->format('JSON')  // 指定返回格式
+            ->request();      // 执行请求
+    }
+
+}