Skip to content

Commit a78a1d1

Browse files
手机检测跳转
1 parent 70fbfcf commit a78a1d1

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

services/Store.php

+20-4
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,19 @@ protected function html5DevideCheckAndRedirect($store_code, $store)
184184
$condition = isset($store['mobile']['condition']) ? $store['mobile']['condition'] : false;
185185
$redirectDomain = isset($store['mobile']['redirectDomain']) ? $store['mobile']['redirectDomain'] : false;
186186
if (is_array($condition) && !empty($condition) && !empty($redirectDomain)) {
187+
188+
$mobile_https = (isset($store['mobile']['https']) && $store['mobile']['https']) ? true : false;
187189
if (in_array('phone', $condition) && in_array('tablet', $condition)) {
188190
if ($mobileDetect->isMobile()) {
189-
$this->redirectMobile($store_code, $redirectDomain);
191+
$this->redirectMobile($store_code, $redirectDomain, $mobile_https);
190192
}
191193
} elseif (in_array('phone', $condition)) {
192194
if ($mobileDetect->isMobile() && !$mobileDetect->isTablet()) {
193-
$this->redirectMobile($store_code, $redirectDomain);
195+
$this->redirectMobile($store_code, $redirectDomain, $mobile_https);
194196
}
195197
} elseif (in_array('tablet', $condition)) {
196198
if ($mobileDetect->isTablet()) {
197-
$this->redirectMobile($store_code, $redirectDomain);
199+
$this->redirectMobile($store_code, $redirectDomain, $mobile_https);
198200
}
199201
}
200202
}
@@ -205,10 +207,24 @@ protected function html5DevideCheckAndRedirect($store_code, $store)
205207
* @property $redirectDomain | String
206208
* 设备满足什么条件的时候进行跳转。
207209
*/
208-
protected function redirectMobile($store_code, $redirectDomain)
210+
protected function redirectMobile($store_code, $redirectDomain, $mobile_https)
209211
{
210212
$currentUrl = Yii::$service->url->getCurrentUrl();
211213
$redirectUrl = str_replace($store_code, $redirectDomain, $currentUrl);
214+
// pc端跳转到html5,可能一个是https,一个是http,因此需要下面的代码进行转换。
215+
if ($mobile_https) {
216+
if (strstr($redirectUrl,'https://') || strstr($redirectUrl,'http://')) {
217+
$redirectUrl = str_replace('http://','https://',$redirectUrl);
218+
} else {
219+
$redirectUrl = 'https:'.$redirectUrl;
220+
}
221+
} else {
222+
if (strstr($redirectUrl,'https://') || strstr($redirectUrl,'http://')) {
223+
$redirectUrl = str_replace('https://','http://',$redirectUrl);
224+
} else {
225+
$redirectUrl = 'http:'.$redirectUrl;
226+
}
227+
}
212228
header('Location:'.$redirectUrl);
213229
}
214230

0 commit comments

Comments
 (0)