package wechat import ( "code.gitea.io/gitea/modules/redis/redis_client" "code.gitea.io/gitea/modules/redis/redis_key" "encoding/json" "strings" "time" ) const BIND_REPLY = "启智账号认证微信成功" // // // // 123456789 // // // // // type WechatEvent struct { ToUserName string FromUserName string CreateTime int64 MsgType string Event string EventKey string Ticket string } type Xml struct { ToUserName string FromUserName string CreateTime int64 MsgType string Content string } func HandleSubscribeEvent(we WechatEvent) string { eventKey := we.EventKey if eventKey == "" { return "" } sceneStr := strings.TrimPrefix(eventKey, "qrscene_") key := redis_key.WechatBindingUserIdKey(sceneStr) val, _ := redis_client.Get(key) if val == "" { return "" } qrCache := new(QRCode4BindCache) json.Unmarshal([]byte(val), qrCache) //todo 已绑定微信号的如何处理? //更新微信openId和流水 BindWechat(qrCache.UserId, we.FromUserName) qrCache.Status = BIND_STATUS_BOUND jsonStr, _ := json.Marshal(qrCache) redis_client.Setex(redis_key.WechatBindingUserIdKey(sceneStr), string(jsonStr), 60*time.Second) return BIND_REPLY }