dingtalk

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// https://ding-doc.dingtalk.com/document#/org-dev-guide/server-api-error-codes
	// AuthenticationAbnormal 鉴权异常
	AuthenticationAbnormal = 88
	// InvalidAccessToken 获取access_token时Secret错误,或者access_token无效
	InvalidAccessToken = "40001"
	EmptyAccessToken   = "40000"
	IllegalAccessToken = "40014"
)

Variables

This section is empty.

Functions

func UnmarshalAndParseError

func UnmarshalAndParseError(v Response) requests.Interceptor

Types

type BasicResponse

type BasicResponse struct {
	RequestID    string `json:"request_id,omitempty"`
	*DingtalkErr `json:",inline"`
}

type Client

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

func NewClient

func NewClient(opt Option) *Client

func (*Client) AccessToken

func (ding *Client) AccessToken() string

func (*Client) GetAccessToken

func (ding *Client) GetAccessToken(ctx context.Context) (string, *http.Response, error)

GetAccessToken 获取access_token https://ding-doc.dingtalk.com/document#/org-dev-guide/obtain-access_token

func (*Client) GetDepartmentV2

func (ding *Client) GetDepartmentV2(ctx context.Context, deptID int) (*DepartmentInfoV2, *http.Response, error)

获取部门详情,可以得到部门主管

func (*Client) GetOrganizationUserCount

func (ding *Client) GetOrganizationUserCount(ctx context.Context, onlyActive int) (int, *http.Response, error)

GetOrganizationUserCount 获取组织人员数

func (*Client) GetUserByUnionID

func (ding *Client) GetUserByUnionID(ctx context.Context, req *RequestGetByUnionID) (*UserGetByUnionId, *http.Response, error)

func (*Client) GetUserInfoByMobileV2

func (ding *Client) GetUserInfoByMobileV2(ctx context.Context, mobile string) (string, *http.Response, error)

根据手机号获取userid v2 https://ding-doc.dingtalk.com/document#/org-dev-guide/query-users-by-phone-number

func (*Client) ListParentDeptByUserV2

func (ding *Client) ListParentDeptByUserV2(ctx context.Context, userid string) (*DeptListParent, *http.Response, error)

获取指定用户的所有父部门列表 https://ding-doc.dingtalk.com/document#/org-dev-guide/obtains-the-list-of-all-parent-departments-of-a-user

func (*Client) RetryOnAccessTokenExpired

func (ding *Client) RetryOnAccessTokenExpired(ctx context.Context, retry int, fn func() error) (err error)

func (*Client) SetAccessToken

func (ding *Client) SetAccessToken(token string)

func (*Client) WithAppOption

func (ding *Client) WithAppOption(opt Option) *Client

type CompleteUserInfo

type CompleteUserInfo struct {
	UserID        string       `json:"userid"`
	UnionID       string       `json:"unionid"`
	Name          string       `json:"name"`
	Avatar        string       `json:"avatar"`
	StateCode     string       `json:"state_code"`
	Mobile        string       `json:"mobile"`
	HideMobile    bool         `json:"hide_mobile"`
	Telephone     string       `json:"telephone"`
	JobNumber     string       `json:"job_number"`
	Title         string       `json:"title"`
	Email         string       `json:"email"`
	WorkPlace     string       `json:"work_place"`
	Remark        string       `json:"remark"`
	DeptIdList    []int        `json:"dept_id_list"`
	DeptOrderList []DeptOrder  `json:"dept_order_list"`
	Extension     string       `json:"extension"`
	HiredDate     int          `json:"hired_date"`
	Active        bool         `json:"active"`
	RealAuthed    bool         `json:"real_authed"`
	Senior        bool         `json:"senior"`
	Admin         bool         `json:"admin"`
	Boss          bool         `json:"boss"`
	LeaderInDept  []DeptLeader `json:"leader_in_dept"`
	RoleList      []UserRole   `json:"role_list"`
}

type DepartmentInfo

type DepartmentInfo struct {
	Id                    int    `json:"id"`
	Name                  string `json:"name"`
	Order                 int    `json:"order"`
	ParentId              int    `json:"parentid"`
	SourceIdentifier      string `json:"source_identifier"`
	CreateDeptGroup       bool   `json:"createDeptGroup"`
	AutoAddUser           bool   `json:"autoAddUser"`
	GroupContainSubDept   bool   `json:"groupContainSubDept"`
	OrgDeptOwner          string `json:"orgDeptOwner"`
	DeptGroupChatId       string `json:"deptGroupChatId"`
	DeptManagerUseridList string `json:"deptManagerUseridList"`
	OuterDept             bool   `json:"outerDept"`
	OuterPermitUsers      string `json:"outerPermitUsers"`
	OuterPermitDepts      string `json:"outerPermitDepts"`
	DeptHiding            bool   `json:"deptHiding"`
	DeptPermits           string `json:"deptPermits"`
	UserPermits           string `json:"userPermits"`
}

