shish 6 years ago
parent
commit
81a8f7e0d5
2 changed files with 13 additions and 3 deletions
  1. 11 2
      app/mobile/controllers/MainController.php
  2. 2 1
      app/mobile/views/main/index.php

+ 11 - 2
app/mobile/controllers/MainController.php

@@ -12,12 +12,21 @@ class MainController extends PublicController
 {
 	
 	public $enableCsrfValidation = false;
-	
+
 	public function actionIndex()
 	{
 		$host = Yii::$app->request->getHostInfo();
 		$fullUrl = Yii::$app->request->url;
-		$token = strpos($fullUrl, 'token') === false ? '' : 'hasToken';
+		$token = '';
+		if(strpos($fullUrl, 'token')){
+			$parse = parse_url($fullUrl);
+			if (isset($parse['query'])) {
+				parse_str($parse['query'], $queryArray);
+				if (isset($queryArray['token']) && !empty($queryArray['token'])) {
+					$token = $queryArray['token'];
+				}
+			}
+		}
 		return $this->renderPartial('index', ['host' => $host, 'token' => $token]);
 	}
 

+ 2 - 1
app/mobile/views/main/index.php

@@ -7,7 +7,8 @@ http://m.huaml.com/#main/index?account=12358&shopId=15680
 <br />
 其中 #main/index 可以自行定义 ,其它为固定格式,不能改变。
 <script>
-    var code = encodeURIComponent('#main/index?account=12358&shopId=15680');
+    //php测试没带#号
+    var code = encodeURIComponent('main/index?account=12358&shopId=15680');
     <?php if(empty($token)){ ?>
     window.location='<?= $host ?>/auth/prepare?suffixUrl='+code+'&authScope=snsapi_base&account=12358';
     <?php }else{ ?>