|
|
package svc
|
|
|
|
|
|
import (
|
|
|
"github.com/silenceper/wechat/v2"
|
|
|
minicache "github.com/silenceper/wechat/v2/cache"
|
|
|
"github.com/silenceper/wechat/v2/miniprogram"
|
|
|
miniConfig "github.com/silenceper/wechat/v2/miniprogram/config"
|
|
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
|
|
"github.com/zeromicro/go-zero/rest"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/config"
|
...
|
...
|
@@ -44,6 +48,8 @@ type ServiceContext struct { |
|
|
ApiAuthService authlib.ApiAuthService
|
|
|
SmsService smslib.SMSService
|
|
|
|
|
|
MiniProgram *miniprogram.MiniProgram
|
|
|
|
|
|
LoginStatusCheck rest.Middleware
|
|
|
LogRequest rest.Middleware
|
|
|
}
|
...
|
...
|
@@ -57,6 +63,11 @@ func NewServiceContext(c config.Config) *ServiceContext { |
|
|
apiAuth := authlib.ApiAuthService{
|
|
|
Service: gateway.NewService(c.ApiAuth.Name, c.ApiAuth.Host, c.ApiAuth.Timeout),
|
|
|
}
|
|
|
miniProgram := wechat.NewWechat().GetMiniProgram(&miniConfig.Config{
|
|
|
AppID: c.Wechat.AppID,
|
|
|
AppSecret: c.Wechat.AppSecret,
|
|
|
Cache: minicache.NewMemory(),
|
|
|
})
|
|
|
return &ServiceContext{
|
|
|
Config: c,
|
|
|
DB: db,
|
...
|
...
|
@@ -65,6 +76,7 @@ func NewServiceContext(c config.Config) *ServiceContext { |
|
|
SmsService: smslib.SMSService{Service: gateway.NewService("短信服务", "https://sms.fjmaimaimai.com:9897", time.Second*5)},
|
|
|
LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle,
|
|
|
LogRequest: middleware.NewLogRequestMiddleware(c.LogRequest).Handle,
|
|
|
MiniProgram: miniProgram,
|
|
|
|
|
|
ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)),
|
|
|
ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)),
|
...
|
...
|
|