youdu

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: MIT Imports: 18 Imported by: 0

README

youdu

👻👻 说明:该项目已捐赠至 AddcnOS 维护

Youdu Go SDK

Go Report Card GoDoc MIT license

Feature

Installation

go get github.com/go-packagist/youdu

Usage

package main

import (
	"github.com/go-packagist/youdu"
	"github.com/go-packagist/youdu/message"
	"log"
)

func main() {
	yd := youdu.New(&youdu.Config{
		Api:    "http://domain.com/api",
		Buin:   1111111,
		AppId:  "22222222222222",
		AesKey: "3444444444444444444444444444444444",
	})

	yd.Message().SendText("11111", "test")
	yd.Message().Send(&message.TextMessage{
		ToUser:  "11111",
		ToDept:  "",
		MsgType: message.MsgTypeText,
		Text: &message.TextItem{
			Content: "test",
		},
	})

	mediaId, err := yd.Media().Upload(youdu.MediaTypeImage, "test.jpeg")
	if err != nil {
		panic(err)
	}
	yd.Message().Send(&message.ImageMessage{
		ToUser:  "11111",
		ToDept:  "",
		MsgType: message.MsgTypeImage,
		Image: &message.MediaItem{
			MediaId: mediaId,
		},
	})

}

Documentation

Index

Constants

View Source
const (
	MediaTypeImage = "image"
	MediaTypeFile  = "file"
	MediaTypeVoice = "voice"
	MediaTypeVideo = "video"
)

Variables

This section is empty.

Functions

func NewAccessTokenProvider

func NewAccessTokenProvider(config *Config) *accessTokenProvider

func NewEncryptor

func NewEncryptor(config *Config) *encryptor

Types

type Auth added in v0.2.0

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

func NewAuth added in v0.2.0

func NewAuth(config *Config) *Auth

func (*Auth) Identify added in v0.2.0

func (a *Auth) Identify(token string) (i IdentifyResp, err error)

Identify 单点登录

func (*Auth) SetAuth added in v0.3.0

func (a *Auth) SetAuth(userId, password string) (bool, error)

SetAuth 第三方认证-设置认证信息

type Config

type Config struct {
	Api    string
	Buin   int
	AppId  string
	AesKey string
	Path   string
	// contains filtered or unexported fields
}

func (*Config) GetAccessTokenProvider

func (c *Config) GetAccessTokenProvider() *accessTokenProvider

func (*Config) GetDefaultPath added in v0.3.0

func (c *Config) GetDefaultPath() string

func (*Config) GetEncryptor

func (c *Config) GetEncryptor() *encryptor

func (*Config) GetHttp

func (c *Config) GetHttp() *Http

func (*Config) GetPath added in v0.3.0

func (c *Config) GetPath() string

GetPath 返回系统默认路径

type DecryptResult

type DecryptResult struct {
	AppId  string
	Data   string
	Length int32
	// contains filtered or unexported fields
}

func (*DecryptResult) Unmarshal

func (d *DecryptResult) Unmarshal(v interface{}) error

type Dept

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

func NewDept

func NewDept(config *Config) *Dept

func (*Dept) GetId added in v0.3.0

func (d *Dept) GetId(alias string)

func (*Dept) GetList

func (d *Dept) GetList(depId int) ([]DeptItem, error)

GetList 获取部门列表

type DeptItem

type DeptItem struct {
	Id       int    `json:"id"`
	Name     string `json:"name"`
	ParentId int    `json:"parentId"`
	SortId   int    `json:"sortId"`
}

type Group added in v0.2.0

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

func NewGroup added in v0.2.0

func NewGroup(config *Config) *Group

func (*Group) AddMember added in v0.2.0

func (g *Group) AddMember(groupId string, userId ...string) (bool, error)

func (*Group) Create added in v0.2.0

func (g *Group) Create(name string) (string, error)

Create 创建一个群组

func (*Group) DelMember added in v0.3.0

func (g *Group) DelMember(groupId string, userId ...string) (bool, error)

func (*Group) Delete added in v0.2.0

func (g *Group) Delete(groupId string) (bool, error)

func (*Group) Info added in v0.2.0

func (g *Group) Info(groupId string) (*GroupInfo, error)

func (*Group) IsMember added in v0.2.0

