package util

import (
	"bytes"
	"dsbqj-admin/pkg/logger"
	"github.com/goccy/go-json"
	"io/ioutil"
	"net/http"
)

func CheckWords(w string) (string, bool) {
	data := map[string]string{}
	data["content"] = w

	sendbuf, _ := json.Marshal(data)

	resp, err := http.Post("http://47.110.50.126:5928/sensitive/check", "application/json", bytes.NewReader(sendbuf))
	if err != nil {
		logger.Error("CheckWords com httppostjson err!err:", err.Error())
		return w, false
	}

	buf, err1 := ioutil.ReadAll(resp.Body)
	if err1 != nil {
		logger.Error("CheckWords read body err!err", err1.Error())
		return w, false
	}

	var result map[string]interface{}
	err = json.Unmarshal(buf, &result)
	if err != nil {
		logger.Info("%s", err.Error())
	}
	logger.Info("check user name result:===?> %v", result)
	return w, result["data"].(bool)
}