type DepartmentInfoV2

type DepartmentInfoV2 struct {
	DeptID                int      `json:"dept_id"`
	Name                  string   `json:"name,omitempty"`
	ParentID              int      `json:"parent_id,omitempty"`
	SourceIdentifier      string   `json:"source_identifier,omitempty"`
	CreateDeptGroup       bool     `json:"create_dept_group,omitempty"`
	AutoAddUser           bool     `json:"auto_add_user,omitempty"`
	FromUnionOrg          bool     `json:"from_union_org,omitempty"`
	Tags                  string   `json:"tags,omitempty"`
	Order                 int      `json:"order,omitempty"`
	DeptGroupChatID       string   `json:"dept_group_chat_id,omitempty"`
	GroupContainSubDept   bool     `json:"group_contain_sub_dept,omitempty"`
	OrgDeptOwner          string   `json:"org_dept_owner,omitempty"`
	DeptManagerUseridList []string `json:"dept_manager_userid_list,omitempty"`
	OuterDept             bool     `json:"outer_dept,omitempty"`
	OuterPermitDepts      []int    `json:"outer_permit_depts,omitempty"`
	OuterPermitUsers      []string `json:"outer_permit_users,omitempty"`
	HideDept              bool     `json:"hide_dept,omitempty"`
	UserPermits           []string `json:"user_permits,omitempty"`
	DeptPermits           []int    `json:"dept_permits,omitempty"`
}

type DepartmentLeader

type DepartmentLeader struct {
	DepartmentID int  `json:"dept_id"`
	Leader       bool `json:"leader"`
}

type DepartmentOrder

type DepartmentOrder struct {
	DepartmentID int `json:"dept_id"`
	Order        int `json:"order"`
}

DepartmentOrder 部门排序

type DeptLeader

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

type DeptListParent

type DeptListParent struct {
	ParentDeptList []ParentDeptIds `json:"parent_list"`
}

type DeptOrder

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

type DingTime

type DingTime struct {
	time.Time
}

钉钉的时间格式

func (DingTime) MarshalJSON

func (dt DingTime) MarshalJSON() ([]byte, error)

func (*DingTime) UnmarshalJSON

func (dt *DingTime) UnmarshalJSON(b []byte) error

type DingtalkErr

type DingtalkErr struct {
	ErrorMessage string `json:"errmsg,omitempty"`
	ErrorCode    int    `json:"errcode,omitempty"`
	SubCode      string `json:"sub_code,omitempty"`
	SubMessage   string `json:"sub_msg,omitempty"`
}

DingtalkErr 钉钉错误信息

func (*DingtalkErr) Error

func (de *DingtalkErr) Error() string

Error error的实现

func (*DingtalkErr) GotErr

func (de *DingtalkErr) GotErr() error

GotErr 返回response中的错误

func (*DingtalkErr) IsAccessTokenExpired

func (de *DingtalkErr) IsAccessTokenExpired() bool

IsAccessTokenExpired access_token是否过期

type FormComponentValue

type FormComponentValue struct {
	Name          string `json:"name,omitempty"`
	Value         string `json:"value,omitempty"`
	ExtValue      string `json:"ext_value,omitempty"`
	ID            string `json:"id,omitempty"`
	ComponentType string `json:"component_type,omitempty"`
}

type Lang

type Lang string
const (
	ZH_CN Lang = "zh_CN"
	EN_US Lang = "en_US"
)

type Option

type Option struct {
	AgentID          string
	AppKey           string
	AppSecret        string
	LoginAppID       string
	LoginAppSecret   string
	LoginCallbackURI string
}

Option 应用凭证

func (Option) IsEmpty

func (ao Option) IsEmpty() bool

type ParentDeptIds

type ParentDeptIds struct {
	ParentDeptIdList []int `json:"parent_dept_id_list"`
}

type ProcessApprovers

type ProcessApprovers struct {
	TaskActionType string   `json:"task_action_type,omitempty"`
	UserIDs        []string `json:"user_ids,omitempty"`
}

type ProcessAttachment

type ProcessAttachment struct {
	FileName string `json:"file_name,omitempty"`
	FileSize string `json:"file_size,omitempty"`
	FileID   string `json:"file_id,omitempty"`
	FileType string `json:"file_type,omitempty"`
}

type ProcessInstance

type ProcessInstance struct {
	Title                      string                    `json:"title,omitempty"`
	CreateTime                 DingTime                  `json:"create_time,omitempty"`
	FinishTime                 DingTime                  `json:"finish_time,omitempty"`
	OriginatorUserID           string                    `json:"originator_userid,omitempty"`
	OriginatorDeptID           string                    `json:"originator_dept_id,omitempty"`
	Status                     string                    `json:"status,omitempty"` // RUNNING审批中COMPLETED完成
	ApproverUserIDs            []string                  `json:"approver_userids,omitempty"`
	CCUserIDs                  []string                  `json:"cc_userids,omitempty"`
	Result                     string                    `json:"result,omitempty"` // agree同意refuse拒绝
	BusinessID                 string                    `json:"business_id,omitempty"`
	OperationRecords           []*ProcessOperationRecord `json:"operation_records,omitempty"`
	Tasks                      []*ProcessTask            `json:"tasks,omitempty"`
	OriginatorDeptName         string                    `json:"originator_dept_name,omitempty"`
	BizAction                  string                    `json:"biz_action,omitempty"`
	AttachedProcessInstanceIDs []string                  `json:"attached_process_instance_ids,omitempty"`
	FormComponentValues        []*FormComponentValue     `json:"form_component_values,omitempty"`
	MainProcessInstanceID      string                    `json:"main_process_instance_id,omitempty"`
}

审批实例详情

type ProcessOperationRecord

type ProcessOperationRecord struct {
	UserID          string               `json:"user_id,omitempty"`
	Date            DingTime             `json:"date,omitempty"`
	OperationType   string               `json:"operation_type,omitempty"`
	OperationResult string               `json:"operation_result,omitempty"`
	Remark          string               `json:"remark,omitempty"`
	Attachments     []*ProcessAttachment `json:"attachments,omitempty"`
}

type ProcessTask

type ProcessTask struct {
	UserID     string   `json:"userid,omitempty"`
	TaskStatus string   `json:"task_status,omitempty"`
	TaskResult string   `json:"task_result,omitempty"`
	CreateTime DingTime `json:"create_time,omitempty"`
	FinishTime DingTime `json:"finish_time,omitempty"`
	TaskID     string   `json:"taskid,omitempty"`
	URL        string   `json:"url,omitempty"`
}

type RequestCreateProcessInstance

type RequestCreateProcessInstance struct {
	FormComponentValues []*FormComponentValue `json:"form_component_values,omitempty"`
	AgentID             string                `json:"agent_id,omitempty"`
	DeptID              string                `json:"dept_id,omitempty"`
	ProcessCode         string                `json:"process_code,omitempty"`
	OriginatorUserID    string                `json:"originator_user_id,omitempty"` // 审批发起人ID
	ApproversV2         []ProcessApprovers    `json:"approvers_v2,omitempty"`
	CCList              string                `json:"cc_list,omitempty"`     // 抄送人userid列表
	CCPosition          string                `json:"cc_position,omitempty"` // 抄送时间,分为(START, FINISH, START_FINISH)
}

审批请求参数

type RequestDepartmentInfo

type RequestDepartmentInfo struct {
	DeptId   string `json:"id"`
	Language Lang   `json:"lang,omitempty"`
}

type RequestDepartmentInfoV2

type RequestDepartmentInfoV2 struct {
	DeptID   int    `json:"dept_id"`
	Language string `json:"language,omitempty"`
}

type RequestGetByUnionID

type RequestGetByUnionID struct {
	UnionID string `json:"unionid"`
}

RequestGetByUnionID https://oapi.dingtalk.com/topapi/user/getbyunionid

type RequestGetUserInfoByCode

type RequestGetUserInfoByCode struct {
	TempAuthCode string `json:"tmp_auth_code"`
}

RequestGetUserInfoByCode https://oapi.dingtalk.com/sns/getuserinfo_bycode

type RequestUserGet

type RequestUserGet struct {
	UserID   string `json:"userid"`
	Language string `json:"language,omitempty"`
}

RequestUserGet https://oapi.dingtalk.com/topapi/v2/user/get

type Response

type Response interface {
	GotErr() error
}

type ResponseCreateProcessInstance

type ResponseCreateProcessInstance struct {
	BasicResponse     `json:",inline"`
	ProcessInstanceID string `json:"process_instance_id,omitempty"`
}

type ResponseDeptInfo

type ResponseDeptInfo struct {
	BasicResponse `json:",inline"`
	*DepartmentInfo
}

type ResponseDeptInfoV2

type ResponseDeptInfoV2 struct {
	BasicResponse `json:",inline"`
	Result        *DepartmentInfoV2 `json:"result,omitempty"`
}

type ResponseGetAccessToken

