dingtalk

package module
v0.0.0-...-a7874d3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2022 License: Apache-2.0 Imports: 23 Imported by: 1

README

Dingtalk

GO SDK for DingTalk

Example

package main

import (
  "github.com/gunsluo/godingtalk"
)

func main() {
	config := dingtalk.ISVConfig{
		CorpId: corpId,
		//CorpSecret: suiteSecret,
		SuiteKey:    suiteKey,
		SuiteSecret: suiteSecret,
	}
	client = dingtalk.NewISVClient(config)
	client.RefreshAndGetSuiteAccessToken()
}

Documentation

Index

Constants

View Source
const (
	SyncActionOrgMicroAppRestore     = "org_micro_app_restore"
	SyncActionOrgMicroAppStop        = "org_micro_app_stop"
	SyncActionOrgMicroAppRemove      = "org_micro_app_remove"
	SyncActionOrgMicroAppScopeUpdate = "org_micro_app_scope_update"
	SyncActionOrgUpdate              = "org_update"
	SyncActionOrgRemove              = "org_remove"
)
View Source
const (
	KeySuiteAccessToken = "suite_access_token"
	KeySuiteTicket      = "suite_ticket"
)
View Source
const (
	OAPIURL   = "https://oapi.dingtalk.com/"
	TOPAPIURL = "https://oapi.dingtalk.com/topapi/"
)
View Source
const (
	MessageTypeText       = "text"
	MessageTypeActionCard = "action_card"
	MessageTypeImage      = "image"
	MessageTypeVoice      = "voice"
	MessageTypeFile       = "file"
	MessageTypeLink       = "link"
	MessageTypeOA         = "oa"
	MessageTypeMarkdown   = "markdown"
)
View Source
const (
	CheckCreateSuiteURLEventType = "check_create_suite_url"
	CheckUpdateSuiteUrlEventType = "check_update_suite_url"
	CheckUrlEventType            = "check_url"
	SyncHTTPPushHighEventType    = "SYNC_HTTP_PUSH_HIGH"
	SyncHTTPPushMediumEventType  = "SYNC_HTTP_PUSH_MEDIUM"
)

Variables

View Source
var (
	ErrAlreadyExpired = errors.New("Data already expired")
)

Functions

This section is empty.

Types

type ActivateSuiteResponse

type ActivateSuiteResponse struct {
	OpenAPIResponse
}

type Biz16Data

type Biz16Data struct {
	SyncAction      string `json:"syncAction"`
	Errcode         int    `json:"errcode"`
	Errmsg          string `json:"errmsg"`
	Corpid          string `json:"corpid"`
	CorpName        string `json:"corp_name"`
	AuthLevel       int    `json:"auth_level"`
	Industry        string `json:"industry"`
	IsAuthenticated bool   `json:"is_authenticated"`
	CorpLogoUrl     string `json:"corp_logo_url"`
}

type Biz2Data

type Biz2Data struct {
	SyncAction  string `json:"syncAction"`
	SuiteTicket string `json:"suiteTicket"`
	SyncSeq     string `json:"syncSeq"`
}

type Biz4Data

type Biz4Data struct {
	AuthUserInfo  BizAuthUserInfo `json:"auth_user_info"`
	AuthCorpInfo  BizAuthCorpInfo `json:"auth_corp_info"`
	PermanentCode string          `json:"permanent_code"`
	SyncAction    string          `json:"syncAction"`
	SyncSeq       string          `json:"syncSeq"`
	AuthInfo      BizAuthInfo     `json:"auth_info"`
	AuthScope     BizAuthScope    `json:"auth_scope"`
}

type Biz7Data

type Biz7Data struct {
	SyncAction string `json:"syncAction"`
	AgentId    int    `json:"agentId"`
}

type BizAgent

type BizAgent struct {
	AdminList []string `json:"admin_list"`
	AgentName string   `json:"agent_name"`
	AgentId   int      `json:"agentid"`
	AppId     int      `json:"appid"`
	LogoUrl   string   `json:"logo_url"`
}

