You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

event_handle.go 1.5 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package wechat
  2. import (
  3. "code.gitea.io/gitea/modules/redis/redis_client"
  4. "code.gitea.io/gitea/modules/redis/redis_key"
  5. "encoding/json"
  6. "strings"
  7. "time"
  8. )
  9. const BIND_REPLY = "启智账号认证微信成功"
  10. //<xml>
  11. // <ToUserName><![CDATA[toUser]]></ToUserName>
  12. // <FromUserName><![CDATA[FromUser]]></FromUserName>
  13. // <CreateTime>123456789</CreateTime>
  14. // <MsgType><![CDATA[event]]></MsgType>
  15. // <Event><![CDATA[SCAN]]></Event>
  16. // <EventKey><![CDATA[SCENE_VALUE]]></EventKey>
  17. // <Ticket><![CDATA[TICKET]]></Ticket>
  18. //</xml>
  19. type WechatEvent struct {
  20. ToUserName string
  21. FromUserName string
  22. CreateTime int64
  23. MsgType string
  24. Event string
  25. EventKey string
  26. Ticket string
  27. }
  28. type Xml struct {
  29. ToUserName string
  30. FromUserName string
  31. CreateTime int64
  32. MsgType string
  33. Content string
  34. }
  35. func HandleSubscribeEvent(we WechatEvent) string {
  36. eventKey := we.EventKey
  37. if eventKey == "" {
  38. return ""
  39. }
  40. sceneStr := strings.TrimPrefix(eventKey, "qrscene_")
  41. key := redis_key.WechatBindingUserIdKey(sceneStr)
  42. val, _ := redis_client.Get(key)
  43. if val == "" {
  44. return ""
  45. }
  46. qrCache := new(QRCode4BindCache)
  47. json.Unmarshal([]byte(val), qrCache)
  48. //todo 已绑定微信号的如何处理?
  49. //更新微信openId和流水
  50. BindWechat(qrCache.UserId, we.FromUserName)
  51. qrCache.Status = BIND_STATUS_BOUND
  52. jsonStr, _ := json.Marshal(qrCache)
  53. redis_client.Setex(redis_key.WechatBindingUserIdKey(sceneStr), string(jsonStr), 60*time.Second)
  54. return BIND_REPLY
  55. }