1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-04 21:02:25 +08:00
Files
wechat/miniprogram/content/content.go
houseme 96c1f98944 [feature] Format the code and improve Mini Program authorization to o… (#473)
* [feature] Format the code and improve Mini Program authorization to obtain openid(miniprogram/auth/auth.go Code2Session)

* [feature] CheckEncryptedData (https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/user-info/auth.checkEncryptedData.html)

* upgrade json error

* upgrade json error

Co-authored-by: houseme <houseme@outlook.com>
2021-09-08 11:03:23 +08:00

62 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package content
import (
"fmt"
"github.com/silenceper/wechat/v2/miniprogram/context"
"github.com/silenceper/wechat/v2/util"
)
const (
checkTextURL = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=%s"
checkImageURL = "https://api.weixin.qq.com/wxa/img_sec_check?access_token=%s"
)
// Content 内容安全
type Content struct {
*context.Context
}
// NewContent 内容安全接口
func NewContent(ctx *context.Context) *Content {
return &Content{ctx}
}
// CheckText 检测文字
// @text 需要检测的文字
func (content *Content) CheckText(text string) error {
accessToken, err := content.GetAccessToken()
if err != nil {
return err
}
response, err := util.PostJSON(
fmt.Sprintf(checkTextURL, accessToken),
map[string]string{
"content": text,
},
)
if err != nil {
return err
}
return util.DecodeWithCommonError(response, "ContentCheckText")
}
// CheckImage 检测图片
// 所传参数为要检测的图片文件的绝对路径图片格式支持PNG、JPEG、JPG、GIF, 像素不超过 750 x 1334同时文件大小以不超过 300K 为宜,否则可能报错
// @media 图片文件的绝对路径
func (content *Content) CheckImage(media string) error {
accessToken, err := content.GetAccessToken()
if err != nil {
return err
}
response, err := util.PostFile(
"media",
media,
fmt.Sprintf(checkImageURL, accessToken),
)
if err != nil {
return err
}
return util.DecodeWithCommonError(response, "ContentCheckImage")
}