func (g *Group) IsMember(groupId, userId string) (bool, error)

func (*Group) List added in v0.2.0

func (g *Group) List(userId ...string) ([]GroupItem, error)

func (*Group) Update added in v0.2.0

func (g *Group) Update(groupId, groupName string) (bool, error)

type GroupInfo added in v0.2.0

type GroupInfo struct {
	Id           string      `json:"id"`
	Name         string      `json:"name"`
	Admins       interface{} `json:"admins"`
	BelongDeptId int         `json:"belongDeptId"`
	IsDeptGroup  bool        `json:"isDeptGroup"`
	Master       int         `json:"master"`
	Members      []struct {
		Account string `json:"account"`
		Name    string `json:"name"`
		Mobile  string `json:"mobile"`
	} `json:"members"`
}

type GroupItem added in v0.2.0

type GroupItem struct {
	Id           string `json:"id"`
	Name         string `json:"name"`
	Version      int    `json:"version"`
	IsDeptGroup  bool   `json:"isDeptGroup"`
	BelongDeptId int    `json:"belongDeptId"`
}

type Http

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

func NewHttp

func NewHttp(config *Config) *Http

func (*Http) Get

func (h *Http) Get(url string, params map[string]string, fn ...func(*resty.Request)) (*Response, error)

func (*Http) Post

func (h *Http) Post(url string, params interface{}, fn ...func(*resty.Request)) (*Response, error)

func (*Http) Request

func (h *Http) Request(method, url string, params interface{}, fn ...func(*resty.Request)) (*Response, error)

type IdentifyResp added in v0.2.0

type IdentifyResp struct {
	Buin   int `json:"buin"`
	Status struct {
		Code      int    `json:"code"`
		Message   string `json:"message"`
		CreatedAt string `json:"createdAt"`
	} `json:"status"`
	UserInfo struct {
		Gid        int    `json:"gid"`
		Account    string `json:"account"`
		ChsName    string `json:"chsName"`
		EngName    string `json:"engName"`
		Gender     int    `json:"gender"`
		OrgId      int    `json:"orgId"`
		Mobile     string `json:"mobile"`
		Phone      string `json:"phone"`
		Email      string `json:"email"`
		CustomAttr string `json:"customAttr"`
	} `json:"userInfo"`
}

type Media

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

func NewMedia

func NewMedia(config *Config) *Media

func (*Media) Get added in v0.2.0

func (m *Media) Get(mediaId string) (r MediaGetResp, err error)

func (*Media) Search added in v0.2.0

func (m *Media) Search(mediaId string) (i MediaInfo, err error)

func (*Media) Upload

func (m *Media) Upload(fileType string, filePath string) (string, error)

type MediaGetResp added in v0.2.0

type MediaGetResp struct {
	Name string `json:"name"`
	Size int    `json:"size"`
	Body string `json:"body"`
}

type MediaInfo added in v0.2.0

type MediaInfo struct {
	Name string `json:"name"`
	Size int    `json:"size"`
}

type Message

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

func NewMessage added in v0.2.0

func NewMessage(config *Config) *Message

func (*Message) Popwindow added in v0.2.0

func (m *Message) Popwindow(msg message.Message) error

func (*Message) Send added in v0.2.0

func (m *Message) Send(msg message.Message) error

func (*Message) SendFile added in v0.2.0

func (m *Message) SendFile(toUser, mediaId string, toDept ...string) error

func (*Message) SendImage added in v0.2.0

func (m *Message) SendImage(toUser, mediaId string, toDept ...string) error

func (*Message) SendText added in v0.2.0

func (m *Message) SendText(toUser, content string, toDept ...string) error

type Pkcs7

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

Pkcs7 is used to padding and unpadding messages.

func NewPkcs7

func NewPkcs7() *Pkcs7

NewPkcs7 is used to create a new Pkcs7.

func (*Pkcs7) Padding

func (p *Pkcs7) Padding(content []byte) []byte

Padding is used to padding messages.

func (*Pkcs7) Unpadding

func (p *Pkcs7) Unpadding(content []byte) []byte

Unpadding is used to unpadding messages.

type Response

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

func NewResponse

func NewResponse(restyResponse *resty.Response) *Response

func (*Response) Body

func (r *Response) Body() []byte

func (*Response) Header

