You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.2 KiB

package aliyun
// @Title 文本检测
import (
"encoding/json"
"net/url"
)
const (
actionTextUrl = "http://monitoring.market.alicloudapi.com/neirongjiance"
)
type text struct {
}
var (
Text = &text{}
)
type textResult struct {
Success bool `json:"success"`
Status int `json:"status"`
Data struct {
Out []CheckText `json:"out"`
} `json:"data"`
}
type CheckText struct {
Politics []string `json:"政治敏感监测"`
Contraband []string `json:"违禁品监测"`
Irrigation []bool `json:"恶意灌水监测"`
Salacity []string `json:"色情监测"`
Abuse []string `json:"辱骂监测"`
}
// @Title 敏感词检测
func (o *text) CheckText(text string) (result CheckText, err error) {
data := url.Values{
"in": []string{text},
}
resByte, err := o.exec(actionTextUrl, data.Encode())
if err != nil {
return
}
res := textResult{}
err = json.Unmarshal(resByte, &res)
if err != nil {
return
}
if len(res.Data.Out) > 0 {
result = res.Data.Out[0]
}
return
}
// @Title 执行请求
func (o *text) exec(action, data string) ([]byte, error) {
return request("POST", action, data, map[string]string{
"Authorization": "APPCODE " + appCode,
"Content-Type": "application/x-www-form-urlencoded",
})
}