wechat.go 920 B

123456789101112131415161718192021222324252627282930313233
  1. package initialize
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. wechat "github.com/silenceper/wechat/v2"
  5. "github.com/silenceper/wechat/v2/cache"
  6. offConfig "github.com/silenceper/wechat/v2/officialaccount/config"
  7. "go.uber.org/zap"
  8. )
  9. func Wechat() {
  10. redisCfg := global.GVA_CONFIG.Redis
  11. redisOpts := &cache.RedisOpts{
  12. Host: redisCfg.Addr,
  13. Password: redisCfg.Password,
  14. Database: redisCfg.DB,
  15. MaxActive: 0,
  16. MaxIdle: 5,
  17. IdleTimeout: 9000,
  18. }
  19. redisCache := cache.NewRedis(redisOpts)
  20. wc := &wechat.Wechat{}
  21. wc.SetCache(redisCache)
  22. wxCfg := global.GVA_CONFIG.Wxxcx
  23. offCfg := &offConfig.Config{
  24. AppID: wxCfg.Wxid,
  25. AppSecret: wxCfg.Wxkey,
  26. Token: "zk1006",
  27. EncodingAESKey: "wNwYix6c48AsPYlJvttcTRbcBivOvncPhBoUOI9YwSH",
  28. }
  29. global.GVA_LOG.Debug("offCfg=", zap.Any("offCfg", offCfg))
  30. global.GVA_WECHAT = wc.GetOfficialAccount(offCfg)
  31. }