Wechaty Gateway 使用教程
source link: https://wechaty.js.org/2022/04/13/wechaty-gateway-use/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
- wechaty 属于开源工具,并没有太多的义务帮你解决问题
- 大家也多是一步一步学习的,工具做好了基本也潜水了
- 所以请尝试自己查找资料
- 我喜欢go嘛
提问的艺术
- 其实 wechaty官网 已经很详细了,这里有很多的文档可供参考
- 使用谷歌语法
wechaty go xp
- 使用 Github 搜索
org:wechaty roomInvitation
- 请将你的
问题,代码,错误日志
一起提交到 issues - 希望你能接受上面的说法,感谢
flowchart LR
Polyglot-->Python
Polyglot-->Go
Polyglot -->Rust
Python-->Grpc
Go-->Grpc
Rust-->Grpc
Grpc-->Puppet
Puppet-->Padlocal
Puppet-->Wechat4U
Puppet-->XP
Padlocal-->微信
Wechat4U-->微信
XP-->微信
Wechat4U
- 首先确定你能不能使用网页版登录
- Wechat4U Token 不需要钱,随机生成就好
- 下面这一套不需要 docker,安装简单
flowchart LR
Polyglot-->Python
Polyglot-->Go
Polyglot -->Rust
Python-->Grpc
Go-->Grpc
Rust-->Grpc
Grpc-->Gateway{Gateway}-->Wechat4U
Wechat4U-->微信
Gateway
npm install -g wechaty wechaty-puppet-wechat4u
# npm --registry https://registry.npm.taobao.org install -g wechaty wechaty-puppet-wechat4u
export WECHATY_PUPPET="wechaty-puppet-wechat4u"
export WECHATY_TOKEN="d6e8b1c7-6fcd-4e32-b3f6-8d1e73388458"
# export WECHATY_TOKEN=$(curl -s https://www.uuidgenerator.net/api/version4)
export WECHATY_PUPPET_SERVICE_TOKEN="insecure_d6e8b1c7-6fcd-4e32-b3f6-8d1e73388458"
# export WECHATY_PUPPET_SERVICE_TOKEN="insecure_$(curl -s https://www.uuidgenerator.net/api/version4)"
export WECHATY_LOG="verbose"
export WECHATY_PUPPET_SERVER_PORT="25000"
export WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_SERVER=true
wechaty gateway --puppet ${WECHATY_PUPPET} --port ${WECHATY_PUPPET_SERVER_PORT} --token ${WECHATY_PUPPET_SERVICE_TOKEN} --puppet-token ${WECHATY_TOKEN}
上面这些就是网关啦,希望你能使用它来作为你的常用工具
wechaty 会在当前目录生成 Gateway.memory-card.json
有了这个文件就不需要总是重新登陆了
Polyglot(wechat4u)
// 其他的官网 demo 照抄就OK,这个使用的是 go-wechaty
// demo: https://github.com/wechaty/go-wechaty/blob/master/examples/ding-dong-bot.go
var bot = wechaty.NewWechaty(wechaty.WithPuppetOption(wp.Option{
Token: "insecure_d6e8b1c7-6fcd-4e32-b3f6-8d1e73388458",
Endpoint: "127.0.0.1:25000",
Timeout: time.Second * 10,
}))
- 相比而言,padLocal 协议更稳定
- XP Token 不需要钱,随机生成就好
- 下面这一套不需要 docker,安装简单
- 安装微信
- Demo : Go-wechaty-Bot - 欢迎下载体验、踢出宝贵的修复建议
flowchart LR
Polyglot-->Python
Polyglot-->Go
Polyglot -->Rust
Python-->Grpc
Go-->Grpc
Rust-->Grpc
Grpc-->Gateway{Gateway}-->XP
XP-->微信
Gateway(wechat4u)
# 这些仅适用于 Windows,因为 xp 支持的是Windows版本微信
npm install -g wechaty wechaty-puppet-xp
# npm --registry https://registry.npm.taobao.org install -g wechaty wechaty-puppet-wechat4u
set WECHATY_PUPPET="wechaty-puppet-xp"
set WECHATY_TOKEN="d6e8b1c7-6fcd-4e32-b3f6-8d1e73388458"
# set WECHATY_TOKEN=$(curl -s https://www.uuidgenerator.net/api/version4)
set WECHATY_PUPPET_SERVICE_TOKEN="insecure_d6e8b1c7-6fcd-4e32-b3f6-8d1e73388458"
# set WECHATY_PUPPET_SERVICE_TOKEN="insecure_$(curl -s https://www.uuidgenerator.net/api/version4)"
set WECHATY_LOG="verbose"
set WECHATY_PUPPET_SERVER_PORT="25000"
set WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_SERVER=true
wechaty gateway --puppet %WECHATY_PUPPET% --port %WECHATY_PUPPET_SERVER_PORT% --token %WECHATY_PUPPET_SERVICE_TOKEN% --puppet-token %WECHATY_TOKEN%
上面这一堆麻烦的东西就是网关啦,希望你能使用它来作为你的好助手!
Polyglot(xp)
// 其他的官网 demo 照抄就OK,这个使用的是 go-wechaty
// demo: https://github.com/wechaty/go-wechaty/blob/master/examples/ding-dong-bot.go
var bot = wechaty.NewWechaty(wechaty.WithPuppetOption(wp.Option{
Token: "insecure_d6e8b1c7-6fcd-4e32-b3f6-8d1e73388458",
Endpoint: "127.0.0.1:25000",
Timeout: time.Second * 10,
}))
Gateway(xp)
func OnScan(ctx *wechaty.Context) {
os.exit(0)
---------------------------------------
➜ time go run test.go
2022/04/13 22:09:40 PuppetService Start()
2022/04/13 22:09:42 PuppetService onGrpcStreamEvent({type:EVENT_TYPE_HEARTBEAT payload:{"data":"Wechaty Puppet gRPC stream connect successfully"}})
2022/04/13 22:09:42 PuppetService onGrpcStreamEvent({type:EVENT_TYPE_SCAN payload:{"qrcode":"https://login.weixin.qq.com/l/IeJ_ESMXqQ==","status":2}})
go run test.go 0.46s user 0.32s system 27% cpu 2.895 total
TypeScript
function onScan(payload: PUPPET.payloads.EventScan) {
return process.exit(0);
---------------------------------------
time cross-env NODE_OPTIONS="--no-warnings --loader=ts-node/esm" node examples/1.ts
Puppet Version: 0.0.0<1.18.3>
Please wait... I'm trying to login in...
cross-env NODE_OPTIONS="--no-warnings --loader=ts-node/esm" node examples/1.t 0.40s user 0.13s system 54% cpu 0.975 total
因为大部分兄弟的微信是不能登录网页版而选的 XP 协议,所以我想说,XP 协议需要 Hook 微信进程,TypeScript 将需要更多的时间
- Viper 用来读取或者写入配置文件,包括 各种 token
- go func() // 这里我并不理解这个,我以为他是 后台程序
- strings.Replace 切割 @ 符号和机器人的名字,机器人的名字可以在 onlogin 的时候读取
- 在 message 接收到消息的时候,如果匹配到了关键字,其实你可以把它放到后台继续执行的
- 还有就是 xp 消息发送过于频繁怕触发微信的风控
- golang 可以使用 air 热重启,typescript 使用 nodemon
关于文档贡献
如果你喜欢这款开源机器人,且愿意与大家分享你的心得,欢迎投稿 参与投稿,你将获得 长期
padlocal token
,更稳定! 那么,关于文档,由于文章较多,我的解决方案是vscode
+Plug markdownlint
+markdownlint Config
Recommend
-
62
wechatBot 微信每日说,每日自动发送微信消息给你心爱的人 项目介绍 灵感来源 在掘金看到了一篇《用Node + EJS写一个爬虫脚本每天定时女朋友发一封暖心邮件》后, 在评论区偶然看到一位读者说可不可以用微信实现一下。然后最近刚好在做微信机器人的小项目
-
48
文章首发于用Node+puppeteer+wechaty每天定时给女(男)朋友发一张微信爱心提醒图 项目简介 通过微信每日定时给指定的一位好友发送消息,去年就有一个类似的想法,不过一直没去执行,直到上周看见篇文章。 不过他的一些功能我根本不需要,而且定时提醒
-
56
前言 开篇连连问? 你是不是有闲置的微信号? 你想不想有个小秘书定时提醒你将要做的事情? 你是否为忘记一些纪念日而懊恼? 你是否加班到很晚,而忘记了今天和别人有约? 你是不是下班还记得拿快递,到家后才发现忘记了? 你是不是想学习一下如何做一个微信小秘书...
-
10
SpringCloud 2020版本教程2:使用spring cloud gateway作为服务网关 2021/04/03
-
7
article xin_bot:一个尝试使用python-we...
-
5
本文主要有两个目的: (一)使用python-wechaty实现一个英文取名机器人,用户输入中文名(输入格式:英文取名:XXX),即可获取对应的英文名, 扩展wechaty的应用场景。 (二)关于WeChaty网上已经有很多教程了,但是大多数是关于Linux或MacOS系统的,对...
-
4
project 使用wechaty与Flask搭建消息通知...
-
1
article 10分钟使用ChatGPT&Wechaty开发...
-
14
article 使用 wechaty langchain 部署私...
-
6
article wechaty+TypeChat:使用自然语言...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK