Showing
1 changed file
with
40 additions
and
1 deletions
@@ -12,7 +12,6 @@ | @@ -12,7 +12,6 @@ | ||
12 | namespace Api; | 12 | namespace Api; |
13 | 13 | ||
14 | use Plugin\Cache; | 14 | use Plugin\Cache; |
15 | - | ||
16 | class Yohobuy | 15 | class Yohobuy |
17 | { | 16 | { |
18 | /* 正式环境 */ | 17 | /* 正式环境 */ |
@@ -68,6 +67,13 @@ class Yohobuy | @@ -68,6 +67,13 @@ class Yohobuy | ||
68 | */ | 67 | */ |
69 | public static function clientType() | 68 | public static function clientType() |
70 | { | 69 | { |
70 | + if(self::isMobile()) { | ||
71 | + return 'h5'; | ||
72 | + } | ||
73 | + else { | ||
74 | + return 'web'; | ||
75 | + } | ||
76 | + | ||
71 | // 苹果设备 | 77 | // 苹果设备 |
72 | if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone')) { | 78 | if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone')) { |
73 | return 'iphone'; | 79 | return 'iphone'; |
@@ -486,4 +492,37 @@ class Yohobuy | @@ -486,4 +492,37 @@ class Yohobuy | ||
486 | 492 | ||
487 | return $result; | 493 | return $result; |
488 | } | 494 | } |
495 | + | ||
496 | + /** | ||
497 | + * 获取用户User-Agent | ||
498 | + * @return bool | ||
499 | + */ | ||
500 | + public static function getUserAgent() | ||
501 | + { | ||
502 | + if (!isset($_SERVER['HTTP_USER_AGENT']) || empty($_SERVER['HTTP_USER_AGENT'])) { | ||
503 | + return ''; | ||
504 | + } | ||
505 | + return $_SERVER['HTTP_USER_AGENT']; | ||
506 | + } | ||
507 | + | ||
508 | + /** | ||
509 | + * 判断是否手机 | ||
510 | + * @return bool | ||
511 | + */ | ||
512 | + public static function isMobile() | ||
513 | + { | ||
514 | + $userAgent = self::getUserAgent(); | ||
515 | + if (stristr($userAgent, 'ipad')) { | ||
516 | + return false; | ||
517 | + } | ||
518 | + $mobileAgents = array('iphone','android',"240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi","anywhereyougo.com","applewebkit/525","applewebkit/532","asus","audio","au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu","cdm-","compal","coolpad","danger","dbtel","dopod","elaine","eric","etouch","fly ","fly_","fly-","go.web","goodaccess","gradiente","grundig","haier","hedy","hitachi","htc","huawei","hutchison","inno","ipad","ipaq","ipod","jbrowser","kddi","kgt","kwc","lenovo","lg ","lg2","lg3","lg4","lg5","lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo","mercator","meridian","micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-","moto","nec-","netfront","newgen","nexian","nf-browser","nintendo","nitro","nokia","nook","novarra","obigo","palm","panasonic","pantech","philips","phone","pg-","playstation","pocket","pt-","qc-","qtek","rover","sagem","sama","samu","sanyo","samsung","sch-","scooter","sec-","sendo","sgh-","sharp","siemens","sie-","softbank","sony","spice","sprint","spv","symbian","tablet","talkabout","tcl-","teleca","telit","tianyu","tim-","toshiba","tsm","up.browser","utec","utstar","verykool","virgin","vk-","voda","voxtel","vx","wap","wellco","wig browser","wii","windows ce","wireless","xda","xde","zte"); | ||
519 | + $isMobile = false; | ||
520 | + foreach ($mobileAgents as $device) { | ||
521 | + if (stristr($userAgent, $device)) { | ||
522 | + $isMobile = true; | ||
523 | + break; | ||
524 | + } | ||
525 | + } | ||
526 | + return $isMobile; | ||
527 | + } | ||
489 | } | 528 | } |
-
Please register or login to post a comment