| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- package dingtalk
- import (
- "dashoo.cn/opms_libary/plugin/dingtalk/bridge"
- "dashoo.cn/opms_libary/plugin/dingtalk/calendar"
- "dashoo.cn/opms_libary/plugin/dingtalk/contact"
- "dashoo.cn/opms_libary/plugin/dingtalk/context"
- "dashoo.cn/opms_libary/plugin/dingtalk/jsapi"
- "dashoo.cn/opms_libary/plugin/dingtalk/message"
- "dashoo.cn/opms_libary/plugin/dingtalk/message/corpconversation"
- "dashoo.cn/opms_libary/plugin/dingtalk/storage"
- "dashoo.cn/opms_libary/plugin/dingtalk/workflow"
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/os/gcache"
- "sync"
- )
- var Client *ClientImpl
- var memCache *gcache.Cache
- // ClientImpl struct
- type ClientImpl struct {
- Context *context.Context
- }
- func init() {
- Client = NewClient()
- }
- func NewClient() *ClientImpl {
- var config = context.Config{
- CorpId: g.Config().GetString("dingtalk.corp-id"), //
- AgentId: g.Config().GetString("dingtalk.agent-id"), //
- AppKey: g.Config().GetString("dingtalk.app-key"), //
- AppSecret: g.Config().GetString("dingtalk.app-secret"), //
- AESKey: g.Config().GetString("dingtalk.aes-key"), //
- Token: g.Config().GetString("dingtalk.token"), //
- }
- return newClient(config)
- }
- func newClient(cfg context.Config) *ClientImpl {
- context := new(context.Context)
- initContext(&cfg, context)
- return &ClientImpl{context}
- }
- func initContext(cfg *context.Config, context *context.Context) {
- if cfg.Cache == nil {
- if memCache == nil {
- memCache = gcache.New()
- }
- cfg.Cache = memCache
- }
- context.Config = cfg
- context.SetAccessTokenLock(new(sync.RWMutex))
- }
- // GetAccessToken 获取access_token
- func (c *ClientImpl) GetAccessToken() (string, error) {
- return c.Context.GetAccessToken()
- }
- // GetJsapi 获取Jsapi
- func (c *ClientImpl) GetJsapi() *jsapi.Jsapi {
- return jsapi.NewJsapi(c.Context)
- }
- // GetContact 通讯录
- func (c *ClientImpl) GetContact() *contact.Contact {
- return contact.NewContact(c.Context)
- }
- // GetContact 通讯录
- func (c *ClientImpl) GetCorpConversation() *corpconversation.CorpConversation {
- return corpconversation.NewCorpConversation(c.Context)
- }
- // GetWorkflow OA审批
- func (c *ClientImpl) GetWorkflow() *workflow.Workflow {
- return workflow.NewWorkflow(c.Context)
- }
- // GetCalendar 日程
- func (c *ClientImpl) GetCalendar() *calendar.Calendar {
- return calendar.NewCalendar(c.Context)
- }
- // GetStorage 获取Jsapi
- func (c *ClientImpl) GetStorage() *storage.Storage {
- return storage.NewStorage(c.Context)
- }
- // GetDingTalkHandler 消息管理
- func (c *ClientImpl) GetDingTalkHandler(msg *message.SubsMessage) *bridge.DingTalkHandler {
- c.Context.SubsMessage = msg
- return bridge.NewDingTalkHandler(c.Context)
- }
|