type BizAuthCorpInfo

type BizAuthCorpInfo struct {
	CorpLogoURL     string `json:"corp_logo_url"`
	CorpType        int    `json:"corp_type"`
	CorpName        string `json:"corp_name"`
	FullCorpName    string `json:"full_corp_name"`
	CorpID          string `json:"corpid"`
	Industry        string `json:"industry"`
	InviteCode      string `json:"invite_code"`
	LicenseCode     string `json:"license_code"`
	AuthChannel     string `json:"auth_channel"`
	AuthChannelType string `json:"auth_channel_type"`
	IsAuthenticated bool   `json:"is_authenticated"`
	AuthLevel       int    `json:"auth_level"`
	InviteURL       string `json:"invite_url"`
}

type BizAuthInfo

type BizAuthInfo struct {
	Agents []BizAgent `json:"agent"`
}

type BizAuthOrgScopes

type BizAuthOrgScopes struct {
	AuthedUser []string `json:"authed_user"`
	AuthedDept []int    `json:"authed_dept"`
}

type BizAuthScope

type BizAuthScope struct {
	ErrCode         int              `json:""`
	ErrMsg          string           `json:""`
	ConditionFields []string         `json:"condition_field"`
	AuthUserFields  []string         `json:"auth_user_field"`
	AuthOrgScopes   BizAuthOrgScopes `json:"auth_org_scopes"`
}

type BizAuthUserInfo

type BizAuthUserInfo struct {
	UserId string `json:"userId"`
}

type BizItem

type BizItem struct {
	BizType     int    `json:"biz_type"`
	GmtCreate   int    `json:"gmt_create"`
	OpenCursor  int    `json:"open_cursor"`
	SubscribeId string `json:"subscribe_id"`
	Id          int    `json:"id"`
	GmtModified int    `json:"gmt_modified"`
	BizId       string `json:"biz_id"`
	CorpId      string `json:"corp_id"`
	Status      int    `json:"status"`

	BizData interface{} `json:"biz_data"`
}

func (*BizItem) UnmarshalJSON

func (b *BizItem) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals a biz item.

type Cache

type Cache interface {
	Set(ctx context.Context, data *KVExpirable) error
	Get(ctx context.Context, key string) (*KVExpirable, error)
}

type ClientType

type ClientType int32
const (
	CORP   ClientType = 0
	ISV    ClientType = 1
	PERSON ClientType = 2
)

type CorpConfig

type CorpConfig struct {
	CorpId     string
	CorpSecret string
	ApiToken   string
	AgentId    string
	AppKey     string
	AppSecret  string
}

type DeptLeader

type DeptLeader struct {
	DeptId int  `json:"dept_id"`
	Leader bool `json:"leader"`
}

type DeptOrder

type DeptOrder struct {
	DeptId int `json:"dept_id"`
	Order  int `json:"order"`
}

type DingTalkClient

type DingTalkClient struct {
	// contains filtered or unexported fields
}

func NewCorpClient

func NewCorpClient(cfg CorpConfig, opts ...Option) *DingTalkClient

func NewISVClient

func NewISVClient(cfg ISVConfig, opts ...Option) *DingTalkClient

func NewPersonClient

func NewPersonClient(cfg PersonConfig, opts ...Option) *DingTalkClient

func (*DingTalkClient) Decrypt

func (dtc *DingTalkClient) Decrypt(signature, timestamp, nonce, secretMsg string) (string, error)

func (*DingTalkClient) DecryptAndUnmarshalPushNotification

func (dtc *DingTalkClient) DecryptAndUnmarshalPushNotification(signature, timestamp, nonce, secretMsg string) (*PushNotification, error)

func (*DingTalkClient) Encrypt

func (dtc *DingTalkClient) Encrypt(msg, timestamp, nonce string) (string, string, error)

func (*DingTalkClient) GetAccessToken

func (dtc *DingTalkClient) GetAccessToken(ctx context.Context) (GetAccessTokenResponse, error)

