mirror of
https://github.com/silenceper/wechat.git
synced 2026-03-01 00:35:26 +08:00
Compare commits
1 Commits
fdacb5f67e
...
9622db07d7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9622db07d7 |
@@ -54,7 +54,6 @@ type USParams struct {
|
|||||||
ExpireType TExpireType `json:"expire_type"`
|
ExpireType TExpireType `json:"expire_type"`
|
||||||
ExpireTime int64 `json:"expire_time"`
|
ExpireTime int64 `json:"expire_time"`
|
||||||
ExpireInterval int `json:"expire_interval"`
|
ExpireInterval int `json:"expire_interval"`
|
||||||
IsExpire bool `json:"is_expire,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// USResult 返回的结果
|
// USResult 返回的结果
|
||||||
|
|||||||
@@ -9,16 +9,12 @@ import (
|
|||||||
const (
|
const (
|
||||||
// departmentCreateURL 创建部门
|
// departmentCreateURL 创建部门
|
||||||
departmentCreateURL = "https://qyapi.weixin.qq.com/cgi-bin/department/create?access_token=%s"
|
departmentCreateURL = "https://qyapi.weixin.qq.com/cgi-bin/department/create?access_token=%s"
|
||||||
// departmentUpdateURL 更新部门
|
|
||||||
departmentUpdateURL = "https://qyapi.weixin.qq.com/cgi-bin/department/update?access_token=%s"
|
|
||||||
// departmentDeleteURL 删除部门
|
|
||||||
departmentDeleteURL = "https://qyapi.weixin.qq.com/cgi-bin/department/delete?access_token=%s&id=%d"
|
|
||||||
// departmentSimpleListURL 获取子部门ID列表
|
// departmentSimpleListURL 获取子部门ID列表
|
||||||
departmentSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/simplelist?access_token=%s&id=%d"
|
departmentSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/simplelist?access_token=%s&id=%d"
|
||||||
// departmentListURL 获取部门列表
|
// departmentListURL 获取部门列表
|
||||||
departmentListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=%s"
|
departmentListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=%s"
|
||||||
departmentListByIDURL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=%s&id=%d"
|
departmentListByIDURL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=%s&id=%d"
|
||||||
// departmentGetURL 获取单个部门详情
|
// departmentGetURL 获取单个部门详情 https://qyapi.weixin.qq.com/cgi-bin/department/get?access_token=ACCESS_TOKEN&id=ID
|
||||||
departmentGetURL = "https://qyapi.weixin.qq.com/cgi-bin/department/get?access_token=%s&id=%d"
|
departmentGetURL = "https://qyapi.weixin.qq.com/cgi-bin/department/get?access_token=%s&id=%d"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -89,49 +85,6 @@ func (r *Client) DepartmentCreate(req *DepartmentCreateRequest) (*DepartmentCrea
|
|||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// DepartmentUpdateRequest 更新部门请求
|
|
||||||
type DepartmentUpdateRequest struct {
|
|
||||||
ID int `json:"id"`
|
|
||||||
Name string `json:"name,omitempty"`
|
|
||||||
NameEn string `json:"name_en,omitempty"`
|
|
||||||
ParentID int `json:"parentid,omitempty"`
|
|
||||||
Order int `json:"order,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// DepartmentUpdate 更新部门
|
|
||||||
// see https://developer.work.weixin.qq.com/document/path/90206
|
|
||||||
func (r *Client) DepartmentUpdate(req *DepartmentUpdateRequest) error {
|
|
||||||
var (
|
|
||||||
accessToken string
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var response []byte
|
|
||||||
if response, err = util.PostJSON(fmt.Sprintf(departmentUpdateURL, accessToken), req); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return util.DecodeWithCommonError(response, "DepartmentUpdate")
|
|
||||||
}
|
|
||||||
|
|
||||||
// DepartmentDelete 删除部门
|
|
||||||
// @see https://developer.work.weixin.qq.com/document/path/90207
|
|
||||||
func (r *Client) DepartmentDelete(departmentID int) error {
|
|
||||||
var (
|
|
||||||
accessToken string
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var response []byte
|
|
||||||
if response, err = util.HTTPGet(fmt.Sprintf(departmentDeleteURL, accessToken, departmentID)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return util.DecodeWithCommonError(response, "DepartmentDelete")
|
|
||||||
}
|
|
||||||
|
|
||||||
// DepartmentSimpleList 获取子部门ID列表
|
// DepartmentSimpleList 获取子部门ID列表
|
||||||
// see https://developer.work.weixin.qq.com/document/path/95350
|
// see https://developer.work.weixin.qq.com/document/path/95350
|
||||||
func (r *Client) DepartmentSimpleList(departmentID int) ([]*DepartmentID, error) {
|
func (r *Client) DepartmentSimpleList(departmentID int) ([]*DepartmentID, error) {
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ const (
|
|||||||
userSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist"
|
userSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist"
|
||||||
// userCreateURL 创建成员
|
// userCreateURL 创建成员
|
||||||
userCreateURL = "https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token=%s"
|
userCreateURL = "https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token=%s"
|
||||||
// userUpdateURL 更新成员
|
|
||||||
userUpdateURL = "https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token=%s"
|
|
||||||
// userGetURL 读取成员
|
// userGetURL 读取成员
|
||||||
userGetURL = "https://qyapi.weixin.qq.com/cgi-bin/user/get"
|
userGetURL = "https://qyapi.weixin.qq.com/cgi-bin/user/get"
|
||||||
// userDeleteURL 删除成员
|
// userDeleteURL 删除成员
|
||||||
@@ -156,51 +154,6 @@ func (r *Client) UserCreate(req *UserCreateRequest) (*UserCreateResponse, error)
|
|||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserUpdateRequest 更新成员请求
|
|
||||||
type UserUpdateRequest struct {
|
|
||||||
UserID string `json:"userid"`
|
|
||||||
NewUserID string `json:"new_userid"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Alias string `json:"alias"`
|
|
||||||
Mobile string `json:"mobile"`
|
|
||||||
Department []int `json:"department"`
|
|
||||||
Order []int `json:"order"`
|
|
||||||
Position string `json:"position"`
|
|
||||||
Gender int `json:"gender"`
|
|
||||||
Email string `json:"email"`
|
|
||||||
BizMail string `json:"biz_mail"`
|
|
||||||
IsLeaderInDept []int `json:"is_leader_in_dept"`
|
|
||||||
DirectLeader []string `json:"direct_leader"`
|
|
||||||
Enable int `json:"enable"`
|
|
||||||
AvatarMediaid string `json:"avatar_mediaid"`
|
|
||||||
Telephone string `json:"telephone"`
|
|
||||||
Address string `json:"address"`
|
|
||||||
MainDepartment int `json:"main_department"`
|
|
||||||
Extattr struct {
|
|
||||||
Attrs []ExtraAttr `json:"attrs"`
|
|
||||||
} `json:"extattr"`
|
|
||||||
ToInvite bool `json:"to_invite"`
|
|
||||||
ExternalPosition string `json:"external_position"`
|
|
||||||
ExternalProfile ExternalProfile `json:"external_profile"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// UserUpdate 更新成员
|
|
||||||
// see https://developer.work.weixin.qq.com/document/path/90197
|
|
||||||
func (r *Client) UserUpdate(req *UserUpdateRequest) error {
|
|
||||||
var (
|
|
||||||
accessToken string
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var response []byte
|
|
||||||
if response, err = util.PostJSON(fmt.Sprintf(userUpdateURL, accessToken), req); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return util.DecodeWithCommonError(response, "UserUpdate")
|
|
||||||
}
|
|
||||||
|
|
||||||
// UserGetResponse 获取部门成员响应
|
// UserGetResponse 获取部门成员响应
|
||||||
type UserGetResponse struct {
|
type UserGetResponse struct {
|
||||||
util.CommonError
|
util.CommonError
|
||||||
|
|||||||
@@ -59,30 +59,6 @@ func (r *Client) UploadImg(filename string) (*UploadImgResponse, error) {
|
|||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// UploadImgFromReader 从 io.Reader 上传图片
|
|
||||||
// @see https://developer.work.weixin.qq.com/document/path/90256
|
|
||||||
func (r *Client) UploadImgFromReader(filename string, reader io.Reader) (*UploadImgResponse, error) {
|
|
||||||
var (
|
|
||||||
accessToken string
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var byteData []byte
|
|
||||||
byteData, err = io.ReadAll(reader)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var response []byte
|
|
||||||
if response, err = util.PostFileByStream("media", filename, fmt.Sprintf(uploadImgURL, accessToken), byteData); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
result := &UploadImgResponse{}
|
|
||||||
err = util.DecodeWithError(response, result, "UploadImg")
|
|
||||||
return result, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// UploadTempFile 上传临时素材
|
// UploadTempFile 上传临时素材
|
||||||
// @see https://developer.work.weixin.qq.com/document/path/90253
|
// @see https://developer.work.weixin.qq.com/document/path/90253
|
||||||
// @mediaType 媒体文件类型,分别有图片(image)、语音(voice)、视频(video),普通文件(file)
|
// @mediaType 媒体文件类型,分别有图片(image)、语音(voice)、视频(video),普通文件(file)
|
||||||
@@ -190,13 +166,5 @@ func (r *Client) GetTempFile(mediaID string) ([]byte, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查响应是否为错误信息
|
|
||||||
err = util.DecodeWithCommonError(response, "GetTempFile")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果不是错误响应,则返回原始数据
|
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user