广告投放

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

    搞定 修改代码 注意缩进

    附上修改的文件

    原文地址:http://www.5che2.com/

    声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

    给TA打赏
    共{{data.count}}人
    人已打赏
    广告位招租919838898
    0 条回复 A文章作者 M管理员
      暂无讨论,说说你的看法吧
    个人中心
    购物车
    优惠劵
    今日签到
    有新私信 私信列表
    搜索