package org.jeecg.modules.spyderUtils.spider;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import kong.unirest.HttpResponse;
import kong.unirest.JsonNode;
import kong.unirest.Unirest;
import org.jeecg.modules.demo.pagecontentcapture.entity.JsResult;
import org.springframework.stereotype.Component;

import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

@Component
public class FangCunUtils {
    public JsResult getJsResult(String text) {
        //错敏词校验-----开始
        Integer[] IntStr = {1000,1001,1002,1004,2000,2001,3000,3001,4000,5000,7001,7002};
        Object oIntStr = JSONArray.toJSON(IntStr);
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("userid", "quyanhong");
        paramMap.put("ukey", "K103fhnBhXak");
        paramMap.put("text", URLEncoder.encode( text));
        paramMap.put("error_types",oIntStr);
        paramMap.put("threshold",0.2);
        paramMap.put("strict_degree","v");
        paramMap.put("domains","test");
        HttpResponse<JsonNode> response = Unirest.post("http://api.ifuncun.cn:8081/v1/proofreadHtml")
                .header("Content-Type", "application/json")
                .body( JSONObject.toJSONString(paramMap))
                .asJson();
        String string = response.getBody().toString();
        JsResult jsonObject = JSONObject.parseObject(string, JsResult.class);
        System.out.println("======================================="+jsonObject);
        return jsonObject;
    }
}
