代码拉取完成,页面将自动刷新
package svc
import (
"context"
"gitee.com/i-Things/core/service/syssvr/internal/config"
"gitee.com/i-Things/core/service/syssvr/internal/repo/relationDB"
"gitee.com/i-Things/share/clients/dingClient"
"gitee.com/i-Things/share/clients/wxClient"
"gitee.com/i-Things/share/conf"
"gitee.com/i-Things/share/ctxs"
"gitee.com/i-Things/share/errors"
"sync"
)
type Clients struct {
WxOfficial *wxClient.WxOfficialAccount
MiniProgram *wxClient.MiniProgram
DingMini *dingClient.DingTalk
Config *relationDB.SysTenantApp
}
type ClientsManage struct {
Config config.Config
}
var (
tc = sync.Map{}
)
func NewClients(c config.Config) *ClientsManage {
return &ClientsManage{Config: c}
}
func (c *ClientsManage) ClearClients(ctx context.Context, appCode string) error {
uc := ctxs.GetUserCtx(ctx)
if appCode == "" {
appCode = uc.AppCode
}
var tenantCode = uc.TenantCode
tc.Delete(tenantCode + appCode)
return nil
}
func (c *ClientsManage) GetClients(ctx context.Context, appCode string) (Clients, error) {
uc := ctxs.GetUserCtx(ctx)
if appCode == "" {
appCode = uc.AppCode
}
var tenantCode = uc.TenantCode
val, ok := tc.Load(tenantCode + appCode)
if ok {
return val.(Clients), nil
}
//如果缓存里没有,需要查库
cfg, err := relationDB.NewTenantAppRepo(ctx).FindOneByFilter(ctx, relationDB.TenantAppFilter{TenantCode: tenantCode, AppCodes: []string{appCode}})
if err != nil {
if !errors.Cmp(err, errors.NotFind) {
return Clients{}, err
}
}
var cli Clients
cli.Config = cfg
if cfg.DingMini != nil && cfg.DingMini.AppSecret != "" {
cli.DingMini, err = dingClient.NewDingTalkClient(&conf.ThirdConf{
AppID: cfg.DingMini.AppID,
AppKey: cfg.DingMini.AppKey,
AppSecret: cfg.DingMini.AppSecret,
})
if err != nil {
return Clients{}, err
}
}
if cfg.WxMini != nil && cfg.WxMini.AppSecret != "" {
cli.MiniProgram, err = wxClient.NewWxMiniProgram(ctx, &conf.ThirdConf{
AppID: cfg.WxMini.AppID,
AppKey: cfg.WxMini.AppKey,
AppSecret: cfg.WxMini.AppSecret,
}, c.Config.CacheRedis)
if err != nil {
return Clients{}, err
}
}
if cfg.WxOpen != nil && cfg.WxOpen.AppSecret != "" {
cli.WxOfficial, err = wxClient.NewWxOfficialAccount(ctx, &conf.ThirdConf{
AppID: cfg.WxOpen.AppID,
AppKey: cfg.WxOpen.AppKey,
AppSecret: cfg.WxOpen.AppSecret,
}, c.Config.CacheRedis)
if err != nil {
return Clients{}, err
}
}
tc.Store(tenantCode, cli)
return cli, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。