package wechat import ( "code.gitea.io/gitea/modules/redis/redis_client" "code.gitea.io/gitea/modules/redis/redis_key" "encoding/json" "encoding/xml" "strings" "time" ) // // // // 123456789 // // // // // type WechatEvent struct { ToUserName string FromUserName string CreateTime int64 MsgType string Event string EventKey string Ticket string } type EventReply struct { XMLName xml.Name `xml:"xml"` 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) if qrCache.Status == BIND_STATUS_UNBIND { err := BindWechat(qrCache.UserId, we.FromUserName) if err != nil { if err, ok := err.(WechatBindError); ok { return err.Reply } return BIND_REPLY_FAILED_DEFAULT } qrCache.Status = BIND_STATUS_BOUND jsonStr, _ := json.Marshal(qrCache) redis_client.Setex(redis_key.WechatBindingUserIdKey(sceneStr), string(jsonStr), 60*time.Second) } return BIND_REPLY_SUCCESS }