Skip to content

Commit 5ef4ac6

Browse files
committed
add: 增加模块内容安全
1 parent e0822a9 commit 5ef4ac6

16 files changed

+213
-33
lines changed

live.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ type LiveRoomGoods struct {
139139
Price int64 `json:"price"`
140140
// 商品价格(参考价格类型)
141141
Price2 int64 `json:"price2"`
142-
// 价格类型,1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必传) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必传
142+
// 价格类型,1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必填) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必填
143143
Price_type PriceType `json:"price_type"`
144144
// 商品id
145145
GoodsID int `json:"goods_id"`

livebroadcast/add_assistant.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import "github.com/medivhzhan/weapp/v3/request"
55
const apiAddAssistant = "/wxaapi/broadcast/room/addassistant"
66

77
type AddAssistantRequest struct {
8-
// 必传 房间ID
8+
// 必填 房间ID
99
RoomId int64 `json:"roomId"`
10-
// 必传 用户数组
10+
// 必填 用户数组
1111
Users []*Assistant `json:"users"`
1212
}
1313

1414
type Assistant struct {
15-
// 必传 用户微信号
15+
// 必填 用户微信号
1616
Username string `json:"username"`
17-
// 必传 用户昵称
17+
// 必填 用户昵称
1818
Nickname string `json:"nickname"`
1919
}
2020

livebroadcast/add_goods.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import "github.com/medivhzhan/weapp/v3/request"
55
const apiAddGoods = "/wxaapi/broadcast/room/addgoods"
66

77
type AddGoodsRequest struct {
8-
// 必传 数组列表,可传入多个,里面填写 商品 ID
8+
// 必填 数组列表,可传入多个,里面填写 商品 ID
99
Ids []int64 `json:"ids"`
10-
// 必传 房间ID
10+
// 必填 房间ID
1111
RoomId int64 `json:"roomId"`
1212
}
1313

livebroadcast/add_role.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ const (
1919
)
2020

2121
type AddRoleRequest struct {
22-
// 必传 设置用户的角色
22+
// 必填 设置用户的角色
2323
// 取值[1-管理员,2-主播,3-运营者],设置超级管理员将无效
2424
Role Role `json:"role"`
25-
// 必传 用户昵称
25+
// 必填 用户昵称
2626
Nickname string `json:"nickname"`
2727
}
2828

livebroadcast/add_sub_anchor.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import "github.com/medivhzhan/weapp/v3/request"
55
const apiAddSubAnchor = "/wxaapi/broadcast/room/addsubanchor"
66

77
type AddSubAnchorRequest struct {
8-
// 必传 房间ID
8+
// 必填 房间ID
99
RoomId int64 `json:"roomId"`
10-
// 必传 用户微信号
10+
// 必填 用户微信号
1111
Username string `json:"username"`
1212
}
1313

livebroadcast/delete_role.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import "github.com/medivhzhan/weapp/v3/request"
55
const apiDeleteRole = "/wxaapi/broadcast/role/deleterole"
66

77
type DeleteRoleRequest struct {
8-
// 必传 设置用户的角色
8+
// 必填 设置用户的角色
99
// 取值[1-管理员,2-主播,3-运营者],设置超级管理员将无效
1010
Role Role `json:"role"`
11-
// 必传 用户昵称
11+
// 必填 用户昵称
1212
Nickname string `json:"nickname"`
1313
}
1414

livebroadcast/delete_sub_anchor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "github.com/medivhzhan/weapp/v3/request"
55
const apiDeleteSubAnchor = "/wxaapi/broadcast/room/deletesubanchor"
66

77
type DeleteSubAnchorRequest struct {
8-
// 必传 房间ID
8+
// 必填 房间ID
99
RoomId int64 `json:"roomId"`
1010
}
1111

livebroadcast/get_liveInfo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type LiveRoomGoods struct {
2424
Price int64 `json:"price"`
2525
// 商品价格(参考价格类型)
2626
Price2 int64 `json:"price2"`
27-
// 价格类型,1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必传) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必传
27+
// 价格类型,1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必填) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必填
2828
Price_type PriceType `json:"price_type"`
2929
// 商品id
3030
GoodsID int `json:"goods_id"`

livebroadcast/goods_add.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type GoodsInfo struct {
1414
CoverImgUrl string `json:"coverImgUrl"`
1515
// 必填 商品名称,最长14个汉字,1个汉字相当于2个字符
1616
Name string `json:"name"`
17-
// 必填 价格类型,1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必传) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必传
17+
// 必填 价格类型,1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必填) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必填
1818
PriceType PriceType `json:"priceType"`
1919
// 必填 数字,最多保留两位小数,单位元
2020
Price float64 `json:"price"`

operation/get_js_err_detail.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,29 @@ import "github.com/medivhzhan/weapp/v3/request"
55
const apiGetJsErrDetail = "/wxaapi/log/jserr_detail"
66

77
type GetJsErrDetailRequest struct {
8-
// 必传 开始时间, 格式 "xxxx-xx-xx"
8+
// 必填 开始时间, 格式 "xxxx-xx-xx"
99
StartTime string `json:"startTime"`
10-
// 必传 结束时间,格式 “xxxx-xx-xx”
10+
// 必填 结束时间,格式 “xxxx-xx-xx”
1111
EndTime string `json:"endTime"`
12-
// 必传 错误列表查询 接口 返回的 errorMsgMd5 字段
12+
// 必填 错误列表查询 接口 返回的 errorMsgMd5 字段
1313
ErrorMsgMd5 string `json:"errorMsgMd5"`
14-
// 必传 错误列表查询 接口 返回的 errorStackMd5 字段
14+
// 必填 错误列表查询 接口 返回的 errorStackMd5 字段
1515
ErrorStackMd5 string `json:"errorStackMd5"`
16-
// 必传 小程序版本 "0"代表全部, 例如:“2.0.18”
16+
// 必填 小程序版本 "0"代表全部, 例如:“2.0.18”
1717
AppVersion string `json:"appVersion"`
18-
// 必传 基础库版本 "0"表示所有版本,例如 "2.14.1"
18+
// 必填 基础库版本 "0"表示所有版本,例如 "2.14.1"
1919
SdkVersion string `json:"sdkVersion"`
20-
// 必传 系统类型 "0"【全部】,"1" 【安卓】,"2" 【IOS】,"3"【其他】
20+
// 必填 系统类型 "0"【全部】,"1" 【安卓】,"2" 【IOS】,"3"【其他】
2121
OsName string `json:"osName"`
22-
// 必传 客户端版本 "0"表示所有版本, 例如 "7.0.22"
22+
// 必填 客户端版本 "0"表示所有版本, 例如 "7.0.22"
2323
ClientVersion string `json:"clientVersion"`
24-
// 必传 发生错误的用户 openId
24+
// 必填 发生错误的用户 openId
2525
Openid string `json:"openid"`
26-
// 必传 排序规则 "0" 升序, "1" 降序
26+
// 必填 排序规则 "0" 升序, "1" 降序
2727
Desc string `json:"desc"`
28-
// 必传 分页起始值
28+
// 必填 分页起始值
2929
Offset int `json:"offset"`
30-
// 必传 一次拉取最大值
30+
// 必填 一次拉取最大值
3131
Limit int `json:"limit"`
3232
}
3333

security/img_sec_check.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package security
2+
3+
import "github.com/medivhzhan/weapp/v3/request"
4+
5+
const apiImgSecCheck = "/wxa/img_sec_check"
6+
7+
type ImgSecCheckRequest struct {
8+
// 必填 要检测的图片文件,格式支持PNG、JPEG、JPG、GIF,图片尺寸不超过 750px x 1334px
9+
Media string
10+
}
11+
12+
// 校验一张图片是否含有违法违规内容。
13+
//
14+
// 官方文档: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.imgSecCheck.html
15+
func (cli *Security) ImgSecCheck(req *ImgSecCheckRequest) (*request.CommonError, error) {
16+
url, err := cli.conbineURI(apiImgSecCheck, nil)
17+
if err != nil {
18+
return nil, err
19+
}
20+
21+
res := new(request.CommonError)
22+
if err := cli.request.FormPostWithFile(url, "media", req.Media, res); err != nil {
23+
return nil, err
24+
}
25+
26+
return res, nil
27+
}

security/media_check_async.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package security
2+
3+
import "github.com/medivhzhan/weapp/v3/request"
4+
5+
const apiMediaCheckAsync = "/wxa/media_check_async"
6+
7+
type MediaCheckAsyncRequest struct {
8+
// 必填 要检测的图片或音频的url,支持图片格式包括jpg, jepg, png, bmp, gif(取首帧),支持的音频格式包括mp3, aac, ac3, wma, flac, vorbis, opus, wav
9+
MediaUrl string `json:"media_url"`
10+
// 必填 1:音频;2:图片
11+
MediaType uint8 `json:"media_type"`
12+
// 必填 接口版本号,2.0版本为固定值2
13+
Version uint8 `json:"version"`
14+
// 必填 用户的openid(用户需在近两小时访问过小程序)
15+
Openid string `json:"openid"`
16+
// 必填 场景枚举值(1 资料;2 评论;3 论坛;4 社交日志)
17+
Scene uint8 `json:"scene"`
18+
}
19+
20+
type MediaCheckAsyncResponse struct {
21+
request.CommonError
22+
// 唯一请求标识,标记单次请求,用于匹配异步推送结果
23+
TraceId string `json:"trace_id"`
24+
}
25+
26+
// 异步校验图片/音频是否含有违法违规内容。
27+
//
28+
// 官方文档: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.mediaCheckAsync.html
29+
func (cli *Security) MediaCheckAsync(req *MediaCheckAsyncRequest) (*MediaCheckAsyncResponse, error) {
30+
url, err := cli.conbineURI(apiMediaCheckAsync, nil)
31+
if err != nil {
32+
return nil, err
33+
}
34+
35+
res := new(MediaCheckAsyncResponse)
36+
if err := cli.request.Post(url, req, res); err != nil {
37+
return nil, err
38+
}
39+
40+
return res, nil
41+
}

security/msg_sec_check.go

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package security
2+
3+
import "github.com/medivhzhan/weapp/v3/request"
4+
5+
const apiMsgSecCheck = "/wxa/msg_sec_check"
6+
7+
type MsgSecCheckRequest struct {
8+
// 必填 接口版本号,2.0版本为固定值2
9+
Version uint8 `json:"version"`
10+
// 必填 用户的openid(用户需在近两小时访问过小程序)
11+
Openid string `json:"openid"`
12+
// 必填 场景枚举值(1 资料;2 评论;3 论坛;4 社交日志)
13+
Scene uint8 `json:"scene"`
14+
// 必填 需检测的文本内容,文本字数的上限为2500字
15+
Content string `json:"content"`
16+
// 非必填 用户昵称
17+
Nickname string `json:"nickname"`
18+
// 非必填 文本标题
19+
Title string `json:"title"`
20+
// 非必填 个性签名,该参数仅在资料类场景有效(scene=1)
21+
Signature string `json:"signature"`
22+
}
23+
24+
type MsgSecCheckResponse struct {
25+
request.CommonError
26+
// 唯一请求标识,标记单次请求
27+
TraceId string `json:"trace_id"`
28+
// 综合结果
29+
Result struct {
30+
// 建议,有risky、pass、review三种值
31+
Suggest string `json:"suggest"`
32+
// 命中标签枚举值,100 正常;10001 广告;20001 时政;20002 色情;20003 辱骂;20006 违法犯罪;20008 欺诈;20012 低俗;20013 版权;21000 其他
33+
Label string `json:"label"`
34+
} `json:"result"`
35+
// 详细检测结果
36+
Detail []struct {
37+
// 策略类型
38+
Strategy string `json:"strategy"`
39+
// 错误码,仅当该值为0时,该项结果有效
40+
Errcode int `json:"errcode"`
41+
// 建议,有risky、pass、review三种值
42+
Suggest string `json:"suggest"`
43+
// 命中标签枚举值,100 正常;10001 广告;20001 时政;20002 色情;20003 辱骂;20006 违法犯罪;20008 欺诈;20012 低俗;20013 版权;21000 其他
44+
Label int `json:"label"`
45+
// 0-100,代表置信度,越高代表越有可能属于当前返回的标签(label)
46+
Prob int `json:"prob"`
47+
// 命中的自定义关键词
48+
Keyword string `json:"keyword"`
49+
} `json:"detail"`
50+
}
51+
52+
// 检查一段文本是否含有违法违规内容。
53+
//
54+
// 官方文档: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.msgSecCheck.html
55+
func (cli *Security) MsgSecCheck(req *MsgSecCheckRequest) (*MsgSecCheckResponse, error) {
56+
url, err := cli.conbineURI(apiMsgSecCheck, nil)
57+
if err != nil {
58+
return nil, err
59+
}
60+
61+
res := new(MsgSecCheckResponse)
62+
if err := cli.request.Post(url, req, res); err != nil {
63+
return nil, err
64+
}
65+
66+
return res, nil
67+
}

security/security.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package security
2+
3+
import (
4+
"github.com/medivhzhan/weapp/v3/request"
5+
)
6+
7+
type Security struct {
8+
request *request.Request
9+
// 组成完整的 URL 地址
10+
// 默认包含 AccessToken
11+
conbineURI func(url string, req interface{}) (string, error)
12+
}
13+
14+
func NewSecurity(request *request.Request, conbineURI func(url string, req interface{}) (string, error)) *Security {
15+
sm := Security{
16+
request: request,
17+
conbineURI: conbineURI,
18+
}
19+
20+
return &sm
21+
}

server/types.go

+23-5
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,29 @@ type CardMessageResult struct {
7474
// MediaCheckAsyncResult 异步校验的图片/音频结果
7575
type MediaCheckAsyncResult struct {
7676
CommonServerResult
77-
IsRisky uint8 `json:"isrisky" xml:"isrisky"` // 检测结果,0:暂未检测到风险,1:风险
78-
ExtraInfoJSON string `json:"extra_info_json" xml:"extra_info_json"` // 附加信息,默认为空
79-
AppID string `json:"appid" xml:"appid"` // 小程序的appid
80-
TraceID string `json:"trace_id" xml:"trace_id"` // 任务id
81-
StatusCode int `json:"status_code" xml:"status_code"` // 默认为:0,4294966288(-1008)为链接无法下载
77+
AppID string `json:"appid" xml:"appid"` // 小程序的appid
78+
TraceID string `json:"trace_id" xml:"trace_id"` // 任务id
79+
Version string `json:"version" xml:"version"` // 可用于区分接口版本
80+
// 综合结果
81+
Result struct {
82+
// 建议,有risky、pass、review三种值
83+
Suggest string `json:"suggest" xml:"suggest"`
84+
// 命中标签枚举值,100 正常;10001 广告;20001 时政;20002 色情;20003 辱骂;20006 违法犯罪;20008 欺诈;20012 低俗;20013 版权;21000 其他
85+
Label string `json:"label" xml:"label"`
86+
} `json:"result" xml:"result"`
87+
// 详细检测结果
88+
Detail []struct {
89+
// 策略类型
90+
Strategy string `json:"strategy" xml:"strategy"`
91+
// 错误码,仅当该值为0时,该项结果有效
92+
Errcode int `json:"errcode" xml:"errcode"`
93+
// 建议,有risky、pass、review三种值
94+
Suggest string `json:"suggest" xml:"suggest"`
95+
// 命中标签枚举值,100 正常;10001 广告;20001 时政;20002 色情;20003 辱骂;20006 违法犯罪;20008 欺诈;20012 低俗;20013 版权;21000 其他
96+
Label int `json:"label" xml:"label"`
97+
// 0-100,代表置信度,越高代表越有可能属于当前返回的标签(label)
98+
Prob int `json:"prob" xml:"prob"`
99+
} `json:"detail" xml:"detail"`
82100
}
83101

84102
// AddNearbyPoiResult 附近小程序添加地点审核状态通知数据

weapp.go

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/medivhzhan/weapp/v3/operation"
1414
"github.com/medivhzhan/weapp/v3/request"
1515
"github.com/medivhzhan/weapp/v3/search"
16+
"github.com/medivhzhan/weapp/v3/security"
1617
"github.com/medivhzhan/weapp/v3/server"
1718
"github.com/medivhzhan/weapp/v3/subscribemessage"
1819
"github.com/medivhzhan/weapp/v3/updatablemessage"
@@ -208,3 +209,8 @@ func (cli *Client) NewSearch() *search.Search {
208209
func (cli *Client) NewLiveBroadcast() *livebroadcast.LiveBroadcast {
209210
return livebroadcast.NewLiveBroadcast(cli.request, cli.conbineURI)
210211
}
212+
213+
// 内容安全
214+
func (cli *Client) NewSecurity() *security.Security {
215+
return security.NewSecurity(cli.request, cli.conbineURI)
216+
}

0 commit comments

Comments
 (0)