diff --git a/Cunkebao/next-env.d.ts b/Cunkebao/next-env.d.ts new file mode 100644 index 00000000..3cd7048e --- /dev/null +++ b/Cunkebao/next-env.d.ts @@ -0,0 +1,6 @@ +/// +/// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/app/api-reference/config/typescript for more information. diff --git a/Server/README_moments.md b/Server/README_moments.md new file mode 100644 index 00000000..9e31075d --- /dev/null +++ b/Server/README_moments.md @@ -0,0 +1,147 @@ +# 微信朋友圈数据处理功能 + +本模块提供了微信朋友圈数据的获取、存储和查询功能,支持保留驼峰命名结构的原始数据。 + +## 数据库表结构 + +项目包含一个数据表: + +**wechat_moments** - 存储朋友圈基本信息 +- `id`: 自增主键 +- `wechatAccountId`: 微信账号ID +- `wechatFriendId`: 微信好友ID +- `snsId`: 朋友圈消息ID +- `commentList`: 评论列表JSON +- `createTime`: 创建时间戳 +- `likeList`: 点赞列表JSON +- `content`: 朋友圈内容 +- `lat`: 纬度 +- `lng`: 经度 +- `location`: 位置信息 +- `picSize`: 图片大小 +- `resUrls`: 资源URL列表 +- `userName`: 用户名 +- `type`: 朋友圈类型 +- `create_time`: 数据创建时间 +- `update_time`: 数据更新时间 + +## API接口 + +### 1. 获取朋友圈信息 + +``` +GET/POST /api/websocket/getMoments +``` + +**参数:** +- `wechatAccountId`: 微信账号ID +- `wechatFriendId`: 微信好友ID +- `count`: 获取条数,默认5条 + +获取指定账号和好友的朋友圈信息,并自动保存到数据库。 + +### 2. 保存单条朋友圈数据 + +``` +POST /api/websocket/saveSingleMoment +``` + +**参数:** +- `commentList`: 评论列表 +- `createTime`: 创建时间戳 +- `likeList`: 点赞列表 +- `momentEntity`: 朋友圈实体,包含以下字段: + - `content`: 朋友圈内容 + - `lat`: 纬度 + - `lng`: 经度 + - `location`: 位置信息 + - `picSize`: 图片大小 + - `resUrls`: 资源URL列表 + - `urls`: 媒体URL列表 + - `userName`: 用户名 +- `snsId`: 朋友圈ID +- `type`: 朋友圈类型 +- `wechatAccountId`: 微信账号ID +- `wechatFriendId`: 微信好友ID + +保存单条朋友圈数据到数据库,保持原有的驼峰数据结构。系统会将`momentEntity`中的字段提取并单独存储,不包括`objectType`和`createTime`字段。 + +### 3. 获取朋友圈数据列表 + +``` +GET/POST /api/websocket/getMomentsList +``` + +**参数:** +- `wechatAccountId`: 微信账号ID (可选) +- `wechatFriendId`: 微信好友ID (可选) +- `page`: 页码,默认1 +- `pageSize`: 每页条数,默认10 +- `startTime`: 开始时间戳 (可选) +- `endTime`: 结束时间戳 (可选) + +获取已保存的朋友圈数据列表,支持分页和条件筛选。返回的数据会自动构建`momentEntity`字段以保持API兼容性。 + +### 4. 获取朋友圈详情 + +``` +GET/POST /api/websocket/getMomentDetail +``` + +**参数:** +- `snsId`: 朋友圈ID +- `wechatAccountId`: 微信账号ID + +获取单条朋友圈的详细信息,包括评论、点赞和资源URL等。返回的数据会自动构建`momentEntity`字段以保持API兼容性。 + +## 使用示例 + +### 保存单条朋友圈数据 + +```php +$data = [ + 'commentList' => [], + 'createTime' => 1742777232, + 'likeList' => [], + 'momentEntity' => [ + 'content' => "第一位个人与Stussy联名的中国名人,不是陈冠希,不是葛民辉,而是周杰伦!", + 'lat' => 0, + 'lng' => 0, + 'location' => "", + 'picSize' => 0, + 'resUrls' => [], + 'snsId' => "-3827269039168736643", + 'urls' => ["http://wxapp.tc.qq.com/251/20304/stodownload?encfilekey=..."], + 'userName' => "wxid_afixeeh53lt012" + ], + 'snsId' => "-3827269039168736643", + 'type' => 28, + 'wechatAccountId' => 123456, // 替换为实际的微信账号ID + 'wechatFriendId' => "wxid_example" // 替换为实际的微信好友ID +]; + +// 发送请求 +$result = curl_post('/api/websocket/saveSingleMoment', $data); +``` + +### 查询朋友圈列表 + +```php +// 获取特定账号的朋友圈 +$params = [ + 'wechatAccountId' => 123456, + 'page' => 1, + 'pageSize' => 20 +]; + +// 发送请求 +$result = curl_get('/api/websocket/getMomentsList', $params); +``` + +## 注意事项 + +1. 所有JSON格式的数据在保存时都会进行编码,查询时会自动解码并还原为原始数据结构。 +2. 数据库中的字段名保持驼峰命名格式,与微信API返回的数据结构保持一致。 +3. 尽管数据库中将`momentEntity`的字段拆分为独立字段存储,但API接口返回时会重新构建`momentEntity`结构,以保持与原始API的兼容性。 +4. `objectType`和`createTime`字段已从`momentEntity`中移除,不再单独存储。 +5. 图片或视频资源URLs直接存储在朋友圈主表中,不再单独存储到资源表。 \ No newline at end of file diff --git a/Server/README_wechat_chatroom_sync.md b/Server/README_wechat_chatroom_sync.md new file mode 100644 index 00000000..fb2e1868 --- /dev/null +++ b/Server/README_wechat_chatroom_sync.md @@ -0,0 +1,105 @@ +# 微信群聊同步功能 + +本功能用于自动同步微信群聊数据,支持分页获取群聊列表以及群成员信息,并将数据保存到数据库中。 + +## 功能特点 + +1. 支持分页获取微信群聊列表 +2. 自动获取每个群聊的成员信息 +3. 支持通过关键词筛选群聊 +4. 支持按微信账号筛选群聊 +5. 可选择是否包含已删除的群聊 +6. 使用队列处理,支持大量数据的同步 +7. 支持失败重试机制 +8. 提供命令行和HTTP接口两种触发方式 + +## 数据表结构 + +本功能使用以下数据表: + +1. **wechat_chatroom** - 存储微信群聊信息 +2. **wechat_chatroom_member** - 存储微信群聊成员信息 + +## 使用方法 + +### 1. HTTP接口触发 + +``` +GET/POST /api/wechat_chatroom/syncChatrooms +``` + +**参数:** +- `pageIndex`: 起始页码,默认0 +- `pageSize`: 每页大小,默认100 +- `keyword`: 群名关键词,可选 +- `wechatAccountKeyword`: 微信账号关键词,可选 +- `isDeleted`: 是否包含已删除群聊,可选 + +**示例:** +``` +/api/wechat_chatroom/syncChatrooms?pageSize=50 +``` + +### 2. 命令行触发 + +```bash +php think sync:wechat:chatrooms [选项] +``` + +**选项:** +- `-p, --pageIndex`: 起始页码,默认0 +- `-s, --pageSize`: 每页大小,默认100 +- `-k, --keyword`: 群名关键词,可选 +- `-a, --account`: 微信账号关键词,可选 +- `-d, --deleted`: 是否包含已删除群聊,可选 + +**示例:** +```bash +# 基本用法 +php think sync:wechat:chatrooms + +# 指定页大小和关键词 +php think sync:wechat:chatrooms -s 50 -k "测试群" + +# 指定账号关键词 +php think sync:wechat:chatrooms --account "张三" +``` + +### 3. 定时任务配置 + +可以将命令添加到系统的定时任务(crontab)中,实现定期自动同步: + +``` +# 每天凌晨3点执行微信群聊同步 +0 3 * * * cd /path/to/your/project && php think sync:wechat:chatrooms +``` + +## 队列消费者配置 + +为了处理同步任务,需要启动队列消费者: + +```bash +# 启动微信群聊队列消费者 +php think queue:work --queue wechat_chatrooms +``` + +建议在生产环境中使用supervisor等工具来管理队列消费者进程。 + +## 同步过程 + +1. 触发同步任务,将初始页任务加入队列 +2. 队列消费者处理任务,获取当前页的群聊列表 +3. 如果当前页有数据且数量等于页大小,则将下一页任务加入队列 +4. 对每个获取到的群聊,添加获取群成员的任务 +5. 所有数据会自动保存到数据库中 + +## 调试与日志 + +同步过程的日志会记录在应用的日志目录中,可以通过查看日志了解同步状态和错误信息。 + +## 注意事项 + +1. 页大小建议设置为合理值(50-100),过大会导致请求超时 +2. 当数据量较大时,建议增加队列消费者的数量 +3. 确保系统授权信息正确,否则无法获取数据 +4. 数据同步是增量的,会自动更新已存在的记录 \ No newline at end of file diff --git a/Server/crontab_tasks.md b/Server/crontab_tasks.md new file mode 100644 index 00000000..00aadff3 --- /dev/null +++ b/Server/crontab_tasks.md @@ -0,0 +1,88 @@ +# 新版微信服务器定时任务配置 + +以下为当前 command.php 注册的所有计划任务示例,按需调整执行频率和日志路径。 + +```bash +# 设备列表 +*/30 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think device:list >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/device_list.log 2>&1 + +# 微信好友列表 +*/5 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think wechatFriends:list >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/wechat_friends_list.log 2>&1 + +# 微信群列表 +*/30 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think wechatChatroom:list >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/wechat_chatroom_list.log 2>&1 + +# 添加好友任务列表 +*/30 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think friendTask:list >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/friend_task_list.log 2>&1 + +# 微信客服列表 +*/30 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think wechatList:list >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/wechat_list.log 2>&1 + +# 公司账号列表 +*/30 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think account:list >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/account_list.log 2>&1 + +# 微信好友消息列表 +*/30 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think message:friendsList >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/message_friends_list.log 2>&1 + +# 微信群聊消息列表 +*/30 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think message:chatroomList >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/message_chatroom_list.log 2>&1 + +# 部门列表 +*/30 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think department:list >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/department_list.log 2>&1 + +# 同步内容库 +0 2 * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think content:sync >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/content_sync.log 2>&1 + +# 微信群好友列表 +*/30 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think groupFriends:list >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/group_friends_list.log 2>&1 + +# 分配规则列表 +0 3 * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think allotrule:list >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/allot_rule_list.log 2>&1 + +# 自动创建分配规则 +0 4 * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think allotrule:autocreate >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/allot_rule_autocreate.log 2>&1 + +# 内容采集任务 +0 5 * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think content:collect >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/content_collect.log 2>&1 + +# 朋友圈采集任务 +0 6 * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think moments:collect >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/moments_collect.log 2>&1 + +# 工作台自动点赞任务 +0 7 * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think workbench:autoLike >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/workbench_auto_like.log 2>&1 + +# 工作台朋友圈同步任务 +0 8 * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think workbench:moments >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/workbench_moments.log 2>&1 + +# 同步微信数据到存客宝 +0 9 * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think sync:wechatData >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/sync_wechat_data.log 2>&1 + +# 工作台流量分发 +0 9 * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think workbench:trafficDistribute >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/traffic_distribute.log 2>&1 + +# 预防性切换好友 +*/2 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think switch:friends >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/switch_friends.log 2>&1 + + +``` + +## 说明 + +- 所有命令都在 `/www/wwwroot/mckb_quwanzhi_com/Server` 目录下执行 +- 默认只获取未删除(活跃)的设备、微信好友和群聊 +- 已注释的命令(以#开头)是获取已删除或已停用数据的任务,可根据需要取消注释启用 +- 每个命令的执行结果都会记录到对应的日志文件中 +- 日志文件名格式包含了数据状态(如 `_active`, `_deleted`, `_stopped`) +- 日志文件位于 `/www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/` 目录下 +- 大部分任务每5分钟执行一次(`*/5 * * * *` 表示每小时的第0,5,10,15...55分钟执行) +- 设备列表的未删除设备任务每天凌晨1点执行一次(`0 1 * * *`) +- 自动创建分配规则每小时整点执行一次(`0 * * * *`) +- 内容采集任务每5分钟执行一次(`*/5 * * * *`) + +## 检查定时任务 + +使用以下命令查看当前配置的 crontab 任务: + +```bash +crontab -l +``` \ No newline at end of file