1 Star 0 Fork 0

vibly/wechat-sdk

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
group.go 2.25 KB
一键复制 编辑 原始数据 按行查看 历史
夏雨天 提交于 2023-05-12 08:37 +08:00 . init
// 用户分组管理.
package group
import (
"gitee.com/vibly/wechat-sdk/mp/core"
)
type Group struct {
Id int64 `json:"id"` // 分组id, 由微信分配
Name string `json:"name"` // 分组名字, UTF8编码
UserCount int `json:"count"` // 分组内用户数量
}
// Create 创建分组.
func Create(clt *core.Client, name string) (group *Group, err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/groups/create?access_token="
var request struct {
Group struct {
Name string `json:"name"`
} `json:"group"`
}
request.Group.Name = name
var result struct {
core.Error
Group `json:"group"`
}
if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
result.Group.UserCount = 0
group = &result.Group
return
}
// Delete 删除分组.
func Delete(clt *core.Client, groupId int64) (err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/groups/delete?access_token="
var request struct {
Group struct {
Id int64 `json:"id"`
} `json:"group"`
}
request.Group.Id = groupId
var result core.Error
if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result
return
}
return
}
// Update 修改分组名.
func Update(clt *core.Client, groupId int64, name string) (err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/groups/update?access_token="
var request struct {
Group struct {
Id int64 `json:"id"`
Name string `json:"name"`
} `json:"group"`
}
request.Group.Id = groupId
request.Group.Name = name
var result core.Error
if err = clt.PostJSON(incompleteURL, &request, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result
return
}
return
}
// List 查询所有分组.
func List(clt *core.Client) (groups []Group, err error) {
const incompleteURL = "https://api.weixin.qq.com/cgi-bin/groups/get?access_token="
var result struct {
core.Error
Groups []Group `json:"groups"`
}
if err = clt.GetJSON(incompleteURL, &result); err != nil {
return
}
if result.ErrCode != core.ErrCodeOK {
err = &result.Error
return
}
groups = result.Groups
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/vibly/wechat-sdk.git
git@gitee.com:vibly/wechat-sdk.git
vibly
wechat-sdk
wechat-sdk
v1.0.0

搜索帮助