shish преди 6 години
родител
ревизия
b5177d3d1b
променени са 6 файла, в които са добавени 170 реда и са изтрити 168 реда
  1. 1 3
      app/mobile/controllers/MainController.php
  2. 0 23
      app/whole/config/main-local.php
  3. 34 0
      common/components/httpUtil.php
  4. 22 10
      common/config/main-local.php
  5. 98 98
      common/config/main.php
  6. 15 34
      common/config/params.php

+ 1 - 3
app/mobile/controllers/MainController.php

@@ -29,9 +29,7 @@ class MainController extends PublicController
 	
 	public function actionJwt()
 	{
-		echo "<pre>";
-		echo $_SERVER['HTTP_HOST'];print_r($_SERVER);die;
-		$time = time(); 
+		$time = time();
 		$signer = new Sha256();
 		$key = new Key('testing');
 		$token = (new Builder())->issuedBy('http://example.com')//发布者的url地址

+ 0 - 23
app/whole/config/main-local.php

@@ -1,27 +1,4 @@
 <?php
-
 $config = [
-    'components' => [
-        'request' => [
-            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
-            'cookieValidationKey' => '3i18DOM7ZDqqQfr2S0hj0c60wFxxTb3J',
-        ],
-    ],
 ];
-
-if (!YII_ENV_TEST) {
-    // configuration adjustments for 'dev' environment
-    $config['bootstrap'][] = 'debug';
-    $config['modules']['debug'] = [
-        'class' => 'yii\debug\Module',
-        'allowedIPs' => ['*'],
-    ];
-
-    $config['bootstrap'][] = 'gii';
-    $config['modules']['gii'] = [
-        'class' => 'yii\gii\Module',
-        'allowedIPs' => ['127.0.0.1', '::1'],
-    ];
-}
-
 return $config;

+ 34 - 0
common/components/httpUtil.php

@@ -0,0 +1,34 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: shish <shish@zhhinc.com>
+ * Date: 2019/11/22 0022
+ * Time: 9:46
+ */
+
+namespace common\components;
+
+class httpUtil
+{
+	//专用方法,请勿修改 shish 2019.11.21
+	public static function getHostData()
+	{
+		$http = isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] . '://' : 'https://';
+		$suffix = 'huahb.com';
+		if (isset($_SERVER['HTTP_HOST'])) {
+			$hostInfo = $_SERVER['HTTP_HOST'];
+			$parse = parse_url($hostInfo);
+			$host = $parse['path'];
+			$pos = strpos($host, '.') + 1;
+			$suffix = substr($host, $pos);
+		}
+		return ['http' => $http, 'suffix' => $suffix];
+	}
+	
+	//获得类似这样 http://m.hhb.com
+	public static function getHost()
+	{
+		return Yii::$app->request->getHostInfo();
+	}
+	
+}

+ 22 - 10
common/config/main-local.php

@@ -1,12 +1,24 @@
 <?php
