帖子

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

问题原因

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

搞定 修改代码 注意缩进

附上修改的文件

https://www.fireself.cn/post/4800

未登录无法操作

评论 0

列表为空,暂无内容
须弥技术

专业PHP开发,运维技术社区

打开 App