最近访客
百度未收录

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;
                }

搞定 修改代码 注意缩进

附上修改的文件

温馨提示:本文最后更新于2022/10/19 22:43:10。若文章内容或图片失效,请留言联系站长反馈!
!
也想出现在这里? 联系我们
创意广告
© 版权声明
THE END
点赞0赞赏 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容