wecom

package
v0.0.0-...-eca2909 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetGroupsCmd = &cobra.Command{
	Use:   "getgroups",
	Short: "获取企微部门分组列表",
	Run: func(cmd *cobra.Command, args []string) {
		corpid, _ := cmd.Flags().GetString("corpid")
		agentid, _ := cmd.Flags().GetString("agentid")
		secret, _ := cmd.Flags().GetString("secret")
		wc := NewWC(corpid, agentid, secret)
		depts, err := wc.GetDepts()
		if err != nil {
			logger.Error("获取部门列表失败", err)
		}

		table, err := gotable.Create("ID", "Name", "ParentId")
		if err != nil {
			log.Fatal("创建表格失败: ", err)
		}

		for _, dept := range depts {
			_ = table.AddRow([]string{
				strconv.Itoa(dept.ID),
				dept.Name,
				strconv.Itoa(dept.ParentID),
			})
		}
		fmt.Println(table)
	},
}
View Source
var GetUsersCmd = &cobra.Command{
	Use:   "getusers",
	Short: "获取企微用户列表",
	Run: func(cmd *cobra.Command, args []string) {
		corpid, _ := cmd.Flags().GetString("corpid")
		agentid, _ := cmd.Flags().GetString("agentid")
		secret, _ := cmd.Flags().GetString("secret")
		wc := NewWC(corpid, agentid, secret)

		users, err := wc.GetUsers()
		if err != nil {
			logger.Error("获取用户列表失败", err)
		}

		table, err := gotable.Create("UserID", "Name", "Mobile", "Department", "Order", "Position", "Gender", "Email", "BizMail", "IsLeaderInDept", "Avatar", "ThumbAvatar", "Telephone", "Alias", "ExtAttr", "Status", "QrCode", "ExternalProfile", "ExternalPosition", "Address", "OpenUserID", "MainDepartment", "EnglishName", "HideMobile")
		if err != nil {
			log.Fatal("创建表格失败: ", err)
		}

		for _, user := range users {
			_ = table.AddRow([]string{
				user.UserID,
				user.Name,
				user.Mobile,
				fmt.Sprintf("%v", user.Department),
				fmt.Sprintf("%v", user.Order),
				user.Position,
				user.Gender,
				user.Email,
				user.BizMail,
				fmt.Sprintf("%v", user.IsLeaderInDept),
				user.Avatar,
				user.ThumbAvatar,
				user.Telephone,
				user.Alias,
				fmt.Sprintf("%v", user.ExtAttr),
				strconv.Itoa(user.Status),
				user.QrCode,
				fmt.Sprintf("%v", user.ExternalProfile),
				user.ExternalPosition,
				user.Address,
				user.OpenUserID,
				strconv.Itoa(user.MainDepartment),
				user.EnglishName,
				strconv.Itoa(user.HideMobile),
			})
		}
		fmt.Println(table)
	},
}

Functions

This section is empty.

Types

type WC

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

func NewWC

func NewWC(CorpID, AgentID, CorpSecret string) *WC

NewWC 创建企业微信客户端

func (*WC) GetDepts

func (w *WC) GetDepts() ([]wecom.ListDepartmentResponseItem, error)

GetDepts 获取部门列表

func (*WC) GetUsers

func (w *WC) GetUsers() ([]wecom.ListUserResponseItem, error)

GetUsers 获取用户列表

Jump to

Keyboard shortcuts

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