|
| 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 | +} |
0 commit comments