| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 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/message"
- "dashoo.cn/opms_libary/plugin/dingtalk/workflow"
- "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{
- //微信公众平台,需要填写的信息
- AppKey: "dinguytykawticadfoht", //g.Config().GetString("dingtalk.app-key"), //"your app id",
- AppSecret: "zPlj4ZpITsUbeq2C0GrwJ78-e8knH_kIeyvznaNQacqtrSb9zbeZcOajgBKdolky", //g.Config().GetString("dingtalk.app-secret"), //"your app secret",
- AESKey: "oUjmeWea8Ow1jsdK4UHoDthy6EMQKq3RGbM2rEeTgnm",
- Token: "WaasHsYk8V3wqwN5xRGsCmiiRDB",
- }
- 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()
- }
- //GetContact 通讯录
- func (c *ClientImpl) GetContact() *contact.Contact {
- return contact.NewContact(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)
- }
- // GetDingTalkHandler 消息管理
- func (c *ClientImpl) GetDingTalkHandler(msg *message.SubsMessage) *bridge.DingTalkHandler {
- c.Context.SubsMessage = msg
- return bridge.NewDingTalkHandler(c.Context)
- }
|