获取微应用后台免登的access_token

func (*DingTalkClient) GetAndRefreshSuiteAccessToken

func (dtc *DingTalkClient) GetAndRefreshSuiteAccessToken(ctx context.Context) (string, error)

刷新并获取第三方企业应用的suite_access_token

func (*DingTalkClient) GetCorpAccessToken

func (dtc *DingTalkClient) GetCorpAccessToken(ctx context.Context) (GetCorpAccessTokenResponse, error)

获取企业内部应用的access_token

func (*DingTalkClient) GetCorpUserByUnionId

func (dtc *DingTalkClient) GetCorpUserByUnionId(ctx context.Context, authCorpId, unionId string) (GetCorpUserByUnionIdResponse, error)

根据unionid获取组织用户userid

func (*DingTalkClient) GetCorpUserDetailByUserId

func (dtc *DingTalkClient) GetCorpUserDetailByUserId(ctx context.Context, authCorpId, userId string, languages ...string) (GetCorpUserDetailByUserIdResponse, error)

根据userId获取组织用户详情

func (*DingTalkClient) GetCorpUserInfoByCode

func (dtc *DingTalkClient) GetCorpUserInfoByCode(ctx context.Context, authCorpId, code string) (GetCorpUserInfoByCodeResponse, error)

通过免登码获取用户信息

func (*DingTalkClient) GetSuiteAccessToken

func (dtc *DingTalkClient) GetSuiteAccessToken(ctx context.Context) (SuiteAccessTokenResponse, error)

获取第三方企业应用的suite_access_token

func (*DingTalkClient) GetSuiteTicket

func (dtc *DingTalkClient) GetSuiteTicket(ctx context.Context) string

get suite ticket

func (*DingTalkClient) IsvActivateSuite

func (dtc *DingTalkClient) IsvActivateSuite(ctx context.Context, authCorpId string, permanentCode string) (ActivateSuiteResponse, error)

激活套件

func (*DingTalkClient) IsvGetAndRefreshCorpAccessToken

func (dtc *DingTalkClient) IsvGetAndRefreshCorpAccessToken(ctx context.Context, authCorpId string) (string, error)

刷新并获取企业授权的凭证

func (*DingTalkClient) IsvGetCorpAccessToken

func (dtc *DingTalkClient) IsvGetCorpAccessToken(ctx context.Context, authCorpId string) (GetCorpAccessTokenResponse, error)

获取企业授权的凭证

func (*DingTalkClient) IsvListUnactivateSuites

func (dtc *DingTalkClient) IsvListUnactivateSuites(ctx context.Context) (ListUnactivateSuitesResponse, error)

获取应用未激活的企业列表

func (*DingTalkClient) MediaDownloadFile

func (dtc *DingTalkClient) MediaDownloadFile(ctx context.Context, mediaID string, write io.Writer) error

获取媒体文件

func (*DingTalkClient) MediaUpload

func (dtc *DingTalkClient) MediaUpload(ctx context.Context, mediaType string, fileName string, reader io.Reader) (MediaUploadResponse, error)

上传媒体文件

func (*DingTalkClient) SNSGetUserInfoByCode

func (dtc *DingTalkClient) SNSGetUserInfoByCode(ctx context.Context, tmpAuthCode string) (SNSGetUserInfoByCodeResponse, error)

func (*DingTalkClient) SendMessageByTemplate

func (dtc *DingTalkClient) SendMessageByTemplate(ctx context.Context, authCorpId string, req SendMessageByTemplateRequest) (SendMessageByTemplateResponse, error)

使用模板发送工作通知消息

func (*DingTalkClient) SetSuiteTicket

func (dtc *DingTalkClient) SetSuiteTicket(ctx context.Context, suiteTicket string) error

set suite ticket

type FileCache

type FileCache struct {
	Path string
	// contains filtered or unexported fields
}

func NewFileCache

func NewFileCache(path string) *FileCache

func (*FileCache) Get

func (f *FileCache) Get(ctx context.Context, key string) (*KVExpirable, error)

