Explorar el Código

小程序判断

shish hace 6 años
padre
commit
ff88db49a6
Se han modificado 2 ficheros con 29 adiciones y 12 borrados
  1. 25 0
      common/components/httpUtil.php
  2. 4 12
      common/components/util.php

+ 25 - 0
common/components/httpUtil.php

@@ -96,4 +96,29 @@ class httpUtil
 		return isset($ptSource[$ptName]) ? $ptSource[$ptName] : 0;
 	}
 	
+	//判断是否微信浏览器
+	public static function isWeixin()
+	{
+		if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') == true) {
+			return true;
+		}
+		return false;
+	}
+
+	//判断小程序 shish 2019.12.13
+	public static function isMiniProgram()
+	{
+		//根据头信息判断
+		$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
+		if (strpos($userAgent, 'miniprogram') !== false) {
+			return true;
+		}
+		//根据来源判断
+		$referrer = Yii::$app->request->referrer;
+		if (strpos($referrer, 'servicewechat.com') !== false) {
+			return true;
+		}
+		return false;
+	}
+
 }

+ 4 - 12
common/components/util.php

@@ -7,25 +7,17 @@ use yii\helpers\Json;
 
 class util
 {
-	
-	/**
-	 * 判断是否微信浏览器
-	 * @return boolean
-	 */
+
+	//判断是否微信浏览器
 	public static function isWeixin()
 	{
 		if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') == true) {
 			return true;
 		}
-		Yii::info('请求头:' . $_SERVER['HTTP_USER_AGENT']);
 		return false;
 	}
-	
-	/**
-	 * @desc 根据两点间的经纬度计算距离
-	 * @param float $lat 纬度值
-	 * @param float $lng 经度值
-	 */
+
+	//根据两点间的经纬度计算距离
 	public static function getDistance($lat1, $lng1, $lat2, $lng2)
 	{
 		$earthRadius = 6367000; //approximate radius of earth in meters