|
@@ -6,6 +6,9 @@ import (
|
|
|
"github.com/beego/beego/v2/client/orm"
|
|
|
"github.com/rdlucklib/rdluck_tools/http"
|
|
|
"hongze/hongze_cygx/utils"
|
|
|
+ "io/ioutil"
|
|
|
+ netHttp "net/http"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
@@ -194,9 +197,10 @@ func WxUsersGet() (openIdStr string) {
|
|
|
}
|
|
|
|
|
|
type WxCheckContentJson struct {
|
|
|
- Detail []WxCheckContentJsonDetail `json:"detail"`
|
|
|
- Errcode int `json:"errcode"`
|
|
|
- Errmsg string `json:"errmsg"`
|
|
|
+ Detail []WxCheckContentJsonDetail `json:"detail"`
|
|
|
+ Errcode int `json:"errcode"`
|
|
|
+ Errmsg string `json:"errmsg"`
|
|
|
+ Result WxCheckContentJsonResult `json:"result"`
|
|
|
}
|
|
|
|
|
|
type WxCheckContentJsonDetail struct {
|
|
@@ -206,33 +210,51 @@ type WxCheckContentJsonDetail struct {
|
|
|
Strategy string
|
|
|
Errcode int
|
|
|
}
|
|
|
+type WxCheckContentJsonResult struct {
|
|
|
+ Suggest string
|
|
|
+ Label int
|
|
|
+}
|
|
|
|
|
|
-func WxCheckContent(content string) (errCode int, keyWord string) {
|
|
|
- accessToken, err := GetWxAccessToken()
|
|
|
+func WxCheckContent(token, openId, content string) (suggest string) {
|
|
|
+ url := "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=" + token
|
|
|
+ fmt.Println(url)
|
|
|
+ //result, err := http.Post(url, content)
|
|
|
+ //if err != nil {
|
|
|
+ // utils.FileLog.Info("GetUser Err:", err.Error())
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ method := "POST"
|
|
|
+ payload := strings.NewReader(`{
|
|
|
+ "openid":"` + openId + `",
|
|
|
+ "scene":` + strconv.Itoa(2) + `,
|
|
|
+ "version":` + strconv.Itoa(2) + `,
|
|
|
+ "content":"` + content + `"
|
|
|
+ }`)
|
|
|
+ client := &netHttp.Client{}
|
|
|
+ req, err := netHttp.NewRequest(method, url, payload)
|
|
|
if err != nil {
|
|
|
- utils.FileLog.Info("GetWxAccessToken Err:%s", err.Error())
|
|
|
return
|
|
|
}
|
|
|
- url := "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=" + accessToken
|
|
|
- fmt.Println(url)
|
|
|
- result, err := http.Post(url, content)
|
|
|
+ req.Header.Add("Content-Type", "application/json")
|
|
|
+ postBody, err := client.Do(req)
|
|
|
if err != nil {
|
|
|
- utils.FileLog.Info("GetUser Err:", err.Error())
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+ defer postBody.Body.Close()
|
|
|
+ body, err := ioutil.ReadAll(postBody.Body)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ utils.FileLog.Info(err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
item := new(WxCheckContentJson)
|
|
|
- err = json.Unmarshal(result, &item)
|
|
|
+ err = json.Unmarshal(body, &item)
|
|
|
if err != nil {
|
|
|
fmt.Println("Unmarshal Err:", err.Error())
|
|
|
return
|
|
|
}
|
|
|
- if len(item.Detail) > 0{
|
|
|
- for _, v := range item.Detail {
|
|
|
- keyWord += v.KeyWord+","
|
|
|
- }
|
|
|
- }
|
|
|
- keyWord = strings.TrimRight(keyWord, ",")
|
|
|
- fmt.Println(result)
|
|
|
+ fmt.Println(item.Result.Label)
|
|
|
+ fmt.Println(item.Result.Suggest)
|
|
|
+ suggest = item.Result.Suggest
|
|
|
return
|
|
|
}
|