{"id":28600940,"url":"https://github.com/oldthreefeng/wechat-go","last_synced_at":"2025-06-11T14:39:29.099Z","repository":{"id":52015799,"uuid":"364806153","full_name":"oldthreefeng/wechat-go","owner":"oldthreefeng","description":null,"archived":false,"fork":false,"pushed_at":"2021-05-10T05:50:13.000Z","size":4842,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-06-21T18:04:55.099Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oldthreefeng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-06T06:23:14.000Z","updated_at":"2021-05-11T02:25:50.000Z","dependencies_parsed_at":"2022-08-24T09:10:17.730Z","dependency_job_id":null,"html_url":"https://github.com/oldthreefeng/wechat-go","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oldthreefeng%2Fwechat-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oldthreefeng%2Fwechat-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oldthreefeng%2Fwechat-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oldthreefeng%2Fwechat-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oldthreefeng","download_url":"https://codeload.github.com/oldthreefeng/wechat-go/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oldthreefeng%2Fwechat-go/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259280932,"owners_count":22833476,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-11T14:39:28.359Z","updated_at":"2025-06-11T14:39:29.089Z","avatar_url":"https://github.com/oldthreefeng.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wechat-go\n\n[![Build Status](https://travis-ci.com/oldthreefeng/wechat-go.svg?branch=main)](https://travis-ci.com/oldthreefeng/wechat-go)\n[![Go Report Card](https://goreportcard.com/badge/github.com/oldthreefeng/wechat-go)](https://goreportcard.com/report/github.com/oldthreefeng/wechat-go)\n[![codebeat badge](https://codebeat.co/badges/4f78bcb2-bf75-477d-a8f4-b09fde3dae80)](https://codebeat.co/projects/github-com-oldthreefeng-wechat-go-master)\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg)]()\n\n微信web版API的go实现，模拟微信网页版的登录／联系人／消息收发等功能，可以完全接管微信收到的消息, 并定制自己的发送内容\n\n* 支持多用户(多开)\n* 支持掉线后免扫码重登\n* 功能以插件的形式提供，可以根据用户(比如付费情况）选择加载或者不加载某插件\n* 插件编写简单, 可定制性强, 无需关心API和消息分发，二次开发极为方便\n* 对于加载的插件, 使用机器人的终端用户可以通过微信聊天界面动态开启/关闭.\n* 目前已提供头像(性别／年龄)识别, gif搜索, 笑话大全, \"阅后即焚\", 消息跨群转发, 中英互译等多个有趣插件\n* 可以发送图片/文字/gif/视频/表情等多种消息\n* 支持Linux/MacOSX/Windows, 树莓派也可以:)\n\n\n## 获取源码\n```\ngit clone github.com/oldthreefeng/wechat-go.git\ngo mod download \n```\n## 编译并运行\n#### linux/mac\n```\ncd wechat-go\ngo build .\n```\n\n## 插件\n\n## 插件列表\n###### switcher\n一个管理插件的插件\n\n```\n#关闭某个插件, 在微信聊天窗口输入\ndisable faceplusplus\n\n#开启某个插件, 在微信聊天窗口输入\nenable faceplusplus\n\n#查看所有插件信息, 在微信聊天窗口输入\ndump\n```\n\n###### faceplusplus\n对收到的图片做面部识别，返回性别和年龄\n\n###### gifer\n以收到的文字消息为关键字做gif搜索，返回gif图, 注意返回的gif可能尺度较大，比如文字消息中包含“污”等关键词。\n\n###### replier\n对收到的文字/图片消息，做自动应答，回复固定文字消息\n\n###### laosj\n随机获取一张美女图片, 在聊天窗口输入 美女\n\n###### joker\n获取一则笑话, 在聊天窗口输入 笑话\n\n###### revoker\n消息撤回插件, 3s后自动撤回手机端所发的文本消息. 机器人发出的消息需要自己在对应插件里写撤回逻辑.\n\n###### system\n处理消息撤回/红包等系统提示\n\n###### forwarder\n消息跨群转发, 在插件里修改群名的全拼即可.\n\n###### youdao\n中英互译插件, 基于有道翻译API\n\n###### verify\n自动接受好友请求, 可以按条件过滤\n\n###### share\n资源(纸牌屋)自动分发示例\n\n###### config\n配置管理插件\n设置配置, 在聊天窗口输入\n```\nset config key value\n```\n查看配置，在聊天窗口输入\n```\nget config key\n```\n在代码中使用配置\n```go\nimport \"github.com/oldthreefeng/wechat-go/kv\"\nfunc demo() {\n\tkv.KVStorageInstance.Set(\"key\", \"value\")\n\tv := kv.KVStorageInstance.Get(\"key\")\n\tif v == nil {\n\t\treturn\n\t}\n\t// v.(string) etc.\n}\n```\n\n## 制作自己的插件\n自定义插件的两个原则\n* 一个插件只完成一个功能，不在一个插件里加入多个handler\n* 插件默认开启\n\n插件示例\n```go\npackage demo // 以插件名命令包名\n\nimport (\n\t\"github.com/oldthreefeng/wechat-go/logs\" // 导入日志包\n\t\"github.com/oldthreefeng/wechat-go/wxweb\"  // 导入协议包\n)\n\n// 必须有的插件注册函数\n// 指定session, 可以对不同用户注册不同插件\nfunc Register(session *wxweb.Session) {\n\t// 将插件注册到session\n\t// 第一个参数: 指定消息类型, 所有该类型的消息都会被转发到此插件\n\t// 第二个参数: 指定消息处理函数, 消息会进入此函数\n\t// 第三个参数: 自定义插件名，不能重名，switcher插件会用到此名称\n\tsession.HandlerRegister.Add(wxweb.MSG_TEXT, wxweb.Handler(demo), \"textdemo\")\n\n\t// 开启插件\n\tif err := session.HandlerRegister.EnableByName(\"textdemo\"); err != nil {\n\t\tlogs.Error(err)\n\t}\n}\n\n// 消息处理函数\nfunc demo(session *wxweb.Session, msg *wxweb.ReceivedMessage) {\n\n\t// 可选: 可以用contact manager来过滤, 比如过滤掉没有保存到通讯录的群\n\t// 注意，contact manager只存储了已保存到通讯录的群组\n\tcontact := session.Cm.GetContactByUserName(msg.FromUserName)\n\tif contact == nil {\n\t\tlogs.Warn(\"ignore the messages from %v, cause you don't save the contact\", msg.FromUserName)\n\t\treturn\n\t}\n\n\t// 可选: 根据消息类型来过滤\n\tif msg.MsgType == wxweb.MSG_IMG {\n\t\treturn\n\t}\n\n\t// 可选: 根据wxweb.User数据结构中的数据来过滤\n\tif contact.PYQuanPin != \"oldthreefeng\" {\n\t\t// 比如根据用户昵称的拼音全拼来过滤\n\t\treturn\n\t}\n\n\t// 可选: 过滤和自己无关的群组消息\n\tif msg.IsGroup \u0026\u0026 msg.Who != session.Bot.UserName {\n\t\treturn\n\t}\n\n\t// 取出收到的内容\n\t// 取text\n\tlogs.Info(msg.Content)\n\t//// 取img\n\t//if b, err := session.GetImg(msg.MsgId); err == nil {\n\t//\tlogs.Debug(string(b))\n\t//}\n\n\t// anything\n\n\t// 回复消息\n\t// 第一个参数: 回复的内容\n\t// 第二个参数: 机器人ID\n\t// 第三个参数: 联系人/群组/特殊账号ID\n\tsession.SendText(\"plugin demo\", session.Bot.UserName, wxweb.RealTargetUserName(session, msg))\n\t// 回复图片和gif 参见wxweb/session.go\n\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foldthreefeng%2Fwechat-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foldthreefeng%2Fwechat-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foldthreefeng%2Fwechat-go/lists"}