youdu

package module
v1.0.2 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 Go SDK

Lint GoDoc Go Report Card Language MIT license

🚀 Youdu SDK is a Go package that provides API implementation related to Youdu IM

Getting Started

Features

Prerequisites

  • Golang Version >= 1.16

Installation

go get github.com/addcnos/youdu

Usage

Please refer to the Documentation

package main

import (
	"github.com/addcnos/youdu"
	"github.com/addcnos/youdu/message"
)

func main()  {

	yd := youdu.New(&youdu.Config{
		Api:    "http://domain.com/api", // youdu api host
		Buin:   1111111, // 企业 buin 码
		AppId:  "22222222222222", // 应用 appId
		AesKey: "3444444444444444444444444444444444", // 应用 AesKey
	})

	yd.Message().Send(&message.TextMessage{
		ToUser:  "user1|user2", // 指定用户
		ToDept:  "dep1|dep2",   // 指定部门
		MsgType: message.MsgTypeText,
		Text: &message.TextItem{
			Content: "content",
		},
	})
}

Contributing

Very welcome to join us! Raise an Issue or submit a Pull Request.

License

MIT License © 2022 addcnos

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

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

func NewAuth

func NewAuth(config *Config) *Auth

func (*Auth) Identify

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

Identify 单点登录

func (*Auth) SetAuth

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

func (c *Config) GetDefaultPath() string

func (*Config) GetEncryptor

func (c *Config) GetEncryptor() *encryptor

func (*Config) GetHttp

func (c *Config) GetHttp() *Http

func (*Config) GetPath

func (c *Config) GetPath() string

GetPath 返回系统默认路径

type DecryptResult

type DecryptResult struct {
	AppId  string
	Data   string
	Length int32
}

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

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

func NewGroup

func NewGroup(config *Config) *Group

func (*Group) AddMember

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

func (*Group) Create

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

Create 创建一个群组

func (*Group) DelMember

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

func (*Group) Delete

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

func (*Group) Info

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

func (*Group) IsMember

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

func (*Group) List

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

func (*Group) Update

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

type GroupInfo

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

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

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

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

func (*Media) Search

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

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

type MediaInfo

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

type Message

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

func NewMessage

func NewMessage(config *Config) *Message

func (*Message) Popwindow

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

func (*Message) Send

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

func (*Message) SendFile

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

func (*Message) SendImage

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

func (*Message) SendText

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

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

func NewSession

func NewSession(config *Config) *Session

func (*Session) Create

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

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

func (*Session) Get

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

Get 获取会话信息

func (*Session) Send

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

Send 发送消息

func (*Session) Update

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

Update 更新会话信息

type SetAuthResp

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

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

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

func NewUser

func NewUser(config *Config) *User

func (*User) EnableState

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

EnableState 查询用户激活状态

func (*User) Get

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

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

func (*User) List

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

List 获取部门用户详细信息

func (*User) SimpleList

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

SimpleList 获取部门用户

type UserInfo

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

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

AccessToken 返回 accessToken

func (*Youdu) Auth

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

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

func (y *Youdu) Session() *Session

Session 创建会话相关的实例

func (*Youdu) User

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