添加企业微信查询所有企业工作人员信息
This commit is contained in:
@@ -47,7 +47,8 @@ func (a *API) CreateAppChat(param *CreateAppChatParamReq) error {
|
||||
// 获取所有的部门列表
|
||||
func (a *API) GetAllDepartmentList() ([]*Department, error) {
|
||||
a.CheckAccessTokenExpiresIn()
|
||||
data, err := a.AccessAPI(WeChatBaseApi, GetAllDepartmentListById, http.MethodGet, map[string]interface{}{"access_token": a.accessToken})
|
||||
param := map[string]interface{}{"access_token": a.accessToken}
|
||||
data, err := a.AccessAPI(WeChatBaseApi, GetAllDepartmentListById, http.MethodGet, param)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -62,25 +63,6 @@ func (a *API) GetAllDepartmentList() ([]*Department, error) {
|
||||
return result.Department, nil
|
||||
}
|
||||
|
||||
// 获取企业部门用户详细情况
|
||||
func (a *API) GetEnterpriseStaffInfo(department int) ([]*UserList, error) {
|
||||
a.CheckAccessTokenExpiresIn()
|
||||
departmentUserDetail, err := a.AccessAPI(WeChatBaseApi, GetDepartmentUserDetail, http.MethodGet, map[string]interface{}{"department_id": department, "fetch_child": 0})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &GetEnterpriseStaffInfoRes{}
|
||||
if err := utils.Map2StructByJson(departmentUserDetail, result, false); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if result.ErrCode != 0 {
|
||||
return nil, errors.New(result.ErrMsg)
|
||||
}
|
||||
|
||||
return result.UserList, nil
|
||||
}
|
||||
|
||||
// 通过手机号获取用户消息
|
||||
func (a *API) GetUserIdByMobile(mobile string) (string, error) {
|
||||
a.CheckAccessTokenExpiresIn()
|
||||
|
||||
37
platformapi/enterprise_wechat/department_list.go
Normal file
37
platformapi/enterprise_wechat/department_list.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package enterprise_wechat
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"net/http"
|
||||
|
||||
"errors"
|
||||
)
|
||||
|
||||
// GetDepartmentList 获取部门id列表
|
||||
func (a *API) GetDepartmentList() {
|
||||
a.CheckAccessTokenExpiresIn()
|
||||
param := map[string]interface{}{"access_token": a.accessToken}
|
||||
departmentList, err := a.AccessAPI(WeChatBaseApi, GetDepartmentList, http.MethodGet, param)
|
||||
fmt.Println(departmentList)
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
// GetEnterpriseStaffInfo 获取企业部门用户详细情况
|
||||
func (a *API) GetEnterpriseStaffInfo(department int) ([]*UserList, error) {
|
||||
a.CheckAccessTokenExpiresIn()
|
||||
departmentUserDetail, err := a.AccessAPI(WeChatBaseApi, GetDepartmentUserDetail, http.MethodGet, map[string]interface{}{"fetch_child": 1, "department_id": department, "access_token": a.accessToken})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &GetEnterpriseStaffInfoRes{}
|
||||
if err := utils.Map2StructByJson(departmentUserDetail, result, false); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if result.ErrCode != 0 {
|
||||
return nil, errors.New(result.ErrMsg)
|
||||
}
|
||||
|
||||
return result.UserList, nil
|
||||
}
|
||||
@@ -129,3 +129,11 @@ func TestGetUserId(t *testing.T) {
|
||||
phone, err := api.GetUserIdByMobile("18981810340")
|
||||
globals.SugarLogger.Debugf("phone := %s,err :=%s", phone, err)
|
||||
}
|
||||
|
||||
func TestDepartmentList(t *testing.T) {
|
||||
api.GetDepartmentList()
|
||||
}
|
||||
|
||||
func TestGetEnterpriseStaffInfo(t *testing.T) {
|
||||
api.GetEnterpriseStaffInfo(7)
|
||||
}
|
||||
|
||||
@@ -108,7 +108,8 @@ func (a *API) AccessAPI(baseUrl, actionApi, method string, bizParams map[string]
|
||||
fullURL := utils.GenerateGetURL(baseUrl, actionApi, map[string]interface{}{"access_token": a.accessToken})
|
||||
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(string(data)))
|
||||
} else {
|
||||
request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(baseUrl, actionApi, bizParams), nil)
|
||||
getUrl := utils.GenerateGetURL(baseUrl, actionApi, bizParams)
|
||||
request, _ = http.NewRequest(http.MethodGet, getUrl, nil)
|
||||
}
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
return request
|
||||
|
||||
@@ -7,18 +7,21 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
WeChatBaseApi = "https://qyapi.weixin.qq.com" // 企业微信基础访问链接
|
||||
WeChatBaseApi = "https://qyapi.weixin.qq.com" // 企业微信基础访问链接
|
||||
ParentDepartmentId = 7 // 企业微信全职人员文件夹id
|
||||
|
||||
// api接口
|
||||
GetToken = "cgi-bin/gettoken" // 获取token
|
||||
CreateAppChat = "cgi-bin/appchat/create" // 创建会话群聊
|
||||
GetAllDepartmentListById = "cgi-bin/department/list" // 获取所有的部门
|
||||
CreateBoosToJxStaff = "cgi-bin/user/create" // 将京西老板创建为企业员工
|
||||
GetDepartmentUserDetail = "cgi-bin/user/list" // 获取部门用户详细情况
|
||||
GetUserByMobileUrl = "cgi-bin/user/getuserid" // 通过手机号获取用户id
|
||||
SendMsgToUser = "cgi-bin/message/send" // 给用户发送消息
|
||||
GetToken = "cgi-bin/gettoken" // 获取token
|
||||
CreateAppChat = "cgi-bin/appchat/create" // 创建会话群聊
|
||||
GetAllDepartmentListById = "cgi-bin/department/list" // 获取所有的部门
|
||||
CreateBoosToJxStaff = "cgi-bin/user/create" // 将京西老板创建为企业员工
|
||||
GetDepartmentUserDetail = "cgi-bin/user/list" // 获取部门用户详细情况
|
||||
GetUserByMobileUrl = "cgi-bin/user/getuserid" // 通过手机号获取用户id
|
||||
SendMsgToUser = "cgi-bin/message/send" // 给用户发送消息
|
||||
GetDepartmentList = "cgi-bin/department/simplelist" // 获取部门子id列表
|
||||
|
||||
EnterpriseTicketInfo = "/suite/receive" // 企业微信服务器会定时(每十分钟)推送ticket
|
||||
|
||||
)
|
||||
|
||||
// 注册请求api
|
||||
|
||||
Reference in New Issue
Block a user