-
Notifications
You must be signed in to change notification settings - Fork 0
/
groupdel.go
72 lines (62 loc) · 1.88 KB
/
groupdel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Created by GoLand.
* User: 姜伟
* Date: 2020/1/13 0013
* Time: 16:19
*/
package group
import (
"github.com/a07061625/gompf/mpf"
"github.com/a07061625/gompf/mpf/api"
"github.com/a07061625/gompf/mpf/api/wx"
"github.com/a07061625/gompf/mpf/mpconstant/errorcode"
"github.com/a07061625/gompf/mpf/mpconstant/project"
"github.com/a07061625/gompf/mpf/mperr"
"github.com/valyala/fasthttp"
)
type groupDel struct {
wx.BaseWxAccount
appId string
groupId int // 分组ID
}
func (gd *groupDel) SetGroupId(groupId int) {
if groupId > 0 {
gd.groupId = groupId
} else {
panic(mperr.NewWxAccount(errorcode.WxAccountParam, "分组ID不合法", nil))
}
}
func (gd *groupDel) checkData() {
if gd.groupId <= 0 {
panic(mperr.NewWxAccount(errorcode.WxAccountParam, "分组ID不能为空", nil))
}
}
func (gd *groupDel) SendRequest() api.APIResult {
gd.checkData()
reqData := make(map[string]interface{})
reqData["group_id"] = gd.groupId
reqBody := mpf.JSONMarshal(reqData)
gd.ReqURI = "https://api.weixin.qq.com/merchant/group/del?access_token=" + wx.NewUtilWx().GetSingleAccessToken(gd.appId)
client, req := gd.GetRequest()
req.SetBody([]byte(reqBody))
resp, result := gd.SendInner(client, req, errorcode.WxAccountRequestPost)
if resp.RespCode > 0 {
return result
}
respData, _ := mpf.JSONUnmarshalMap(resp.Content)
errCode, ok := respData["errcode"]
if ok && (errCode.(int) == 0) {
result.Data = respData
} else {
result.Code = errorcode.WxAccountRequestPost
result.Msg = respData["errmsg"].(string)
}
return result
}
func NewGroupDel(appId string) *groupDel {
gd := &groupDel{wx.NewBaseWxAccount(), "", 0}
gd.appId = appId
gd.ReqContentType = project.HTTPContentTypeJSON
gd.ReqMethod = fasthttp.MethodPost
return gd
}