func (*FileCache) Set

func (f *FileCache) Set(ctx context.Context, data *KVExpirable) error

type GetAccessTokenResponse

type GetAccessTokenResponse struct {
	OpenAPIResponse
	AccessToken string `json:"access_token"`
}

type GetCorpAccessTokenResponse

type GetCorpAccessTokenResponse struct {
	OpenAPIResponse
	AccessToken string `json:"access_token"`
	ExpiresIn   int    `json:"expires_in"`
}

type GetCorpUserByUnionIdResponse

type GetCorpUserByUnionIdResponse struct {
	OpenAPIResponse
	RequestId string                     `json:"request_id"`
	UserInfo  GetCorpUserByUnionIdResult `json:"result"`
}

type GetCorpUserByUnionIdResult

type GetCorpUserByUnionIdResult struct {
	ContactType int    `json:"contact_type"`
	UserId      string `json:"userid"`
}

type GetCorpUserDetailByUserIdResponse

type GetCorpUserDetailByUserIdResponse struct {
	OpenAPIResponse
	RequestId string                          `json:"request_id"`
	UserInfo  GetCorpUserDetailByUserIdResult `json:"result"`
}

type GetCorpUserDetailByUserIdResult

type GetCorpUserDetailByUserIdResult struct {
	UserId               string       `json:"userid"`
	Unionid              string       `json:"unionid"`
	Name                 string       `json:"name"`
	Avatar               string       `json:"avatar"`
	StateCode            string       `json:"state_code"`
	ManagerUserid        string       `json:"manager_userid"`
	Mobile               string       `json:"mobile"`
	HideMobile           bool         `json:"hide_mobile"`
	Telephone            string       `json:"telephone"`
	Job_number           string       `json:"job_number"`
	Title                string       `json:"title"`
	Email                string       `json:"email"`
	WorkPlace            string       `json:"work_place"`
	Remark               string       `json:"remark"`
	LoginId              string       `json:"login_id"`
	ExclusiveAccountType string       `json:"exclusive_account_type"`
	ExclusiveAccount     bool         `json:"exclusive_account"`
	Extension            string       `json:"extension"`
	HiredDate            int          `json:"hired_date"`
	Active               bool         `json:"active"`
	RealAuthed           bool         `json:"real_authed"`
	OrgEmail             string       `json:"org_email"`
	OrgEmailType         string       `json:"org_email_type"`
	Nickname             string       `json:"nickname"`
	Senior               bool         `json:"senior"`
	Admin                bool         `json:"admin"`
	Boss                 bool         `json:"boss"`
	CorpId               string       `json:"corp_id"`
	DeptIdList           []int        `json:"dept_id_list"`
	DeptOrderList        []DeptOrder  `json:"dept_order_list"`
	LeaderInDept         []DeptLeader `json:"leader_in_dept"`
	RoleList             []UserRole   `json:"role_list"`
	UnionEmpExt          UnionEmpExt  `json:"union_emp_ext"`
}

type GetCorpUserInfoByCodeResponse

type GetCorpUserInfoByCodeResponse struct {
	OpenAPIResponse
	RequestId string                      `json:"request_id"`
	UserInfo  GetCorpUserInfoByCodeResult `json:"result"`
}

type GetCorpUserInfoByCodeResult

type GetCorpUserInfoByCodeResult struct {
	UserId            string `json:"userid"`
	DeviceId          string `json:"device_id"`
	Sys               bool   `json:"sys"`
	SysLevel          int    `json:"sys_level"`
	AssociatedUnionid string `json:"associated_unionid"`
	Unionid           string `json:"unionid"`
	Name              string `json:"name"`
}

type ISVConfig

type ISVConfig struct {
	CorpId      string
	CorpSecret  string
	ApiToken    string
	MiniAppId   string
	AppId       string
	SuiteId     string
	SuiteKey    string
	SuiteSecret string
	AESKey      string
	Token       string
}

type KVExpirable