type ResponseGetAccessToken struct {
	*DingtalkErr `json:",inline"`
	AccessToken  string `json:"access_token"`
	ExpiresIn    int    `json:"expires_in"`
}

type ResponseGetByUnionID

type ResponseGetByUnionID struct {
	*BasicResponse `json:",inline"`
	Result         *UserGetByUnionId `json:"result,omitempty"`
}

ResponseGetByUnionID https://oapi.dingtalk.com/topapi/user/getbyunionid

type ResponseGetProcessInstance

type ResponseGetProcessInstance struct {
	BasicResponse   `json:",inline"`
	ProcessInstance *ProcessInstance `json:"process_instance,omitempty"`
}

type ResponseGetUserIdByUnionid

type ResponseGetUserIdByUnionid struct {
	BasicResponse `json:",inline"`
	Result        *DeptListParent `json:"result"`
}

type ResponseGetUserInfo

type ResponseGetUserInfo struct {
	*DingtalkErr `json:",inline"`
	Result       *CompleteUserInfo `json:"result"`
}

type ResponseGetUserInfoByCode

type ResponseGetUserInfoByCode struct {
	UserInfo     *UserInfo `json:"user_info"`
	*DingtalkErr `json:",inline"`
}

ResponseGetUserInfoByCode https://oapi.dingtalk.com/sns/getuserinfo_bycode

type ResponseOrganizationUserCount

type ResponseOrganizationUserCount struct {
	*DingtalkErr `json:",inline"`
	Count        int `json:"count"`
}

type ResponseUserByMobile

type ResponseUserByMobile struct {
	BasicResponse `json:",inline"`
	Result        struct {
		Userid string `json:"userid"`
	} `json:"result"`
}

type ResponseUserGet

type ResponseUserGet struct {
	BasicResponse `json:",inline"`
	Result        *UserGetResponse `json:"result"`
}

ResponseUserGet https://oapi.dingtalk.com/topapi/v2/user/get

type UnixTimestamp

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

func (*UnixTimestamp) MarshalJSON

func (ts *UnixTimestamp) MarshalJSON() ([]byte, error)

func (*UnixTimestamp) Time

func (ts *UnixTimestamp) Time() time.Time

func (*UnixTimestamp) UnmarshalJSON

func (ts *UnixTimestamp) UnmarshalJSON(data []byte) error

type UserGetByUnionId

type UserGetByUnionId struct {
	ContactType int    `json:"contact_type,omitempty"`
	UserID      string `json:"userid,omitempty"`
}

type UserGetResponse

type UserGetResponse struct {
	UserID             string              `json:"userid"`
	UnionID            string              `json:"unionid"`
	Name               string              `json:"name"`
	Avatar             string              `json:"avatar"`
	StateCode          string              `json:"state_code"` // 国际电话区号
	Mobile             string              `json:"mobile"`
	HideMobile         bool                `json:"hide_mobile"` // 是否隐藏手机号码
	Telephone          string              `json:"telephone"`   // 分机号
	JobNumber          string              `json:"job_number"`  // 工号
	Title              string              `json:"title"`       // 职位
	Email              string              `json:"email"`       // 邮箱
	WorkPlace          string              `json:"work_place"`  // 办公地点
	Remark             string              `json:"remark"`
	DepartmentIDs      []int               `json:"dept_id_list"`    // 所属部门ID列表
	DepartmentOrders   []*DepartmentOrder  `json:"dept_order_list"` // 员工在对应部门的排序
	Extension          string              `json:"extension"`       // 扩展属性
	HiredDate          *UnixTimestamp      `json:"hired_date"`
	Active             bool                `json:"active"`
	RealAuthed         bool                `json:"real_authed"` // 是否完成了实名认证
	Admin              bool                `json:"admin"`       // 是否未企业管理员
	Boss               bool                `json:"boss"`        // 是否为企业老板
	LeaderInDepartment []*DepartmentLeader `json:"leader_in_dept"`
	Roles              []*UserRole         `json:"role_list"`
}

type UserInfo

type UserInfo struct {
	Nick                 string `json:"nick,omitempty"`                     // 用户在钉钉上面的昵称
	UnionID              string `json:"unionid,omitempty"`                  // 用户在当前开放应用所属企业的唯一标识
	OpenID               string `json:"openid,omitempty"`                   // 用户在当前开放应用内的唯一标识
	MainOrgAuthHighLevel bool   `json:"main_org_auth_high_level,omitempty"` // 用户主企业是否达到高级认证级别
}

type UserRole

type UserRole struct {
	ID    int    `json:"id"`
	Name  string `json:"name"`
	Group string `json:"group_name"`
}

Jump to

Keyboard shortcuts

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