Authored by cailing

PHP接口调用client_type修改

@@ -80,21 +80,27 @@ class Yohobuy @@ -80,21 +80,27 @@ class Yohobuy
80 */ 80 */
81 public static function clientType() 81 public static function clientType()
82 { 82 {
83 - // 苹果设备  
84 - if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone')) {  
85 - return 'iphone'; 83 + if(self::isMobile()) {
  84 + return 'h5';
86 } 85 }
87 - // 苹果IPAD  
88 - elseif (strstr($_SERVER['HTTP_USER_AGENT'], 'iPad')) {  
89 - return 'ipad';  
90 - }  
91 - elseif (stristr($_SERVER['HTTP_USER_AGENT'], 'android')) {  
92 - return 'android';  
93 - }  
94 - // 其它  
95 else { 86 else {
96 - return 'android'; 87 + return 'web';
97 } 88 }
  89 +// // 苹果设备
  90 +// if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone')) {
  91 +// return 'iphone';
  92 +// }
  93 +// // 苹果IPAD
  94 +// elseif (strstr($_SERVER['HTTP_USER_AGENT'], 'iPad')) {
  95 +// return 'ipad';
  96 +// }
  97 +// elseif (stristr($_SERVER['HTTP_USER_AGENT'], 'android')) {
  98 +// return 'android';
  99 +// }
  100 +// // 其它
  101 +// else {
  102 +// return 'android';
  103 +// }
98 } 104 }
99 105
100 /** 106 /**
@@ -493,4 +499,37 @@ class Yohobuy @@ -493,4 +499,37 @@ class Yohobuy
493 499
494 return $result; 500 return $result;
495 } 501 }
  502 +
  503 + /**
  504 + * 获取用户User-Agent
  505 + * @return bool
  506 + */
  507 + public static function getUserAgent()
  508 + {
  509 + if (!isset($_SERVER['HTTP_USER_AGENT']) || empty($_SERVER['HTTP_USER_AGENT'])) {
  510 + return '';
  511 + }
  512 + return $_SERVER['HTTP_USER_AGENT'];
  513 + }
  514 +
  515 + /**
  516 + * 判断是否手机
  517 + * @return bool
  518 + */
  519 + public static function isMobile()
  520 + {
  521 + $userAgent = self::getUserAgent();
  522 + if (stristr($userAgent, 'ipad')) {
  523 + return false;
  524 + }
  525 + $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");
  526 + $isMobile = false;
  527 + foreach ($mobileAgents as $device) {
  528 + if (stristr($userAgent, $device)) {
  529 + $isMobile = true;
  530 + break;
  531 + }
  532 + }
  533 + return $isMobile;
  534 + }
496 } 535 }