shenshihai 2 年之前
父节点
当前提交
e8a6184c32
共有 2 个文件被更改,包括 29 次插入2 次删除
  1. 9 1
      src/PackageClass.php
  2. 20 1
      src/Utility.php

+ 9 - 1
src/PackageClass.php

@@ -254,7 +254,15 @@ class PackageClass
 			}
 			logInfo("succeeded to decode config file -- .distribute/config.json");
 		}
-
+		
+		//如果检测到在SIS内网,替换成内网IP
+		$clientip = getClientIp();
+		if($clientip === false){
+			return false;
+		}
+		else if( $clientip == '39.171.62.20'){
+			self::$config['oss-host'] = 'http://192.168.3.10:8996';
+		}
 		return true;
 	}
 	

+ 20 - 1
src/Utility.php

@@ -9,6 +9,7 @@ function defaultConfig(){
 		'mysql-host'=> '',
 	);
 }
+
 //记录信息日志
 function logInfo(){
 	$content = '[INF] ';
@@ -33,7 +34,25 @@ function logError(){
 	print($content);
 	file_put_contents(LOG_PATH, $content, FILE_APPEND);
 }
-
+//获取用户IP
+function getClientIp(){
+	$url = 'http://8.136.238.47:3000/user/clientip';
+	$data = file_get_contents($url);
+	if($data === false){
+		logError('failed to get client ip',$url);
+		return false;
+	}
+	$json = json_decode($data);
+	if(!$json){
+		logError('failed to parse client ip data',$data);
+		return false;
+	}
+	if(!$json['data']['ip']){
+		logError('failed to parse client ip',$data);
+		return false;
+	}
+	return $json['data']['ip'];
+}
 //获取操作系统名称
 function getOsName(){
 	if(substr(PHP_OS,0,3)==='WIN')