Skip to content

Commit

Permalink
add: 增加模块内容安全
Browse files Browse the repository at this point in the history
  • Loading branch information
royalrick committed Sep 27, 2021
1 parent e0822a9 commit 5ef4ac6
Show file tree
Hide file tree
Showing 16 changed files with 213 additions and 33 deletions.
2 changes: 1 addition & 1 deletion live.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ type LiveRoomGoods struct {
Price int64 `json:"price"`
// 商品价格(参考价格类型)
Price2 int64 `json:"price2"`
// 价格类型,1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必传) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必传
// 价格类型,1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必填) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必填
Price_type PriceType `json:"price_type"`
// 商品id
GoodsID int `json:"goods_id"`
Expand Down
8 changes: 4 additions & 4 deletions livebroadcast/add_assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import "github.com/medivhzhan/weapp/v3/request"
const apiAddAssistant = "/wxaapi/broadcast/room/addassistant"

type AddAssistantRequest struct {
// 必传 房间ID
// 必填 房间ID
RoomId int64 `json:"roomId"`
// 必传 用户数组
// 必填 用户数组
Users []*Assistant `json:"users"`
}

type Assistant struct {
// 必传 用户微信号
// 必填 用户微信号
Username string `json:"username"`
// 必传 用户昵称
// 必填 用户昵称
Nickname string `json:"nickname"`
}

Expand Down
4 changes: 2 additions & 2 deletions livebroadcast/add_goods.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import "github.com/medivhzhan/weapp/v3/request"
const apiAddGoods = "/wxaapi/broadcast/room/addgoods"

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

Expand Down
4 changes: 2 additions & 2 deletions livebroadcast/add_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const (
)

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

Expand Down
4 changes: 2 additions & 2 deletions livebroadcast/add_sub_anchor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import "github.com/medivhzhan/weapp/v3/request"
const apiAddSubAnchor = "/wxaapi/broadcast/room/addsubanchor"

type AddSubAnchorRequest struct {
// 必传 房间ID
// 必填 房间ID
RoomId int64 `json:"roomId"`
// 必传 用户微信号
// 必填 用户微信号
Username string `json:"username"`
}

Expand Down
4 changes: 2 additions & 2 deletions livebroadcast/delete_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import "github.com/medivhzhan/weapp/v3/request"
const apiDeleteRole = "/wxaapi/broadcast/role/deleterole"

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

Expand Down
2 changes: 1 addition & 1 deletion livebroadcast/delete_sub_anchor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "github.com/medivhzhan/weapp/v3/request"
const apiDeleteSubAnchor = "/wxaapi/broadcast/room/deletesubanchor"

type DeleteSubAnchorRequest struct {
// 必传 房间ID
// 必填 房间ID
RoomId int64 `json:"roomId"`
}

Expand Down
2 changes: 1 addition & 1 deletion livebroadcast/get_liveInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type LiveRoomGoods struct {
Price int64 `json:"price"`
// 商品价格(参考价格类型)
Price2 int64 `json:"price2"`
// 价格类型,1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必传) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必传
// 价格类型,1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必填) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必填
Price_type PriceType `json:"price_type"`
// 商品id
GoodsID int `json:"goods_id"`
Expand Down
2 changes: 1 addition & 1 deletion livebroadcast/goods_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type GoodsInfo struct {
CoverImgUrl string `json:"coverImgUrl"`
// 必填 商品名称,最长14个汉字,1个汉字相当于2个字符
Name string `json:"name"`
// 必填 价格类型,1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必传) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必传
// 必填 价格类型,1:一口价(只需要传入price,price2不传) 2:价格区间(price字段为左边界,price2字段为右边界,price和price2必填) 3:显示折扣价(price字段为原价,price2字段为现价, price和price2必填
PriceType PriceType `json:"priceType"`
// 必填 数字,最多保留两位小数,单位元
Price float64 `json:"price"`
Expand Down
24 changes: 12 additions & 12 deletions operation/get_js_err_detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ import "github.com/medivhzhan/weapp/v3/request"
const apiGetJsErrDetail = "/wxaapi/log/jserr_detail"

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

Expand Down
27 changes: 27 additions & 0 deletions security/img_sec_check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package security

import "github.com/medivhzhan/weapp/v3/request"

const apiImgSecCheck = "/wxa/img_sec_check"

type ImgSecCheckRequest struct {
// 必填 要检测的图片文件,格式支持PNG、JPEG、JPG、GIF,图片尺寸不超过 750px x 1334px
Media string
}

// 校验一张图片是否含有违法违规内容。
//
// 官方文档: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.imgSecCheck.html
func (cli *Security) ImgSecCheck(req *ImgSecCheckRequest) (*request.CommonError, error) {
url, err := cli.conbineURI(apiImgSecCheck, nil)
if err != nil {
return nil, err
}

res := new(request.CommonError)
if err := cli.request.FormPostWithFile(url, "media", req.Media, res); err != nil {
return nil, err
}

return res, nil
}
41 changes: 41 additions & 0 deletions security/media_check_async.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package security

import "github.com/medivhzhan/weapp/v3/request"

const apiMediaCheckAsync = "/wxa/media_check_async"

type MediaCheckAsyncRequest struct {
// 必填 要检测的图片或音频的url,支持图片格式包括jpg, jepg, png, bmp, gif(取首帧),支持的音频格式包括mp3, aac, ac3, wma, flac, vorbis, opus, wav
MediaUrl string `json:"media_url"`
// 必填 1:音频;2:图片
MediaType uint8 `json:"media_type"`
// 必填 接口版本号,2.0版本为固定值2
Version uint8 `json:"version"`
// 必填 用户的openid(用户需在近两小时访问过小程序)
Openid string `json:"openid"`
// 必填 场景枚举值(1 资料;2 评论;3 论坛;4 社交日志)
Scene uint8 `json:"scene"`
}

type MediaCheckAsyncResponse struct {
request.CommonError
// 唯一请求标识,标记单次请求,用于匹配异步推送结果
TraceId string `json:"trace_id"`
}

// 异步校验图片/音频是否含有违法违规内容。
//
// 官方文档: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.mediaCheckAsync.html
func (cli *Security) MediaCheckAsync(req *MediaCheckAsyncRequest) (*MediaCheckAsyncResponse, error) {
url, err := cli.conbineURI(apiMediaCheckAsync, nil)
if err != nil {
return nil, err
}

res := new(MediaCheckAsyncResponse)
if err := cli.request.Post(url, req, res); err != nil {
return nil, err
}

return res, nil
}
67 changes: 67 additions & 0 deletions security/msg_sec_check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package security

import "github.com/medivhzhan/weapp/v3/request"

const apiMsgSecCheck = "/wxa/msg_sec_check"

type MsgSecCheckRequest struct {
// 必填 接口版本号,2.0版本为固定值2
Version uint8 `json:"version"`
// 必填 用户的openid(用户需在近两小时访问过小程序)
Openid string `json:"openid"`
// 必填 场景枚举值(1 资料;2 评论;3 论坛;4 社交日志)
Scene uint8 `json:"scene"`
// 必填 需检测的文本内容,文本字数的上限为2500字
Content string `json:"content"`
// 非必填 用户昵称
Nickname string `json:"nickname"`
// 非必填 文本标题
Title string `json:"title"`
// 非必填 个性签名,该参数仅在资料类场景有效(scene=1)
Signature string `json:"signature"`
}

type MsgSecCheckResponse struct {
request.CommonError
// 唯一请求标识,标记单次请求
TraceId string `json:"trace_id"`
// 综合结果
Result struct {
// 建议,有risky、pass、review三种值
Suggest string `json:"suggest"`
// 命中标签枚举值,100 正常;10001 广告;20001 时政;20002 色情;20003 辱骂;20006 违法犯罪;20008 欺诈;20012 低俗;20013 版权;21000 其他
Label string `json:"label"`
} `json:"result"`
// 详细检测结果
Detail []struct {
// 策略类型
Strategy string `json:"strategy"`
// 错误码,仅当该值为0时,该项结果有效
Errcode int `json:"errcode"`
// 建议,有risky、pass、review三种值
Suggest string `json:"suggest"`
// 命中标签枚举值,100 正常;10001 广告;20001 时政;20002 色情;20003 辱骂;20006 违法犯罪;20008 欺诈;20012 低俗;20013 版权;21000 其他
Label int `json:"label"`
// 0-100,代表置信度,越高代表越有可能属于当前返回的标签(label)
Prob int `json:"prob"`
// 命中的自定义关键词
Keyword string `json:"keyword"`
} `json:"detail"`
}

// 检查一段文本是否含有违法违规内容。
//
// 官方文档: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.msgSecCheck.html
func (cli *Security) MsgSecCheck(req *MsgSecCheckRequest) (*MsgSecCheckResponse, error) {
url, err := cli.conbineURI(apiMsgSecCheck, nil)
if err != nil {
return nil, err
}

res := new(MsgSecCheckResponse)
if err := cli.request.Post(url, req, res); err != nil {
return nil, err
}

return res, nil
}
21 changes: 21 additions & 0 deletions security/security.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package security

import (
"github.com/medivhzhan/weapp/v3/request"
)

type Security struct {
request *request.Request
// 组成完整的 URL 地址
// 默认包含 AccessToken
conbineURI func(url string, req interface{}) (string, error)
}

func NewSecurity(request *request.Request, conbineURI func(url string, req interface{}) (string, error)) *Security {
sm := Security{
request: request,
conbineURI: conbineURI,
}

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

// AddNearbyPoiResult 附近小程序添加地点审核状态通知数据
Expand Down
6 changes: 6 additions & 0 deletions weapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/medivhzhan/weapp/v3/operation"
"github.com/medivhzhan/weapp/v3/request"
"github.com/medivhzhan/weapp/v3/search"
"github.com/medivhzhan/weapp/v3/security"
"github.com/medivhzhan/weapp/v3/server"
"github.com/medivhzhan/weapp/v3/subscribemessage"
"github.com/medivhzhan/weapp/v3/updatablemessage"
Expand Down Expand Up @@ -208,3 +209,8 @@ func (cli *Client) NewSearch() *search.Search {
func (cli *Client) NewLiveBroadcast() *livebroadcast.LiveBroadcast {
return livebroadcast.NewLiveBroadcast(cli.request, cli.conbineURI)
}

// 内容安全
func (cli *Client) NewSecurity() *security.Security {
return security.NewSecurity(cli.request, cli.conbineURI)
}

0 comments on commit 5ef4ac6

Please sign in to comment.