1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-26 20:52:44 +08:00

优化分享URL

This commit is contained in:
xiaochong0302 2023-05-11 21:54:20 +08:00
parent 820f7a9684
commit af84f778c2
16 changed files with 638 additions and 34 deletions

View File

@ -30,6 +30,8 @@ class HelpController extends Controller
return $this->response->redirect($location); return $this->response->redirect($location);
} }
$featuredCourses = $this->getFeaturedCourses();
$service = new HelpListService(); $service = new HelpListService();
$items = $service->handle(); $items = $service->handle();
@ -37,6 +39,7 @@ class HelpController extends Controller
$this->seo->prependTitle('帮助'); $this->seo->prependTitle('帮助');
$this->view->setVar('items', $items); $this->view->setVar('items', $items);
$this->view->setVar('featured_courses', $featuredCourses);
} }
/** /**

View File

@ -4,6 +4,8 @@
{{ partial('macros/article') }} {{ partial('macros/article') }}
{% set share_url = share_url('article',article.id,auth_user.id) %}
{% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
{% set article_edit_url = url({'for':'home.article.edit','id':article.id}) %} {% set article_edit_url = url({'for':'home.article.edit','id':article.id}) %}
{% set article_delete_url = url({'for':'home.article.delete','id':article.id}) %} {% set article_delete_url = url({'for':'home.article.delete','id':article.id}) %}
{% set article_private_url = url({'for':'home.article.private','id':article.id}) %} {% set article_private_url = url({'for':'home.article.private','id':article.id}) %}
@ -102,9 +104,6 @@
{{ partial('article/sticky') }} {{ partial('article/sticky') }}
</div> </div>
{% set share_url = full_url({'for':'home.share'},{'id':article.id,'type':'article'}) %}
{% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
<div class="layui-hide"> <div class="layui-hide">
<input type="hidden" name="share.title" value="{{ article.title }}"> <input type="hidden" name="share.title" value="{{ article.title }}">
<input type="hidden" name="share.pic" value="{{ article.cover }}"> <input type="hidden" name="share.pic" value="{{ article.cover }}">

View File

@ -2,6 +2,8 @@
{% block content %} {% block content %}
{% set share_url = full_url('chapter',chapter.id,auth_user.id) %}
{% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
{% set course_url = url({'for':'home.course.show','id':chapter.course.id}) %} {% set course_url = url({'for':'home.course.show','id':chapter.course.id}) %}
{% set learning_url = url({'for':'home.chapter.learning','id':chapter.id}) %} {% set learning_url = url({'for':'home.chapter.learning','id':chapter.id}) %}
{% set live_chats_url = url({'for':'home.live.chats','id':chapter.id}) %} {% set live_chats_url = url({'for':'home.live.chats','id':chapter.id}) %}
@ -58,9 +60,6 @@
<input type="hidden" name="bind_user_url" value='{{ bind_user_url }}'> <input type="hidden" name="bind_user_url" value='{{ bind_user_url }}'>
</div> </div>
{% set share_url = full_url({'for':'home.share'},{'id':chapter.id,'type':'chapter'}) %}
{% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
<div class="layui-hide"> <div class="layui-hide">
<input type="hidden" name="share.title" value="{{ chapter.course.title }}"> <input type="hidden" name="share.title" value="{{ chapter.course.title }}">
<input type="hidden" name="share.pic" value="{{ chapter.course.cover }}"> <input type="hidden" name="share.pic" value="{{ chapter.course.cover }}">

View File

@ -2,6 +2,8 @@
{% block content %} {% block content %}
{% set share_url = full_url('chapter',chapter.id,auth_user.id) %}
{% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
{% set course_url = url({'for':'home.course.show','id':chapter.course.id}) %} {% set course_url = url({'for':'home.course.show','id':chapter.course.id}) %}
{% set learning_url = url({'for':'home.chapter.learning','id':chapter.id}) %} {% set learning_url = url({'for':'home.chapter.learning','id':chapter.id}) %}
@ -44,9 +46,6 @@
<input type="hidden" name="chapter.learning_url" value="{{ learning_url }}"> <input type="hidden" name="chapter.learning_url" value="{{ learning_url }}">
</div> </div>
{% set share_url = full_url({'for':'home.share'},{'id':chapter.id,'type':'chapter'}) %}
{% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
<div class="layui-hide"> <div class="layui-hide">
<input type="hidden" name="share.title" value="{{ chapter.course.title }}"> <input type="hidden" name="share.title" value="{{ chapter.course.title }}">
<input type="hidden" name="share.pic" value="{{ chapter.course.cover }}"> <input type="hidden" name="share.pic" value="{{ chapter.course.cover }}">

View File

@ -2,6 +2,8 @@
{% block content %} {% block content %}
{% set share_url = share_url('chapter',chapter.id,auth_user.id) %}
{% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
{% set course_url = url({'for':'home.course.show','id':chapter.course.id}) %} {% set course_url = url({'for':'home.course.show','id':chapter.course.id}) %}
{% set learning_url = url({'for':'home.chapter.learning','id':chapter.id}) %} {% set learning_url = url({'for':'home.chapter.learning','id':chapter.id}) %}
@ -47,9 +49,6 @@
<input type="hidden" name="chapter.play_urls" value='{{ chapter.play_urls|json_encode }}'> <input type="hidden" name="chapter.play_urls" value='{{ chapter.play_urls|json_encode }}'>
</div> </div>
{% set share_url = full_url({'for':'home.share'},{'id':chapter.id,'type':'chapter'}) %}
{% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
<div class="layui-hide"> <div class="layui-hide">
<input type="hidden" name="share.title" value="{{ chapter.course.title }}"> <input type="hidden" name="share.title" value="{{ chapter.course.title }}">
<input type="hidden" name="share.pic" value="{{ chapter.course.cover }}"> <input type="hidden" name="share.pic" value="{{ chapter.course.cover }}">

View File

@ -4,6 +4,9 @@
{{ partial('macros/course') }} {{ partial('macros/course') }}
{% set share_url = share_url('course',course.id,auth_user.id) %}
{% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
<div class="breadcrumb"> <div class="breadcrumb">
<span class="layui-breadcrumb"> <span class="layui-breadcrumb">
<a href="/">首页</a> <a href="/">首页</a>
@ -93,9 +96,6 @@
{{ partial('course/sticky') }} {{ partial('course/sticky') }}
</div> </div>
{% set share_url = full_url({'for':'home.share'},{'id':course.id,'type':'course'}) %}
{% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
<div class="layui-hide"> <div class="layui-hide">
<input type="hidden" name="share.title" value="{{ course.title }}"> <input type="hidden" name="share.title" value="{{ course.title }}">
<input type="hidden" name="share.pic" value="{{ course.cover }}"> <input type="hidden" name="share.pic" value="{{ course.cover }}">

View File

@ -2,6 +2,8 @@
{% block content %} {% block content %}
{{ partial('macros/course') }}
<div class="breadcrumb"> <div class="breadcrumb">
<span class="layui-breadcrumb"> <span class="layui-breadcrumb">
<a href="/">首页</a> <a href="/">首页</a>
@ -30,20 +32,20 @@
</div> </div>
</div> </div>
<div class="layout-sidebar"> <div class="layout-sidebar">
<div class="layui-card cs-sidebar"> {% if featured_courses %}
<div class="layui-card-header">客户服务</div> <div class="sidebar">
<div class="layui-card">
<div class="layui-card-header">推荐课程</div>
<div class="layui-card-body"> <div class="layui-card-body">
<p>没解决你的疑问?试试联系客服吧!</p> {% for course in featured_courses %}
{% if contact_info.qq %} {{ sidebar_course_card(course) }}
{% set link_url = 'https://wpa.qq.com/msgrd?v=3&uin=%s&site=qq&menu=yes'|format(contact_info.qq) %} {% endfor %}
<p class="center"> </div>
<a href="{{ link_url }}" class="layui-btn layui-btn-sm">联系客服</a> </div>
</p> </div>
{% endif %} {% endif %}
</div> </div>
</div> </div>
</div>
</div>
{% endblock %} {% endblock %}

View File

@ -4,12 +4,20 @@
{{ partial('macros/course') }} {{ partial('macros/course') }}
{% set share_url = share_url('help',help.id,auth_user.id) %}
{% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
<div class="breadcrumb"> <div class="breadcrumb">
<span class="layui-breadcrumb"> <span class="layui-breadcrumb">
<a href="/">首页</a> <a href="/">首页</a>
<a href="{{ url({'for':'home.help.index'}) }}">帮助中心</a> <a href="{{ url({'for':'home.help.index'}) }}">帮助中心</a>
<a><cite>{{ help.title }}</cite></a> <a><cite>{{ help.title }}</cite></a>
</span> </span>
<span class="share">
<a class="share-wechat" href="javascript:" title="分享到微信"><i class="layui-icon layui-icon-login-wechat"></i></a>
<a class="share-qq" href="javascript:" title="分享到QQ空间"><i class="layui-icon layui-icon-login-qq"></i></a>
<a class="share-weibo" href="javascript:" title="分享到微博"><i class="layui-icon layui-icon-login-weibo"></i></a>
</span>
</div> </div>
<div class="layout-main"> <div class="layout-main">
@ -34,6 +42,12 @@
</div> </div>
</div> </div>
<div class="layui-hide">
<input type="hidden" name="share.title" value="{{ help.title }}">
<input type="hidden" name="share.url" value="{{ share_url }}">
<input type="hidden" name="share.qrcode" value="{{ qrcode_url }}">
</div>
{% endblock %} {% endblock %}
{% block link_css %} {% block link_css %}

View File

@ -4,11 +4,19 @@
{{ partial('macros/course') }} {{ partial('macros/course') }}
{% set share_url = share_url('page',page.id,auth_user.id) %}
{% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
<div class="breadcrumb"> <div class="breadcrumb">
<span class="layui-breadcrumb"> <span class="layui-breadcrumb">
<a href="/">首页</a> <a href="/">首页</a>
<a><cite>{{ page.title }}</cite></a> <a><cite>{{ page.title }}</cite></a>
</span> </span>
<span class="share">
<a class="share-wechat" href="javascript:" title="分享到微信"><i class="layui-icon layui-icon-login-wechat"></i></a>
<a class="share-qq" href="javascript:" title="分享到QQ空间"><i class="layui-icon layui-icon-login-qq"></i></a>
<a class="share-weibo" href="javascript:" title="分享到微博"><i class="layui-icon layui-icon-login-weibo"></i></a>
</span>
</div> </div>
<div class="layout-main"> <div class="layout-main">
@ -33,6 +41,12 @@
</div> </div>
</div> </div>
<div class="layui-hide">
<input type="hidden" name="share.title" value="{{ page.title }}">
<input type="hidden" name="share.url" value="{{ share_url }}">
<input type="hidden" name="share.qrcode" value="{{ qrcode_url }}">
</div>
{% endblock %} {% endblock %}
{% block link_css %} {% block link_css %}

View File

@ -4,6 +4,8 @@
{{ partial('macros/question') }} {{ partial('macros/question') }}
{% set share_url = share_url('question',question.id,auth_user.id) %}
{% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
{% set question_report_url = url({'for':'home.report.add'},{'item_id':question.id,'item_type':107}) %} {% set question_report_url = url({'for':'home.report.add'},{'item_id':question.id,'item_type':107}) %}
{% set question_edit_url = url({'for':'home.question.edit','id':question.id}) %} {% set question_edit_url = url({'for':'home.question.edit','id':question.id}) %}
{% set question_delete_url = url({'for':'home.question.delete','id':question.id}) %} {% set question_delete_url = url({'for':'home.question.delete','id':question.id}) %}
@ -98,9 +100,6 @@
{{ partial('question/sticky') }} {{ partial('question/sticky') }}
</div> </div>
{% set share_url = full_url({'for':'home.share'},{'id':question.id,'type':'question'}) %}
{% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
<div class="layui-hide"> <div class="layui-hide">
<input type="hidden" name="share.title" value="{{ question.title }}"> <input type="hidden" name="share.title" value="{{ question.title }}">
<input type="hidden" name="share.pic" value=""> <input type="hidden" name="share.pic" value="">

View File

@ -4,6 +4,8 @@
{{ partial('macros/user') }} {{ partial('macros/user') }}
{% set share_url = share_url('user',user.id,auth_user.id) %}
{% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
{% set avatar_class = user.vip == 1 ? 'avatar vip' : 'avatar' %} {% set avatar_class = user.vip == 1 ? 'avatar vip' : 'avatar' %}
<div class="breadcrumb"> <div class="breadcrumb">
@ -13,7 +15,6 @@
<a><cite>{{ user.name }}</cite></a> <a><cite>{{ user.name }}</cite></a>
</span> </span>
<span class="share"> <span class="share">
<a href="javascript:" title="添加好友" class="apply-friend" data-id="{{ user.id }}" data-name="{{ user.name }}" data-avatar="{{ user.avatar }}"><i class="layui-icon layui-icon-user"></i></a>
<a href="javascript:" title="分享到微信"><i class="layui-icon layui-icon-login-wechat share-wechat"></i></a> <a href="javascript:" title="分享到微信"><i class="layui-icon layui-icon-login-wechat share-wechat"></i></a>
<a href="javascript:" title="分享到QQ空间"><i class="layui-icon layui-icon-login-qq share-qq"></i></a> <a href="javascript:" title="分享到QQ空间"><i class="layui-icon layui-icon-login-qq share-qq"></i></a>
<a href="javascript:" title="分享到微博"><i class="layui-icon layui-icon-login-weibo share-weibo"></i></a> <a href="javascript:" title="分享到微博"><i class="layui-icon layui-icon-login-weibo share-weibo"></i></a>
@ -80,9 +81,6 @@
</div> </div>
</div> </div>
{% set share_url = full_url({'for':'home.share'},{'id':user.id,'type':'user'}) %}
{% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %}
<div class="layui-hide"> <div class="layui-hide">
<input type="hidden" name="share.title" value="{{ user.name }}"> <input type="hidden" name="share.title" value="{{ user.name }}">
<input type="hidden" name="share.pic" value="{{ user.avatar }}"> <input type="hidden" name="share.pic" value="{{ user.avatar }}">

View File

@ -8,8 +8,8 @@
use App\Caches\Setting as SettingCache; use App\Caches\Setting as SettingCache;
use App\Library\Purifier as HtmlPurifier; use App\Library\Purifier as HtmlPurifier;
use App\Library\Validators\Common as CommonValidator; use App\Library\Validators\Common as CommonValidator;
use App\Services\Logic\Url\ShareUrl as ShareUrlService;
use App\Services\Storage as StorageService; use App\Services\Storage as StorageService;
use Koogua\Ip2Region\Searcher as Ip2RegionSearcher;
use Phalcon\Config; use Phalcon\Config;
use Phalcon\Di; use Phalcon\Di;
use Phalcon\Text; use Phalcon\Text;
@ -727,6 +727,21 @@ function kg_full_url($uri, $args = null)
return $baseUrl . $url->get($uri, $args); return $baseUrl . $url->get($uri, $args);
} }
/**
* 构造分享url
*
* @param string $type
* @param int $id
* @param int $referer
* @return string
*/
function kg_share_url($type, $id, $referer = 0)
{
$service = new ShareUrlService();
return $service->handle($type, $id, $referer);
}
/** /**
* 获取H5首页地址 * 获取H5首页地址
* *

View File

@ -39,6 +39,10 @@ class Volt extends Provider
return 'kg_full_url(' . $resolvedArgs . ')'; return 'kg_full_url(' . $resolvedArgs . ')';
}); });
$compiler->addFunction('share_url', function ($resolvedArgs) {
return 'kg_share_url(' . $resolvedArgs . ')';
});
$compiler->addFunction('static_url', function ($resolvedArgs) { $compiler->addFunction('static_url', function ($resolvedArgs) {
return 'kg_static_url(' . $resolvedArgs . ')'; return 'kg_static_url(' . $resolvedArgs . ')';
}); });

View File

@ -0,0 +1,192 @@
<?php
/**
* @copyright Copyright (c) 2022 深圳市酷瓜软件有限公司
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* @link https://www.koogua.com
*/
namespace App\Services\Logic\Url;
use App\Models\Course as CourseModel;
use App\Repos\Chapter as ChapterRepo;
use App\Services\Service as AppService;
use App\Traits\Client as ClientTrait;
class FullH5Url extends AppService
{
/**
* 基准地址
*
* @var string
*/
protected $baseUrl;
/**
* 跳转来源
*
* @var string
*/
protected $source = 'pc';
use ClientTrait;
public function __construct()
{
$this->baseUrl = $this->getBaseUrl();
}
public function getHomeUrl()
{
return $this->getFullUrl('/index/index');
}
public function getAccountRegisterUrl()
{
return $this->getFullUrl('/account/register');
}
public function getAccountLoginUrl()
{
return $this->getFullUrl('/account/login');
}
public function getAccountForgetUrl()
{
return $this->getFullUrl('/account/forget');
}
public function getVipIndexUrl()
{
return $this->getFullUrl('/vip/index');
}
public function getHelpIndexUrl()
{
return $this->getFullUrl('/help/index');
}
public function getCourseListUrl()
{
return $this->getFullUrl('/course/list');
}
public function getArticleListUrl()
{
return $this->getFullUrl('/article/list');
}
public function getQuestionListUrl()
{
return $this->getFullUrl('/question/list');
}
public function getLiveListUrl()
{
return $this->getFullUrl('/live/list');
}
public function getTeacherListUrl()
{
return $this->getFullUrl('/teacher/list');
}
public function getFlashSaleListUrl()
{
return $this->getFullUrl('/flash-sale/list');
}
public function getPointGiftListUrl()
{
return $this->getFullUrl('/point/gift/list');
}
public function getPageInfoUrl($id)
{
return $this->getFullUrl('/page/info', ['id' => $id]);
}
public function getHelpInfoUrl($id)
{
return $this->getFullUrl('/help/info', ['id' => $id]);
}
public function getArticleInfoUrl($id)
{
return $this->getFullUrl('/article/info', ['id' => $id]);
}
public function getQuestionInfoUrl($id)
{
return $this->getFullUrl('/question/info', ['id' => $id]);
}
public function getAnswerInfoUrl($id)
{
return $this->getFullUrl('/answer/info', ['id' => $id]);
}
public function getTopicInfoUrl($id)
{
return $this->getFullUrl('/topic/info', ['id' => $id]);
}
public function getPackageInfoUrl($id)
{
return $this->getFullUrl('/package/info', ['id' => $id]);
}
public function getCourseInfoUrl($id)
{
return $this->getFullUrl('/course/info', ['id' => $id]);
}
public function getChapterInfoUrl($id)
{
$chapterRepo = new ChapterRepo();
$chapter = $chapterRepo->findById($id);
if ($chapter->model == CourseModel::MODEL_VOD) {
return $this->getFullUrl('/chapter/vod', ['id' => $id]);
} elseif ($chapter->model == CourseModel::MODEL_LIVE) {
return $this->getFullUrl('/chapter/live', ['id' => $id]);
} elseif ($chapter->model == CourseModel::MODEL_READ) {
return $this->getFullUrl('/chapter/read', ['id' => $id]);
} else {
return $this->getHomeUrl();
}
}
public function getUserIndexUrl($id)
{
return $this->getFullUrl('/user/index', ['id' => $id]);
}
public function getTeacherIndexUrl($id)
{
return $this->getFullUrl('/teacher/index', ['id' => $id]);
}
public function getPointGiftInfoUrl($id)
{
return $this->getFullUrl('/point/gift/info', ['id' => $id]);
}
protected function getFullUrl($path, $params = [])
{
$extra = ['source' => $this->source];
$data = array_merge($params, $extra);
$query = http_build_query($data);
return sprintf('%s%s?%s', $this->baseUrl, $path, $query);
}
protected function getBaseUrl()
{
return sprintf('%s/h5/#/pages', kg_site_url());
}
}

