-
Notifications
You must be signed in to change notification settings - Fork 0
/
auditstatus.go
75 lines (64 loc) · 2.02 KB
/
auditstatus.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
73
74
75
/**
* Created by GoLand.
* User: 姜伟
* Date: 2020/1/11 0011
* Time: 11:58
*/
package codemanager
import (
"regexp"
"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 auditStatus struct {
wx.BaseWxOpen
appId string // 应用ID
auditId string // 审核id
}
func (cas *auditStatus) SetAuditId(auditId string) {
match, _ := regexp.MatchString(project.RegexDigitAlpha, auditId)
if match {
cas.auditId = auditId
} else {
panic(mperr.NewWxOpenMini(errorcode.WxOpenParam, "审核id不合法", nil))
}
}
func (cas *auditStatus) checkData() {
if len(cas.auditId) == 0 {
panic(mperr.NewWxOpenMini(errorcode.WxOpenParam, "审核id不能为空", nil))
}
cas.ReqData["audit_id"] = cas.auditId
}
func (cas *auditStatus) SendRequest() api.APIResult {
cas.checkData()
reqBody := mpf.JSONMarshal(cas.ReqData)
cas.ReqURI = "https://api.weixin.qq.com/wxa/get_auditstatus?access_token=" + wx.NewUtilWx().GetOpenAuthorizeAccessToken(cas.appId)
client, req := cas.GetRequest()
req.SetBody([]byte(reqBody))
resp, result := cas.SendInner(client, req, errorcode.WxOpenRequestPost)
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.WxOpenRequestPost
result.Msg = respData["errmsg"].(string)
}
return result
}
func NewCodeAuditStatus(appId string) *auditStatus {
cas := &auditStatus{wx.NewBaseWxOpen(), "", ""}
cas.appId = appId
cas.ReqContentType = project.HTTPContentTypeJSON
cas.ReqMethod = fasthttp.MethodPost
return cas
}