批量优化功能

This commit is contained in:
2026-09-30 00:57:36 +08:00
parent ca4220f92c
commit e3db229f41
43 changed files with 2959 additions and 207 deletions
+34 -4
View File
@@ -398,14 +398,29 @@ func HandleInbound(cfg *Config, msg *InboundMessage) string {
_, _ = UpsertSubscribe(openid, now)
scene := strings.TrimPrefix(strings.TrimSpace(msg.EventKey), "qrscene_")
if scene != "" {
// 带参二维码:先看是否为扫码登录会话(自动回复确认链接)
if reply, ok := HandleScanLoginEvent(scene, openid); ok {
return reply
}
return handleScanScene(cfg, scene, openid)
}
return "欢迎关注云泽平台!\n如需接收系统提醒、公告推送,请回到系统页面点击「绑定微信」,使用微信扫码获取专属验证码;已扫码但未收到时可发送「验证码」重新获取。"
// 普通关注:已绑定直接给「确认登录」链接,未绑定提示先绑定
return DirectLoginReply(openid)
case "scan":
return handleScanScene(cfg, strings.TrimSpace(msg.EventKey), openid)
scene := strings.TrimSpace(msg.EventKey)
if reply, ok := HandleScanLoginEvent(scene, openid); ok {
return reply
}
return handleScanScene(cfg, scene, openid)
case "unsubscribe":
_ = MarkUnsubscribe(openid, now)
return ""
case "click":
// 自定义菜单点击:键值为登录入口时直接回复确认登录链接
if isLoginMenuKey(msg.EventKey) {
return DirectLoginReply(openid)
}
return ""
}
case "text":
return handleTextIntent(openid, msg.Content)
@@ -414,11 +429,16 @@ func HandleInbound(cfg *Config, msg *InboundMessage) string {
}
// handleTextIntent 处理公众号文本消息:
// - 发送「登录」:已绑定用户获取一次性登录链接(见 login.go);
// - 发送「验证码」等关键词:返回该微信号的验证码(复用未核销会话;没有则在公众号侧
// 新建「待认领」会话),用户回系统页面输入即完成绑定,无需先扫码;
// - 其余文本:给出绑定引导。
func handleTextIntent(openid, content string) string {
if !isBindKeyword(strings.TrimSpace(content)) {
text := strings.TrimSpace(content)
if isLoginKeyword(text) {
return DirectLoginReply(openid)
}
if !isBindKeyword(text) {
return textBindGuide()
}
// 1) 复用该微信号未核销、未过期的会话(扫码会话或此前公众号发起的会话)
@@ -457,7 +477,17 @@ func isBindKeyword(text string) bool {
// textBindGuide 非关键词文本的绑定引导
func textBindGuide() string {
return "如需绑定账号:请在系统页面点击「绑定微信」,然后任选一种方式——① 扫描页面上的二维码;② 直接在本公众号发送「验证码」。\n两种方式都会回复 6 位验证码,回到系统页面输入即可完成绑定。"
return "如需绑定账号:请在系统页面点击「绑定微信」,然后直接在本公众号发送「验证码」," +
"收到 6 位验证码后回到系统页面输入即可完成绑定。\n绑定后在本公众号发送「登录」可获取一次性登录链接。"
}
// BindGuides 系统页面「绑定微信」卡片的操作指引(未认证公众号无带参二维码,仅引导发码取码)
func BindGuides() []string {
return []string{
"① 用微信扫码关注本公众号(或微信搜索公众号名称进入会话)",
"② 在公众号会话中直接发送文字「验证码」",
"③ 公众号回复 6 位验证码,填入本页输入框完成绑定",
}
}
// handleScanScene 扫码(关注/已关注)后的统一处理:写入验证码会话 + 回复验证码