-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
213 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters