# 企微 H5 应用配置指南 (D-T4) - 完整版 ## 前置条件 | 依赖 | 状态 | 说明 | |------|------|------| | GoFlyLiveChat 服务 | ✅ 已运行 | `http://10.90.5.110:8081` | | SSL 证书 | ✅ 已有 | 使用 itsupport.servyou.com.cn 证书 | | 企微 OAuth2 | ❌ 待开发 | 需要对接企微用户体系 | --- ## 整体架构 ``` 用户 → 企微工作台 → 应用 → HTTPS(itsupport.servyou.com.cn/gofly) ↓ Nginx反向代理 ↓ GoFlyLiveChat:8081 ↓ MySQL数据库 ``` --- ## 配置步骤 ### 步骤1:Nginx 反向代理配置 在现有 Nginx 上添加 GoFlyLiveChat 路由(子路径): ```bash # 在生产服务器(10.90.5.110)上执行 # 1. 创建 Nginx 配置 cat > /etc/nginx/conf.d/gofly.conf << 'EOF' # GoFlyLiveChat 子路径代理 location /gofly { proxy_pass http://127.0.0.1:8081; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; # WebSocket 支持 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; # 解决WebSocket子路径问题 proxy_redirect ~^/(.*)$ /gofly/$1; } # 根路径重定向到IT服务台 location = /gofly { return 301 /gofly/; } EOF # 2. 测试配置 nginx -t # 3. 重载 Nginx nginx -s reload ``` > ⚠️ 注意:GoFlyLiveChat 可能不支持子路径,需要使用独立子域名 --- ### 方案B:独立子域名(如需要) 如果GoFlyLiveChat不支持子路径,使用独立子域名: ``` https://itdesk.servyou.com.cn → IT服务台(H5) https://itsupport.servyou.com.cn → 主域名(现有) https://chat.servyou.com.cn → GoFlyLiveChat(新申请) ``` --- ### 步骤2:企微应用配置 1. 登录企微管理后台:https://work.weixin.qq.com 2. **应用管理** → **自建应用** → **创建应用** | 字段 | 示例值 | 说明 | |------|--------|------| | 应用名称 | IT智能服务台 | 展示给用户 | | 应用主页 | `https://itsupport.servyou.com.cn/gofly` | **必须HTTPS** | | 可信域名 | `servyou.com.cn` | 用于OAuth2 | 3. **网页授权及JS-SDK** → 设置可信域名 4. **发布应用** → 设置可见范围 --- ### 步骤3:企微 OAuth2 集成(开发任务) GoFlyLiveChat 需要改造支持企微OAuth2: #### 3.1 获取企微授权 用户访问应用时重定向到: ``` https://open.weixin.qq.com/connect/oauth2/authorize? appid=CORP_ID& redirect_uri=URL-encoded(https://itsupport.servyou.com.cn/gofly/callback)& response_type=code& scope=snsapi_base& state=STATE# wechat_redirect ``` #### 3.2 回调处理 ```python # 获取用户身份 code = request.GET.get('code') # 调用企微接口获取用户ID user_id = wecom_api.get_user_id(code) # 创建/更新用户会话 ``` #### 3.3 与现有系统对接 | 现有系统 | 对接方式 | |----------|----------| | 用户表 | 通过企微user_id关联 | | 角色体系 | 映射企微部门到角色 | | 会话管理 | 使用现有session或JWT | --- ## 完整配置清单 | 序号 | 任务 | 负责人 | 状态 | |------|------|--------|------| | 1 | Nginx 配置 /gofly 路由 | 运维 | ⏳ | | 2 | 测试子路径访问 | 工程师 | ⏳ | | 3 | 企微创建自建应用 | 运维 | ⏳ | | 4 | 开发 OAuth2 集成代码 | 工程师 | ⏳ | | 5 | 测试完整流程 | QA | ⏳ | --- ## 访问地址 | 环境 | 地址 | 说明 | |------|------|------| | 测试 | `http://10.90.5.110:8081` | 已运行 | | 生产 | `https://itsupport.servyou.com.cn/gofly` | 需配置Nginx | --- ## 验证清单 - [ ] Nginx /gofly 路由配置生效 - [ ] HTTPS 访问正常 - [ ] GoFlyLiveChat 服务正常 - [ ] 企微应用可访问 - [ ] OAuth2 登录流程正常