func (r *Response) Header() map[string][]string

func (*Response) IsSuccess

func (r *Response) IsSuccess() bool

func (*Response) Json

func (r *Response) Json() (map[string]interface{}, error)

func (*Response) StatusCode

func (r *Response) StatusCode() int

func (*Response) String

func (r *Response) String() string

type Session added in v0.2.0

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

func NewSession added in v0.2.0

func NewSession(config *Config) *Session

func (*Session) Create added in v0.2.0

func (s *Session) Create(title string, members []string) (*session.Session, error)

Create 创建一个会话 members 第一个默认为创建者

func (*Session) Get added in v0.2.0

func (s *Session) Get(sessionId string) (*session.Session, error)

Get 获取会话信息

func (*Session) Send added in v0.2.0

func (s *Session) Send(message session.Message) error

Send 发送消息

func (*Session) Update added in v0.2.0

func (s *Session) Update(sessionId, opUser, title string, addMembers, delMembers []string) (*session.Session, error)

Update 更新会话信息

type SetAuthResp added in v0.3.0

type SetAuthResp struct {
	FromUser   string `json:"fromUser"`
	CreateTime int    `json:"createTime"`
	PackageId  int    `json:"packageId"`
	MsgType    string `json:"msgType"`
	Passwd     string `json:"passwd"`
}

type SimpleUserInfo added in v0.3.0

type SimpleUserInfo struct {
	Gid    int    `json:"gid"`
	UserId string `json:"userId"`
	Name   string `json:"name"`
	Gender int    `json:"gender"`
	Dept   []int  `json:"dept"`
}

type User added in v0.2.0

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

func NewUser added in v0.2.0

func NewUser(config *Config) *User

func (*User) EnableState added in v0.3.0

func (u *User) EnableState(userId string) (int, error)

EnableState 查询用户激活状态

func (*User) Get added in v0.2.0

func (u *User) Get(userId string) (UserInfo, error)

Get 获取用户信息 see: https://youdu.im/doc/api/c01_00013.html#_6

func (*User) List added in v0.3.0

func (u *User) List(deptId int) ([]UserInfo, error)

List 获取部门用户详细信息

func (*User) SimpleList added in v0.3.0

func (u *User) SimpleList(deptId int) ([]SimpleUserInfo, error)

SimpleList 获取部门用户

type UserInfo added in v0.2.0

type UserInfo struct {
	Gid        int    `json:"gid"`
	UserId     string `json:"userId"`
	Name       string `json:"name"`
	Gender     int    `json:"gender"` // 性别。0表示男性,1表示女性
	Mobile     string `json:"mobile"`
	Phone      string `json:"phone"`
	Email      string `json:"email"`
	Dept       []int  `json:"dept"`
	DeptDetail []struct {
		DeptId   int    `json:"deptId"`
		DeptName string `json:"deptName"`
		Position string `json:"position"`
		Weight   int    `json:"weight"`
		SortId   int    `json:"sortId"`
	} `json:"deptDetail"`
	Attrs []interface{} `json:"attrs"`
}

type Youdu

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

func New

func New(config *Config) *Youdu

New 创建一个 Youdu 实例

func (*Youdu) AccessToken added in v0.2.0

func (y *Youdu) AccessToken() (string, error)

AccessToken 返回 accessToken

func (*Youdu) Auth added in v0.2.0

func (y *Youdu) Auth() *Auth

func (*Youdu) Config

func (y *Youdu) Config() *Config

Config 获取配置

func (*Youdu) Dept

func (y *Youdu) Dept() *Dept

Dept 创建部门相关的实例

func (*Youdu) Encryptor

func (y *Youdu) Encryptor() *encryptor

Encryptor 返回加密器

func (*Youdu) Group added in v0.2.0

func (y *Youdu) Group() *Group

Group 创建群相关的实例

func (*Youdu) Media

func (y *Youdu) Media() *Media

Media 创建媒体相关的实例

func (*Youdu) Message

func (y *Youdu) Message() *Message

Message 创建消息相关的实例

func (*Youdu) Session added in v0.2.0

func (y *Youdu) Session() *Session

Session 创建会话相关的实例

func (*Youdu) User added in v0.2.0

func (y *Youdu) User() *User

User 创建用户相关的实例

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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