-return [
-    'components' => [
-	    'db' => [
-		    'class' => 'yii\db\Connection',
-		    'dsn' => 'mysql:host=127.0.0.1;dbname=huahuibao',
-		    'username' => 'root',
-		    'password' => 'zt20152008',
-		    'charset' => 'utf8',
-	    ],
-    ],
+$config = [
+	'bootstrap' => ['debug', 'gii'],
+	'modules' => [
+		'debug' => [
+			'class' => 'yii\debug\Module',
+			'allowedIPs' => ['*'],
+		],
+		'gii' => [
+			'class' => 'yii\gii\Module',
+			'allowedIPs' => ['127.0.0.1', '::1'],
+		],
+	],
+	'components' => [
+		'db' => [
+			'class' => 'yii\db\Connection',
+			'dsn' => 'mysql:host=127.0.0.1;dbname=huahuibao',
+			'username' => 'root',
+			'password' => 'zt20152008',
+			'charset' => 'utf8',
+		],
+	],
 ];
+return $config;

+ 98 - 98
common/config/main.php

@@ -1,102 +1,102 @@
 <?php
 return [
-    'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
-    'components' => [
-	    'cache' => [
-	    	'class' => 'yii\caching\FileCache',
-	    ],
-	    'db' => [
-		    'class' => 'yii\db\Connection',
-		    'dsn' => 'mysql:host=127.0.0.1;dbname=huahuibao',
-		    'username' => 'root',
-		    'password' => 'zt20152008',
-		    'charset' => 'utf8',
-	    ],
-        'redis' => [
-	        'class' => 'yii\redis\Connection',
-	        'hostname' => '127.0.0.1',
-	        'port' => 6379,
-	        'database' => 0,
-	        'password'=>'byt6gc1w0aed2q7h',
-        ],
-	    //redis发布与订阅
-	    'redisPubSub'=>[
-		    'class' => 'hollisho\redis_pub_sub\RedisPubSub',
-		    'connect' => [
-			    'class' => 'yii\redis\Connection',
-			    'hostname' => '127.0.0.1',
-			    'port' => 6379,
-			    'database' => 0,
-			    'password' => 'byt6gc1w0aed2q7h',
-			    'connectionTimeout' => 20,
-		    ]
-	    ],
-	    'dict' => [
-		    'class' => 'common\components\configDict',
+	'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
+	'components' => [
+		'cache' => [
+			'class' => 'yii\caching\FileCache',
 		],
-	    'rabbitmq' => [
-		    'class' => 'mikemadisonweb\rabbitmq\Configuration',
-		    'connections' => [
-			    [
-				    'host' => '127.0.0.1',
-				    'port' => '5672',
-				    'user' => 'admin',
-				    'password' => 'vn3oaz1i8w32k4mm9',
-				    'vhost' => '/',
-			    ]
-		    ],
-		    'exchanges' => [
-			    [
-				    'name' => 'ex1',
-				    'type' => 'direct'
-			    ],
-		    ],
-		    'queues' => [
-			    [
-				    'name' => 'queues1',
-				    'passive' => false,
-			    ],
-			    [
-				    'name' => 'queues2',
-				    'passive' => false,
-			    ],
-		    ],
-		    'bindings' => [
-			    [
-				    'queue' => 'queues1',
-				    'exchange' => 'ex1',
-				    'routing_keys' => ['route1'],
-			    ],
-		    ],
-		    'producers' => [
-			    [
-				    'name' => 'producers',
-			    ],
-		    ],
-		    'consumers' => [
-			    [
-				    'name' => 'consumers',
-				    'callbacks' => [
-					    'queues1' => '\common\components\rabbitmq\ImportDataConsumer',
-				    ],
-			    ],
-		    ],
-	    ],
-	    'mailer' => [
-		    'class' => 'yii\swiftmailer\Mailer',
-		    'useFileTransport' =>false,//false发送邮件,true只是生成邮件在runtime文件夹下,不发邮件
-		    'transport' => [
-			    'class' => 'Swift_SmtpTransport',
-			    'host' => 'smtp.126.com',  //每种邮箱的host配置不一样
-			    'username' => 'zhhinc@126.com',
-			    'password' => '',
-			    'port' => '25',
-			    'encryption' => 'tls',
-		    ],
-		    'messageConfig'=>[
-			    'charset'=>'UTF-8',
-			    'from'=>['zhhinc@126.com'=>'系统邮件']
-		    ],
-	    ],
-    ],
+		'db' => [
+			'class' => 'yii\db\Connection',
+			'dsn' => 'mysql:host=127.0.0.1;dbname=huahuibao',
+			'username' => 'root',
+			'password' => 'zt20152008',
+			'charset' => 'utf8',
+		],
+		'redis' => [
+			'class' => 'yii\redis\Connection',
+			'hostname' => '127.0.0.1',
+			'port' => 6379,
+			'database' => 0,
+			'password' => 'byt6gc1w0aed2q7h',
+		],
+		//redis发布与订阅
+		'redisPubSub' => [
+			'class' => 'hollisho\redis_pub_sub\RedisPubSub',
+			'connect' => [
+				'class' => 'yii\redis\Connection',
+				'hostname' => '127.0.0.1',
+				'port' => 6379,
+				'database' => 0,
+				'password' => 'byt6gc1w0aed2q7h',
+				'connectionTimeout' => 20,
+			]
+		],
+		'dict' => [
+			'class' => 'common\components\configDict',
+		],
+		'rabbitmq' => [
+			'class' => 'mikemadisonweb\rabbitmq\Configuration',
+			'connections' => [
+				[
+					'host' => '127.0.0.1',
+					'port' => '5672',
+					'user' => 'admin',
+					'password' => 'vn3oaz1i8w32k4mm9',
+					'vhost' => '/',
+				]
+			],
+			'exchanges' => [
+				[
+					'name' => 'ex1',
+					'type' => 'direct'
+				],
+			],
+			'queues' => [
+				[
+					'name' => 'queues1',
+					'passive' => false,
+				],
+				[
+					'name' => 'queues2',
+					'passive' => false,
+				],
+			],
+			'bindings' => [
+				[
+					'queue' => 'queues1',
+					'exchange' => 'ex1',
+					'routing_keys' => ['route1'],
+				],
+			],
+			'producers' => [
+				[
+					'name' => 'producers',
+				],
+			],
+			'consumers' => [
+				[
+					'name' => 'consumers',
+					'callbacks' => [
+						'queues1' => '\common\components\rabbitmq\ImportDataConsumer',
+					],
+				],
+			],
+		],
+		'mailer' => [
+			'class' => 'yii\swiftmailer\Mailer',
+			'useFileTransport' => false,
+			'transport' => [
+				'class' => 'Swift_SmtpTransport',
+				'host' => 'smtp.126.com',
+				'username' => 'zhhinc@126.com',
+				'password' => '',
+				'port' => '25',
+				'encryption' => 'tls',
+			],
+			'messageConfig' => [
+				'charset' => 'UTF-8',
+				'from' => ['zhhinc@126.com' => '系统邮件']
+			],
+		],
+	],
 ];

+ 15 - 34
common/config/params.php

@@ -1,37 +1,24 @@
 <?php
-$suffix = 'huahb.com';
-if (isset($_SERVER['HTTP_HOST'])) {
-	$hostInfo = $_SERVER['HTTP_HOST'];
-	$parse = parse_url($hostInfo);
-	$host = $parse['path'];
-	$pos = strpos($host, '.') + 1;
-	$suffix = substr($host, $pos);
-}
-
-$miniUrl = 'https://mini.' . $suffix;
-$imgUrl = 'http://img.' . $suffix;
-$adminUrl = 'http://a.' . $suffix;
-$frontUrl = 'http://m.' . $suffix;
-$mobileUrl = 'http://m.' . $suffix;
-
-$openUrl = 'http://o.' . $suffix;
-$picUrl = 'http://pic.' . $suffix;//阿里云oss图床
-$wwwUrl = 'http://www.' . $suffix;
-$cssUrl = 'http://css.' . $suffix;
-$jsUrl = 'http://js.' . $suffix;
-
-//redis键过期时间
-$oneHourExpireTime = 3600;
-$threeHourExpireTime = 3600 * 3;
-$oneDayExpireTime = 86400 * 1;
-$threeDayExpireTime = 86400 * 3;
-
+$hostData = \common\components\httpUtil::getHostData();
+$http = $hostData['http'];
+$suffix = $hostData['suffix'];
+$miniUrl = $http . 'mini.' . $suffix;
+$imgUrl = $http . 'img.' . $suffix;
+$adminUrl = $http . 'a.' . $suffix;
+$frontUrl = $http . 'm.' . $suffix;
+$mobileUrl = $http . 'm.' . $suffix;
+$openUrl = $http . 'o.' . $suffix;
+$picUrl = $http . 'pic.' . $suffix;
+$wwwUrl = $http . 'www.' . $suffix;
+$cssUrl = $http . 'css.' . $suffix;
+$jsUrl = $http . 'js.' . $suffix;
 
 return [
 	'adminEmail' => 'admin@example.com',
 	'supportEmail' => 'support@example.com',
 	'user.passwordResetTokenExpire' => 3600,
-	'secretKey' => 'cMWjvVY5F-dqT6XKnj81qheU2wI3Sok-',//全站统一使用的秘钥
+	//全站统一使用的秘钥
+	'secretKey' => 'cMWjvVY5F-dqT6XKnj81qheU2wI3Sok-',
 	'imgUrl' => $imgUrl,
 	'adminUrl' => $adminUrl,
 	'frontUrl' => $frontUrl,
@@ -40,10 +27,4 @@ return [
 	'wwwUrl' => $wwwUrl,
 	'mobileUrl' => $mobileUrl,
 	'miniUrl' => $miniUrl,
-	'oneHourExpireTime' => $oneHourExpireTime,
-	'threeHourExpireTime' => $threeHourExpireTime,
-	'oneDayExpireTime' => $oneDayExpireTime,
-	'threeDayExpireTime' => $threeDayExpireTime,
-	
-	'secretKey' => '6XKnj81qheU2wI3#C^LpNy~a8Sok#2019',
 ];