Files
wecome-middleware/test-server.py
xudw 034d425b21 初始提交: WeCom Middleware项目基础结构
包含以下内容:
1. Spring Boot后端项目结构
2. Vue.js前端项目结构
3. Docker Compose部署配置
4. MySQL数据库初始化脚本
5. Redis缓存配置
6. Nginx反向代理配置
7. 完整的项目文档

技术栈:
- 后端: Spring Boot 2.7.18 + Java 11 + MyBatis Plus
- 前端: Vue.js 3 + TypeScript + Element Plus
- 数据库: MySQL 8.0 + Redis 7
- 部署: Docker Compose + Nginx

已部署服务:
- 后端API: http://localhost:18080
- 前端界面: http://localhost:13000
- 数据库管理: http://localhost:18081
- MySQL: localhost:13306
- Redis: localhost:16379
2026-03-09 12:39:09 +08:00

238 lines
9.2 KiB
Python
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
WeCom Middleware 测试服务器
用于快速验证项目结构和访问地址
"""
from http.server import HTTPServer, BaseHTTPRequestHandler
import json
import time
import socket
class TestHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
html = """
<!DOCTYPE html>
<html>
<head>
<title>WeCom Middleware - 测试服务器</title>
<style>
body { font-family: Arial, sans-serif; margin: 40px; }
.container { max-width: 800px; margin: 0 auto; }
.header { background: #4CAF50; color: white; padding: 20px; border-radius: 5px; }
.card { background: #f9f9f9; padding: 20px; margin: 20px 0; border-radius: 5px; }
.status { padding: 10px; margin: 10px 0; border-radius: 3px; }
.success { background: #d4edda; color: #155724; }
.warning { background: #fff3cd; color: #856404; }
.error { background: #f8d7da; color: #721c24; }
.link { color: #007bff; text-decoration: none; }
.link:hover { text-decoration: underline; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🚀 WeCom Middleware 测试服务器</h1>
<p>企业微信与OpenClaw双向通信中间件</p>
</div>
<div class="card">
<h2>📋 项目状态</h2>
<div class="status success">
✅ 项目架构已创建完成
</div>
<div class="status warning">
⚠️ 后端服务需要编译启动
</div>
<div class="status warning">
⚠️ 前端服务需要构建启动
</div>
</div>
<div class="card">
<h2>🌐 访问地址</h2>
<ul>
<li><a class="link" href="http://localhost:8080" target="_blank">后端API服务 (Spring Boot)</a></li>
<li><a class="link" href="http://localhost:3000" target="_blank">前端管理界面 (Vue)</a></li>
<li><a class="link" href="http://localhost:8080/api/system/status" target="_blank">系统状态接口</a></li>
<li><a class="link" href="http://localhost:8080/api/system/health" target="_blank">健康检查接口</a></li>
<li><a class="link" href="http://localhost:8081" target="_blank">数据库管理 (Adminer)</a></li>
</ul>
</div>
<div class="card">
<h2>🔧 快速启动</h2>
<pre><code># 进入项目目录
cd /root/.openclaw/workspace/wecom-middleware
# 一键启动(推荐)
./start.sh
# 或者手动启动
docker-compose up -d</code></pre>
</div>
<div class="card">
<h2>📁 项目结构</h2>
<pre><code>wecom-middleware/
├── backend/ # Spring Boot后端
├── frontend/ # Vue前端
├── docker/ # Docker配置
├── scripts/ # 数据库脚本
├── docker-compose.yml # Docker Compose配置
├── build.sh # 构建脚本
├── start.sh # 启动脚本
└── README.md # 项目文档</code></pre>
</div>
<div class="card">
<h2>📞 技术支持</h2>
<p>如果遇到问题,请检查:</p>
<ol>
<li>Docker和Docker Compose是否安装</li>
<li>端口是否被占用8080, 3000, 3306, 6379, 8081</li>
<li>查看日志:<code>docker-compose logs -f</code></li>
</ol>
</div>
</div>
</body>
</html>
"""
self.wfile.write(html.encode())
elif self.path == '/api/system/status':
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
status = {
"success": True,
"message": "WeCom Middleware 测试服务器运行中",
"timestamp": int(time.time()),
"services": {
"backend": {
"status": "待启动",
"port": 8080,
"url": "http://localhost:8080"
},
"frontend": {
"status": "待启动",
"port": 3000,
"url": "http://localhost:3000"
},
"mysql": {
"status": "待启动",
"port": 3306
},
"redis": {
"status": "待启动",
"port": 6379
}
},
"project": {
"name": "WeCom Middleware",
"version": "1.0.0",
"description": "企业微信与OpenClaw双向通信中间件"
}
}
self.wfile.write(json.dumps(status, indent=2).encode())
elif self.path == '/api/system/health':
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
health = {
"status": "UP",
"timestamp": int(time.time()),
"components": {
"testServer": "UP",
"backend": "DOWN",
"frontend": "DOWN",
"database": "DOWN",
"cache": "DOWN"
},
"message": "测试服务器运行正常其他服务需要启动Docker容器"
}
self.wfile.write(json.dumps(health, indent=2).encode())
else:
self.send_response(404)
self.send_header('Content-type', 'application/json')
self.end_headers()
error = {
"error": "Not Found",
"path": self.path,
"message": "请访问 / 或 /api/system/status"
}
self.wfile.write(json.dumps(error, indent=2).encode())
def do_POST(self):
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
response = {
"success": True,
"message": "POST请求已接收",
"timestamp": int(time.time()),
"method": "POST"
}
self.wfile.write(json.dumps(response, indent=2).encode())
def log_message(self, format, *args):
# 简化日志输出
print(f"[{time.strftime('%Y-%m-%d %H:%M:%S')}] {format % args}")
def get_local_ip():
"""获取本地IP地址"""
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ip = s.getsockname()[0]
s.close()
return ip
except:
return "127.0.0.1"
def main():
port = 9090
local_ip = get_local_ip()
print("=" * 60)
print("🚀 WeCom Middleware 测试服务器启动中...")
print("=" * 60)
print(f"📡 本地访问: http://localhost:{port}")
print(f"🌐 网络访问: http://{local_ip}:{port}")
print("=" * 60)
print("📋 项目状态:")
print(" ✅ 完整的项目架构已创建")
print(" ✅ Docker Compose配置完成")
print(" ✅ 数据库脚本已准备")
print(" ✅ 前后端代码框架完成")
print("=" * 60)
print("🔧 启动完整服务:")
print(" 1. cd /root/.openclaw/workspace/wecom-middleware")
print(" 2. ./start.sh # 一键启动")
print("")
print(" 2. docker-compose up -d")
print("=" * 60)
print("🌐 完整服务访问地址:")
print(" - 前端管理界面: http://localhost:3000")
print(" - 后端API服务: http://localhost:8080")
print(" - 数据库管理: http://localhost:8081")
print("=" * 60)
try:
server = HTTPServer(('0.0.0.0', port), TestHandler)
print(f"✅ 测试服务器已启动,按 Ctrl+C 停止")
print("=" * 60)
server.serve_forever()
except KeyboardInterrupt:
print("\n🛑 测试服务器已停止")
except Exception as e:
print(f"❌ 启动失败: {e}")
if __name__ == '__main__':
main()