Selaa lähdekoodia

域名的自动化配置

shish 6 vuotta sitten
vanhempi
commit
cbdf7bc090

+ 1 - 1
app/business/controllers/ChatController.php

@@ -23,7 +23,7 @@ class ChatController extends BaseController
 		UserService::valid($user, $this->merchantId);
 		return $this->renderPartial('index', ['userId' => $userId]);
 	}
-	
+
 	//聊天双方的用户信息 shish 2019.12.30
 	public function actionBegin()
 	{

+ 3 - 3
app/business/views/chat/index.php

@@ -15,7 +15,7 @@
                 case 'init':
                     clientId = data.client_id;
                     //当前发起的聊天会员与当前登陆用户绑定关系
-                    $.post('http://api.b.hhb.com/chat/bind-merchant', {clientId: clientId}, function (data) {
+                    $.post('<?= Yii::$app->params['b'] ?>/chat/bind-merchant', {clientId: clientId}, function (data) {
 
                     }, 'json');
                 default :
@@ -26,7 +26,7 @@
     function closeMsg()
     {
         console.log(clientId);
-        $.post('http://api.b.hhb.com/chat/close', {clientId: clientId}, function (data) {
+        $.post('<?= Yii::$app->params['b'] ?>/chat/close', {clientId: clientId}, function (data) {
 
         }, 'json');
     }
@@ -58,7 +58,7 @@
                 break;
             default:
         }
-        $.post('http://api.b.hhb.com/chat/send', data, function (data) {
+        $.post('<?= Yii::$app->params['b'] ?>/chat/send', data, function (data) {
         }, 'json');
     }
 

+ 3 - 3
app/client/views/chat/index.php

@@ -14,7 +14,7 @@
             switch (type) {
                 case 'init':
                     clientId = data.client_id;
-                    $.post('http://api.m.hhb.com/chat/bind-user', {clientId: clientId}, function (data) {
+                    $.post('<?= Yii::$app->params['c'] ?>/chat/bind-user', {clientId: clientId}, function (data) {
 
                     }, 'json');
                 default :
@@ -26,7 +26,7 @@
     function closeMsg()
     {
         console.log(clientId);
-        $.post('http://api.m.hhb.com/chat/close', {clientId: clientId}, function (data) {
+        $.post('<?= Yii::$app->params['c'] ?>/chat/close', {clientId: clientId}, function (data) {
 
         }, 'json');
     }
@@ -58,7 +58,7 @@
                 break;
             default:
         }
-        $.post('http://api.m.hhb.com/chat/send', data, function (data) {
+        $.post('<?= Yii::$app->params['c'] ?>/chat/send', data, function (data) {
         }, 'json');
     }
 

+ 48 - 3
common/config/params.php

@@ -12,7 +12,7 @@ $picUrl = $http . 'pic.' . $suffix;
 $wwwUrl = $http . 'www.' . $suffix;
 $cssUrl = $http . 'css.' . $suffix;
 $jsUrl = $http . 'js.' . $suffix;
-return [
+$config = [
 	//全站统一使用的秘钥
 	'secretKey' => 'CzWjvVY5F.dUqT65Knj81qh_eU2wI3SokO',
 	'imgUrl' => $imgUrl,
@@ -40,5 +40,50 @@ return [
 	'neverExpireTime' => 4102416000,
 	//永不过期日期
 	'neverExpireDate' => '2100-01-01 00:00:00',
-	'pageSize'=>20,
-];
+	'pageSize' => 20,
+];
+
+$prefixHttp = 'http://';
+$userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']) : '';
+if (strpos($userAgent, 'miniprogram') === true) {
+	$prefixHttp = 'https://';
+}
+$referrer = isset($_SERVER["HTTP_REFERER"]) ? strtolower($_SERVER["HTTP_REFERER"]) : '';
+if (strpos($referrer, 'servicewechat.com') === true) {
+	$prefixHttp = 'https://';
+}
+if (strpos($referrer, 'https') === true) {
+	$prefixHttp = 'https://';
+}
+
+if (getenv('YII_ENV') == 'local') {
+	$config['c'] = $prefixHttp . 'api.m.hhb.com/';
+	$config['b'] = $prefixHttp . 'api.b.hhb.com/';
+	if (strpos($referrer, $prefixHttp . 'h') === true || strpos($referrer, $prefixHttp . 'api.h') === true) {
+		$config['b'] = $prefixHttp . 'api.h.hhb.com/';
+	}
+	$config['s'] = $prefixHttp . 'api.s.hhb.com/';
+}
+if (getenv('YII_ENV') == 'test') {
+	$config['c'] = $prefixHttp . 'api.m.huaml.com/';
+	$config['b'] = $prefixHttp . 'api.b.huaml.com/';
+	if (strpos($referrer, $prefixHttp . 'h') === true || strpos($referrer, $prefixHttp . 'api.h') === true) {
+		$config['b'] = $prefixHttp . 'api.h.huaml.com/';
+	}
+	$config['s'] = $prefixHttp . 'api.s.huaml.com/';
+}
+if (getenv('YII_ENV') == 'development') {
+	$config['c'] = $prefixHttp . 'api.m.huaml.com/';
+	$config['b'] = $prefixHttp . 'api.b.huaml.com/';
+	if (strpos($referrer, $prefixHttp . 'h') === true || strpos($referrer, $prefixHttp . 'api.h') === true) {
+		$config['b'] = $prefixHttp . 'api.h.huaml.com/';
+	}
+	$config['s'] = $prefixHttp . 'api.s.huaml.com/';
+}
+if (getenv('YII_ENV') == 'production') {
+	$config['c'] = $prefixHttp . 'api.m.huahb.com/';
+	$config['b'] = $prefixHttp . 'api.b.huahb.com/';
+	$config['b'] = $prefixHttp . 'api.h.huahb.com/';
+	$config['s'] = $prefixHttp . 'api.s.huahb.com/';
+}
+return $config;