feat: service-lark
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-01-12 01:44:10 +08:00
parent c048909a9d
commit d247aded23
5 changed files with 126 additions and 16 deletions
+20
View File
@@ -0,0 +1,20 @@
package lark
import (
"context"
"github.com/larksuite/oapi-sdk-go/core"
im "github.com/larksuite/oapi-sdk-go/service/im/v1"
)
func (l Lark) SendMessage(code string) error {
coreCtx := core.WrapContext(context.Background())
reqCall := l.imService.Messages.Create(coreCtx, &im.MessageCreateReqBody{
ReceiveId: "ou_a11d2bcc7d852afbcaf37e5b3ad01f7e",
Content: `{"text":"<at user_id="ou_a11d2bcc7d852afbcaf37e5b3ad01f7e">Tom</at> test content"}`,
MsgType: "text",
})
reqCall.SetReceiveIdType("user_id")
_, err := reqCall.Do()
return err
}
+7 -11
View File
@@ -1,32 +1,28 @@
package lark
import (
"context"
cfg "git.icechen.cn/monorepo/backend/app/zeus/service/lark/internal/config"
"github.com/larksuite/oapi-sdk-go/core"
"github.com/larksuite/oapi-sdk-go/core/config"
authen "github.com/larksuite/oapi-sdk-go/service/authen/v1"
im "github.com/larksuite/oapi-sdk-go/service/im/v1"
)
type Lark struct {
conf *config.Config
conf *config.Config
userService *authen.Service
imService *im.Service
}
var lark Lark
func Client() Lark {
if lark.conf == nil {
if lark.conf == nil || lark.userService == nil {
appSettings := core.NewInternalAppSettings(
core.SetAppCredentials(cfg.Config.LarkAppID, cfg.Config.LarkAppSecret))
lark.conf = core.NewConfig(core.DomainFeiShu, appSettings, core.SetLoggerLevel(core.LoggerLevelError))
lark.userService = authen.NewService(lark.conf)
lark.imService = im.NewService(lark.conf)
}
return lark
}
func (l Lark) Auth(code string) (*authen.UserAccessTokenInfo, error) {
s := authen.NewService(l.conf)
return s.Authens.AccessToken(core.WrapContext(context.Background()), &authen.AuthenAccessTokenReqBody{
GrantType: "",
Code: code,
}).Do()
}
@@ -0,0 +1,14 @@
package lark
import (
"context"
"github.com/larksuite/oapi-sdk-go/core"
authen "github.com/larksuite/oapi-sdk-go/service/authen/v1"
)
func (l Lark) Auth(code string) (*authen.UserAccessTokenInfo, error) {
return l.userService.Authens.AccessToken(core.WrapContext(context.Background()), &authen.AuthenAccessTokenReqBody{
GrantType: "",
Code: code,
}).Do()
}