type KVExpirable struct {
	Key       string `json:"key"`
	Value     string `json:"value"`
	ExpiresIn int    `json:"expires_in"`
	Created   int64  `json:"created"`
}

func NewKVExpirable

func NewKVExpirable(key, value string, expiresIn int) *KVExpirable

func (*KVExpirable) IsExpired

func (e *KVExpirable) IsExpired() bool

type ListUnactivateSuitesResponse

type ListUnactivateSuitesResponse struct {
	OpenAPIResponse
	AppId    int      `json:""`
	CorpList []string `json:"corp_list"`
	HasMore  bool     `json:"has_more"`
}

type MediaDownloadFileResponse

type MediaDownloadFileResponse struct {
	OpenAPIResponse
	MediaID string
	Writer  io.Writer
}

type MediaUploadResponse

type MediaUploadResponse struct {
	OpenAPIResponse
	Type      string
	MediaID   string `json:"media_id"`
	CreatedAt int64  `json:"created_at"`
}

type OpenAPIResponse

type OpenAPIResponse struct {
	ErrCode int    `json:"errcode"`
	ErrMsg  string `json:"errmsg"`
}

type Option

type Option func(*options)

func WithCache

func WithCache(cache Cache) Option

func WithPersist

func WithPersist(persist Persist) Option

type Persist

type Persist = Cache

type PersonConfig

type PersonConfig struct {
	CorpId     string
	CorpSecret string
	ApiToken   string
	MiniAppId  string
	AppId      string
	AppSecret  string
}

type PushCryptoSuit

type PushCryptoSuit struct {
	// contains filtered or unexported fields
}

func NewPushCryptoSuit

func NewPushCryptoSuit(token, aesKey, suiteKey string) (*PushCryptoSuit, error)

func (*PushCryptoSuit) Decrypt

func (s *PushCryptoSuit) Decrypt(signature, timestamp, nonce, secretMsg string) (string, error)

func (*PushCryptoSuit) Encrypt

func (s *PushCryptoSuit) Encrypt(msg, timestamp, nonce string) (string, string, error)

type PushNotification

type PushNotification struct {
	Random       string    `json:"Random"`
	EventType    string    `json:"EventType"`
	TestSuiteKey string    `json:"TestSuiteKey"`
	BizItems     []BizItem `json:"bizData"`
}

type SNSGetUserInfoByCode

type SNSGetUserInfoByCode struct {
	Nick          string `json:"nick"`
	OpenId        string `json:"openid"`
	UnionId       string `json:"unionid"`
	AuthHighLevel bool   `json:"main_org_auth_high_level"`
}

type SNSGetUserInfoByCodeResponse

type SNSGetUserInfoByCodeResponse struct {
	OpenAPIResponse
	UserInfo SNSGetUserInfoByCode `json:"user_info"`
}

type SendMessageByTemplateRequest

type SendMessageByTemplateRequest struct {
	AgentId    int
	TemplateId string
	UserIds    []string
	DeptIds    []string
	Data       string
}

type SendMessageByTemplateResponse

type SendMessageByTemplateResponse struct {
	OpenAPIResponse
	TaskId    int    `json:"task_id"`
	RequestId string `json:"request_id"`
}

type SuiteAccessTokenResponse

type SuiteAccessTokenResponse struct {
	OpenAPIResponse
	SuiteAccessToken string `json:"suite_access_token"`
	ExpiresIn        int    `json:"expires_in"`
}

type UnionEmpExt

type UnionEmpExt struct {
	UserId          string        `json:"userid"`
	UnionEmpMapList []UnionEmpMap `json:"union_emp_map_list"`
	CorpId          string        `json:"corp_id"`
}

type UnionEmpMap

type UnionEmpMap struct {
	UserId string `json:"userid"`
	CorpId string `json:"corp_id"`
}

type Unmarshallable

type Unmarshallable interface {
	// contains filtered or unexported methods
}

type UserRole

type UserRole struct {
	Id        int    `json:"id"`
	Name      string `json:"name"`
	GroupName string `json:"group_name"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL