forked from mygomod/muses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
security.go
76 lines (64 loc) · 1.98 KB
/
security.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
76
package miniprogram
import (
"encoding/json"
"fmt"
"github.com/pinke/muses/pkg/wechat/util"
)
const (
getImgSecCheckURL = "https://api.weixin.qq.com/wxa/img_sec_check?access_token=%s"
getMediaCheckURL = "https://api.weixin.qq.com/wxa/media_check_async?access_token=%s"
getMsgSecCheckURL = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=%s"
)
// ResAnalysisRetain 小程序留存数据返回
type ResSecurity struct {
util.CommonError
}
// CheckImg 检测图片
// 文档地址: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.imgSecCheck.html
func (wxa *MiniProgram) CheckImg(fileName string) (response ResSecurity, err error) {
var accessToken string
accessToken, err = wxa.GetAccessToken()
if err != nil {
return
}
var info []byte
info,err = wxa.Context.PostFile("media",fileName,fmt.Sprintf(getImgSecCheckURL,accessToken))
if err != nil {
return
}
err = json.Unmarshal(info,&response)
return
}
//// CheckMedia 检测Media
//// 文档地址: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.imgSecCheck.html
//func (wxa *MiniProgram) CheckMedia(fileName string) (response ResSecurity, err error) {
// var info []byte
// info,err = wxa.Context.PostFile("media",fileName,getImgSecCheckURL)
// if err != nil {
// return
// }
// err = json.Unmarshal(info,&response)
// return
//}
type ReqCheckMsg struct {
Content string `json:"content"`
}
// CheckMsg 检测敏感词
// 文档地址: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.msgSecCheck.html
func (wxa *MiniProgram) CheckMsg(content string) (response ResSecurity, err error) {
var accessToken string
accessToken, err = wxa.GetAccessToken()
if err != nil {
return
}
var info []byte
req := ReqCheckMsg {
Content:content,
}
info,err = wxa.Context.PostJSON(fmt.Sprintf(getMsgSecCheckURL,accessToken),req)
if err != nil {
return
}
err = json.Unmarshal(info,&response)
return
}