youdu

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2022 License: MIT Imports: 16 Imported by: 0

README

youdu

Feature

Install

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(message.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)

type Config

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

func (*Config) GetAccessTokenProvider

func (c *Config) GetAccessTokenProvider() *accessTokenProvider

func (*Config) GetEncryptor

func (c *Config) GetEncryptor() *encryptor

func (*Config) GetHttp

func (c *Config) GetHttp() *Http

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) 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(id int, userId int)

func (*Group) Create added in v0.2.0

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

Create 创建一个群组

func (*Group) Delete added in v0.2.0

func (g *Group) Delete(id int)

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) RemoveMember added in v0.2.0

func (g *Group) RemoveMember(id int, userId int)

func (*Group) Update added in v0.2.0

func (g *Group) Update(id int, name string)

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 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) 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

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