DiscuzQ更新后手机端视频帖与语音帖无法播放问题

问题原因

DiscuzQ 324更新 手机端使用了新增加的V2接口,V2接口没有返回视频的鉴权地址。

解决方法

找到 app\Api\Controller\Threads 下

ListThreadsV2Controller.php

找到

use Discuz\Base\DzqController;

下面加上

use Discuz\Contracts\Setting\SettingsRepository;
use Carbon\Carbon;
use Illuminate\Support\Str;

找到

public function main()

上面加上

    protected $settings;

    public function __construct(SettingsRepository $settings)
    {
        $this->settings = $settings;
    }

找到

$data['extension'] = [
                    Thread::EXT_VIDEO => ThreadVideo::instance()->getThreadVideo($thread['id'])
                ];

下面加上

$urlKey = $this->settings->get('qcloud_vod_url_key', 'qcloud');
                $urlExpire = (int) $this->settings->get('qcloud_vod_url_expire', 'qcloud');
                if ($urlKey && $urlExpire && $data['extension']['video']['mediaUrl']) {
                    $currentTime = Carbon::now()->timestamp;
                    $dir = Str::beforeLast(parse_url($data['extension']['video']['mediaUrl'])['path'], '/') . '/';
                    $t = dechex($currentTime+$urlExpire);
                    $us = Str::random(10);
                    $sign = md5($urlKey . $dir . $t . $us);
                    $data['extension']['video']['mediaUrl'] = $data['extension']['video']['mediaUrl'] . '?t=' . $t . '&us='. $us . '&sign='.$sign;
                }

ResourceThreadV2Controller.php

找到

use Discuz\Base\DzqController;

下面加上

use Discuz\Contracts\Setting\SettingsRepository;
use Carbon\Carbon;
use Illuminate\Support\Str;

找到

public $relation = [
        'rewardedUsers' => Order::ORDER_TYPE_REWARD,            //打赏的人
        'paidUsers' => Order::ORDER_TYPE_THREAD,                //付费用户
        'onlookers' => Order::ORDER_TYPE_ONLOOKER                 //围观用户
    ];

下面加

protected $settings;

找到

UserFollowRepository $userFollow

后面加上

,SettingsRepository $settings

找到

$data['images'] = [];

下面加上

$urlKey = $this->settings->get('qcloud_vod_url_key', 'qcloud');
$urlExpire = (int) $this->settings->get('qcloud_vod_url_expire', 'qcloud');

找到

$data['threadVideo'] = $thread->threadVideo ?? [];

下面加上

                if ($urlKey && $urlExpire && $data['threadVideo']['mediaUrl']) {
                    $currentTime = Carbon::now()->timestamp;
                    $dir = Str::beforeLast(parse_url($data['threadVideo']['mediaUrl'])['path'], '/') . '/';
                    $t = dechex($currentTime+$urlExpire);
                    $us = Str::random(10);
                    $sign = md5($urlKey . $dir . $t . $us);
                    $data['threadVideo']['mediaUrl'] = $data['threadVideo']['mediaUrl'] . '?t=' . $t . '&us='. $us . '&sign='.$sign;
                }

找到

$data['threadAudio'] = $thread->threadAudio ?? [];

下面加上

if ($urlKey && $urlExpire && $data['threadAudio']['mediaUrl']) {
                    $currentTime = Carbon::now()->timestamp;
                    $dir = Str::beforeLast(parse_url($data['threadAudio']['mediaUrl'])['path'], '/') . '/';
                    $t = dechex($currentTime+$urlExpire);
                    $us = Str::random(10);
                    $sign = md5($urlKey . $dir . $t . $us);
                    $data['threadAudio']['mediaUrl'] = $data['threadAudio']['mediaUrl'] . '?t=' . $t . '&us='. $us . '&sign='.$sign;
                }

搞定 修改代码 注意缩进

附上修改的文件

相关文章

Discuz Q

DiscuzX转DiscuzQ远程附件问题

2021-4-25 0:28:29

Discuz Q

DiscuzQ手机端音频附件和视频附件无法显示播放问题

2021-5-8 3:11:16

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索