-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 增加小程序内容安全接口 * 内容安全接口 按照golint规范进行优化 * 内容安全接口 按照golint规范进行优化 * 删除CheckImage中的输出代码 * 小程序内容安全接口 * 小程序内容安全接口 * 小程序内容安全接口 1:修改返回值 改为error异常统一返回 Co-authored-by: root <[email protected]>
- Loading branch information
Showing
3 changed files
with
69 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,5 @@ _testmain.go | |
.vscode/ | ||
vendor | ||
.idea/ | ||
example/* | ||
example/* | ||
/test |
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,61 @@ | ||
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") | ||
} |
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