View File

@ -0,0 +1,139 @@
<?php
/**
* @copyright Copyright (c) 2022 深圳市酷瓜软件有限公司
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* @link https://www.koogua.com
*/
namespace App\Services\Logic\Url;
use App\Services\Service;
class FullWebUrl extends Service
{
/**
* 基准地址
*
* @var string
*/
protected $baseUrl;
/**
* 跳转来源
*
* @var string
*/
protected $source = 'pc';
public function __construct()
{
$this->baseUrl = $this->getBaseUrl();
}
public function getHomeUrl()
{
return $this->baseUrl;
}
public function getVipUrl()
{
$route = $this->url->get(['for' => 'home.vip.index']);
return $this->getFullUrl($route);
}
public function getHelpShowUrl($id)
{
$route = $this->url->get(['for' => 'home.help.show', 'id' => $id]);
return $this->getFullUrl($route);
}
public function getPageShowUrl($id)
{
$route = $this->url->get(['for' => 'home.page.show', 'id' => $id]);
return $this->getFullUrl($route);
}
public function getArticleShowUrl($id)
{
$route = $this->url->get(['for' => 'home.article.show', 'id' => $id]);
return $this->getFullUrl($route);
}
public function getQuestionShowUrl($id)
{
$route = $this->url->get(['for' => 'home.question.show', 'id' => $id]);
return $this->getFullUrl($route);
}
public function getTopicShowUrl($id)
{
$route = $this->url->get(['for' => 'home.topic.show', 'id' => $id]);
return $this->getFullUrl($route);
}
public function getPackageShowUrl($id)
{
$route = $this->url->get(['for' => 'home.package.show', 'id' => $id]);
return $this->getFullUrl($route);
}
public function getCourseShowUrl($id)
{
$route = $this->url->get(['for' => 'home.course.show', 'id' => $id]);
return $this->getFullUrl($route);
}
public function getChapterShowUrl($id)
{
$route = $this->url->get(['for' => 'home.chapter.show', 'id' => $id]);
return $this->getFullUrl($route);
}
public function getUserShowUrl($id)
{
$route = $this->url->get(['for' => 'home.user.show', 'id' => $id]);
return $this->getFullUrl($route);
}
public function getTeacherShowUrl($id)
{
$route = $this->url->get(['for' => 'home.teacher.show', 'id' => $id]);
return $this->getFullUrl($route);
}
public function getPointGiftShowUrl($id)
{
$route = $this->url->get(['for' => 'home.point_gift.show', 'id' => $id]);
return $this->getFullUrl($route);
}
protected function getFullUrl($path, $params = [])
{
$extra = ['source' => $this->source];
$data = array_merge($params, $extra);
$query = http_build_query($data);
return sprintf('%s%s?%s', $this->baseUrl, $path, $query);
}
protected function getBaseUrl()
{
return kg_site_url();
}
}

View File

@ -0,0 +1,228 @@
<?php
/**
* @copyright Copyright (c) 2022 深圳市酷瓜软件有限公司
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* @link https://www.koogua.com
*/
namespace App\Services\Logic\Url;
use App\Services\Service as AppService;
use App\Traits\Client as ClientTrait;
class ShareUrl extends AppService
{
/**
* WEB站点URL
*
* @var string
*/
protected $fullWebUrl;
/**
* H5站点URL
*
* @var string
*/
protected $fullH5Url;
/**
* 目标类型h5|web
*
* @var string
*/
protected $targetType;
use ClientTrait;
public function __construct()
{
$this->fullWebUrl = new FullWebUrl();
$this->fullH5Url = new FullH5Url();
}
public function handle($type, $id = 0, $referer = 0)
{
if ($type == 'article') {
$result = $this->getArticleUrl($id);
} elseif ($type == 'page') {
$result = $this->getPageUrl($id);
} elseif ($type == 'question') {
$result = $this->getQuestionUrl($id);
} elseif ($type == 'course') {
$result = $this->getCourseUrl($id);
} elseif ($type == 'chapter') {
$result = $this->getChapterUrl($id);
} elseif ($type == 'user') {
$result = $this->getUserUrl($id);
} elseif ($type == 'teacher') {
$result = $this->getTeacherUrl($id);
} elseif ($type == 'topic') {
$result = $this->getTopicUrl($id);
} elseif ($type == 'package') {
$result = $this->getPackageUrl($id);
} elseif ($type == 'vip') {
$result = $this->getVipUrl();
} elseif ($type == 'point_gift') {
$result = $this->getPointGiftUrl($id);
} else {
$result = $this->getHomeUrl();
}
if ($referer > 0) {
$result['h5'] = $this->withReferer($result['h5'], $referer);
$result['web'] = $this->withReferer($result['web'], $referer);
}
$gotoH5 = $this->gotoH5Url();
return $gotoH5 ? $result['h5'] : $result['web'];
}
public function getHomeUrl()
{
$webUrl = $this->fullWebUrl->getHomeUrl();
$h5Url = $this->fullH5Url->getHomeUrl();
return ['web' => $webUrl, 'h5' => $h5Url];
}
public function getVipUrl()
{
$webUrl = $this->fullWebUrl->getVipUrl();
$h5Url = $this->fullH5Url->getVipIndexUrl();
return ['web' => $webUrl, 'h5' => $h5Url];
}
public function getHelpUrl($id)
{
$webUrl = $this->fullWebUrl->getHelpShowUrl($id);
$h5Url = $this->fullH5Url->getHelpInfoUrl($id);
return ['web' => $webUrl, 'h5' => $h5Url];
}
public function getPageUrl($id)
{
$webUrl = $this->fullWebUrl->getPageShowUrl($id);
$h5Url = $this->fullH5Url->getPageInfoUrl($id);
return ['web' => $webUrl, 'h5' => $h5Url];
}
public function getArticleUrl($id)
{
$webUrl = $this->fullWebUrl->getArticleShowUrl($id);
$h5Url = $this->fullH5Url->getArticleInfoUrl($id);
return ['web' => $webUrl, 'h5' => $h5Url];
}
public function getQuestionUrl($id)
{
$webUrl = $this->fullWebUrl->getQuestionShowUrl($id);
$h5Url = $this->fullH5Url->getQuestionInfoUrl($id);
return ['web' => $webUrl, 'h5' => $h5Url];
}
public function getTopicUrl($id)
{
$webUrl = $this->fullWebUrl->getTopicShowUrl($id);
$h5Url = $this->fullH5Url->getTopicInfoUrl($id);
return ['web' => $webUrl, 'h5' => $h5Url];
}
public function getPackageUrl($id)
{
$webUrl = $this->fullWebUrl->getPackageShowUrl($id);
$h5Url = $this->fullH5Url->getPackageInfoUrl($id);
return ['web' => $webUrl, 'h5' => $h5Url];
}
public function getCourseUrl($id)
{
$webUrl = $this->fullWebUrl->getCourseShowUrl($id);
$h5Url = $this->fullH5Url->getCourseInfoUrl($id);
return ['web' => $webUrl, 'h5' => $h5Url];
}
public function getChapterUrl($id)
{
$webUrl = $this->fullWebUrl->getChapterShowUrl($id);
$h5Url = $this->fullH5Url->getChapterInfoUrl($id);
return ['web' => $webUrl, 'h5' => $h5Url];
}
public function getUserUrl($id)
{
$webUrl = $this->fullWebUrl->getUserShowUrl($id);
$h5Url = $this->fullH5Url->getUserIndexUrl($id);
return ['web' => $webUrl, 'h5' => $h5Url];
}
public function getTeacherUrl($id)
{
$webUrl = $this->fullWebUrl->getTeacherShowUrl($id);
$h5Url = $this->fullH5Url->getTeacherIndexUrl($id);
return ['web' => $webUrl, 'h5' => $h5Url];
}
public function getPointGiftUrl($id)
{
$webUrl = $this->fullWebUrl->getPointGiftShowUrl($id);
$h5Url = $this->fullH5Url->getPointGiftInfoUrl($id);
return ['web' => $webUrl, 'h5' => $h5Url];
}
public function setTargetType($targetType)
{
$this->targetType = $targetType;
}
protected function withReferer($url, $referer)
{
$params = ['referer' => $referer];
if (strpos($url, '?') === false) {
$url .= '?' . http_build_query($params);
} else {
$url .= '&' . http_build_query($params);
}
return $url;
}
protected function gotoH5Url()
{
if (!$this->h5Enabled()) return false;
if ($this->targetType == 'h5') return true;
return $this->isMobileBrowser();
}
}