shish il y a 6 ans
Parent
commit
a103093baf

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

@@ -6,7 +6,7 @@
     var clientId='';
     var ws;
     function openMsg() {
-        ws = new WebSocket("ws://127.0.0.1:8282");
+        ws = new WebSocket("ws://<?= Yii::$app->params['host'] ?>:8282");
         //服务端主动推送消息时会触发这里
         ws.onmessage = function (e) {
             var data = eval("(" + e.data + ")");

+ 2 - 2
app/business/views/main/index.php

@@ -4,7 +4,7 @@
     var clientId;
     var ws;
     function openMsg() {
-        ws = new WebSocket("ws://127.0.0.1:8282");
+        ws = new WebSocket("ws://<?= Yii::$app->params['host'] ?>:8282");
         //服务端主动推送消息时会触发这里
         ws.onmessage = function (e) {
             var data = eval("(" + e.data + ")");
@@ -13,7 +13,7 @@
                 case 'init':
                     clientId = data.client_id;
                     //当前发起的会话与平台绑定关系
-                    $.post('http://api.b.hhb.com/chat/bind-console', {clientId: clientId}, function (data) {
+                    $.post('<?= Yii::$app->params['b'] ?>/chat/bind-console', {clientId: clientId}, function (data) {
                     }, 'json');
                 case 'newMessage':
                     if (data.status == 1) {

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

@@ -6,7 +6,7 @@
     var clientId;
     var ws;
     function openMsg() {
-        ws = new WebSocket("ws://127.0.0.1:8282");
+        ws = new WebSocket("ws://<?= Yii::$app->params['host'] ?>:8282");
         //服务端主动推送消息时会触发这里
         ws.onmessage = function (e) {
             var data = eval("(" + e.data + ")");

+ 4 - 0
common/config/params.php

@@ -63,6 +63,7 @@ if (getenv('YII_ENV') == 'local') {
 		$config['b'] = $prefixHttp . 'api.h.hhb.com';
 	}
 	$config['s'] = $prefixHttp . 'api.s.hhb.com';
+	$config['host'] = 'hhb.com';
 }
 if (getenv('YII_ENV') == 'test') {
 	$config['c'] = $prefixHttp . 'api.m.huaml.com';
@@ -71,6 +72,7 @@ if (getenv('YII_ENV') == 'test') {
 		$config['b'] = $prefixHttp . 'api.h.huaml.com';
 	}
 	$config['s'] = $prefixHttp . 'api.s.huaml.com';
+	$config['host'] = 'huaml.com';
 }
 if (getenv('YII_ENV') == 'development') {
 	$config['c'] = $prefixHttp . 'api.m.huaml.com';
@@ -79,11 +81,13 @@ if (getenv('YII_ENV') == 'development') {
 		$config['b'] = $prefixHttp . 'api.h.huaml.com';
 	}
 	$config['s'] = $prefixHttp . 'api.s.huaml.com';
+	$config['host'] = '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';
+	$config['host'] = 'huahb.com';
 }
 return $config;

+ 21 - 20
vendor/workerman/GatewayWorker/Applications/retail/start_gateway.php

@@ -1,4 +1,4 @@
-<?php 
+<?php
 /**
  * This file is part of workerman.
  *
@@ -39,27 +39,28 @@ $gateway->registerAddress = '127.0.0.1:1238';
 // 心跳数据
 //$gateway->pingData = '{"type":"ping"}';
 
-/* 
+
 // 当客户端连接上来时,设置连接的onWebSocketConnect,即在websocket握手时的回调
-$gateway->onConnect = function($connection)
-{
-    $connection->onWebSocketConnect = function($connection , $http_header)
-    {
-        // 可以在这里判断连接来源是否合法,不合法就关掉连接
-        // $_SERVER['HTTP_ORIGIN']标识来自哪个站点的页面发起的websocket链接
-        if($_SERVER['HTTP_ORIGIN'] != 'http://kedou.workerman.net')
-        {
-            $connection->close();
-        }
-        // onWebSocketConnect 里面$_GET $_SERVER是可用的
-        // var_dump($_GET, $_SERVER);
-    };
-}; 
-*/
+$gateway->onConnect = function ($connection) {
+	$connection->onWebSocketConnect = function ($connection, $http_header) {
+		// 可以在这里判断连接来源是否合法,不合法就关掉连接
+		// $_SERVER['HTTP_ORIGIN']标识来自哪个站点的页面发起的websocket链接
+		if ($_SERVER['HTTP_ORIGIN'] != 'http://huahb.com') {
+			//$connection->close();
+		}
+
+		if (strpos($_SERVER['HTTP_ORIGIN'], 'huahb.com') !== true && strpos($_SERVER['HTTP_ORIGIN'], 'huaml.com') !== true && strpos($_SERVER['HTTP_ORIGIN'], 'hhb.com') !== true) {
+			$connection->close();
+		}
+
+		// onWebSocketConnect 里面$_GET $_SERVER是可用的
+		// var_dump($_GET, $_SERVER);
+	};
+};
+
 
 // 如果不是在根目录启动,则运行runAll方法
-if(!defined('GLOBAL_START'))
-{
-    Worker::runAll();
+if (!defined('GLOBAL_START')) {
+	Worker::runAll();
 }