Files
ai-agent/internal/wxwork/wxwork.go
T
mlogclub 101577f163 Refactor internal services to use agent-desk package structure
- Updated import paths in multiple service files to reflect the new agent-desk module.
- Added a new configuration file for agent-desk in the Docker setup.
2026-05-31 18:43:48 +08:00

71 lines
2.1 KiB
Go

package wxwork
import (
"agent-desk/internal/pkg/config"
"strings"
"github.com/silenceper/wechat/v2/cache"
"github.com/silenceper/wechat/v2/work"
"github.com/silenceper/wechat/v2/work/addresslist"
wxconfig "github.com/silenceper/wechat/v2/work/config"
"github.com/silenceper/wechat/v2/work/oauth"
)
var (
w *work.Work
wxCfg config.WxWorkConfig
)
type LoginUser struct {
CorpID string `json:"corpId"`
UserID string `json:"userId"`
OpenID string `json:"openId,omitempty"`
ExternalUserID string `json:"externalUserId,omitempty"`
UserTicket string `json:"userTicket,omitempty"`
Name string `json:"name,omitempty"`
Avatar string `json:"avatar,omitempty"`
Mobile string `json:"mobile,omitempty"`
Email string `json:"email,omitempty"`
BizMail string `json:"bizMail,omitempty"`
UserInfo *oauth.GetUserInfoResponse `json:"userInfo,omitempty"`
UserDetail *oauth.GetUserDetailResponse `json:"userDetail,omitempty"`
UserProfile *addresslist.UserGetResponse `json:"userProfile,omitempty"`
}
func Init() {
w = nil
wxCfg = config.WxWorkConfig{}
cfg := config.Current()
if !cfg.WxWork.Enabled {
return
}
wxCfg = cfg.WxWork
if strings.TrimSpace(wxCfg.CorpID) == "" || strings.TrimSpace(wxCfg.CorpSecret) == "" {
return
}
w = work.NewWork(&wxconfig.Config{
CorpID: wxCfg.CorpID,
CorpSecret: wxCfg.CorpSecret,
AgentID: wxCfg.AgentID,
RasPrivateKey: wxCfg.RSAPrivateKey,
Token: wxCfg.Token,
EncodingAESKey: wxCfg.EncodingAESKey,
Cache: cache.NewMemory(),
})
}
func Enabled() bool {
return w != nil && wxCfg.Enabled
}
func StateSecret() string {
if strings.TrimSpace(wxCfg.StateSecret) != "" {
return strings.TrimSpace(wxCfg.StateSecret)
}
return strings.TrimSpace(wxCfg.CorpSecret)
}
func GetWorkCli() *work.Work {
return w
}