zyx 2 년 전
부모
커밋
21438471fa
1개의 변경된 파일21개의 추가작업 그리고 12개의 파일을 삭제
  1. 21 12
      src/main/java/com/sxtvs/open/api/youmei/service/YoumeiAccountServiceImpl.java

+ 21 - 12
src/main/java/com/sxtvs/open/api/youmei/service/YoumeiAccountServiceImpl.java

@@ -12,6 +12,7 @@ import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.hc.client5.http.classic.methods.HttpPost;
 import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
+import org.apache.hc.client5.http.fluent.Request;
 import org.apache.hc.client5.http.impl.classic.BasicHttpClientResponseHandler;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
@@ -20,6 +21,8 @@ import org.apache.hc.core5.http.message.BasicNameValuePair;
 import org.apache.http.Consts;
 import org.springframework.stereotype.Service;
 
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -83,7 +86,6 @@ public class YoumeiAccountServiceImpl extends ServiceImpl<YoumeiAccountMapper, Y
             .build();
 
 
-
     public String getWbjcTokenCache() {
         return tokenCache.get("sxgdwbjc", this::getWbjcToken);
     }
@@ -94,19 +96,16 @@ public class YoumeiAccountServiceImpl extends ServiceImpl<YoumeiAccountMapper, Y
                 .one().getAccessToken();
     }
 
-    private final CloseableHttpClient client = HttpClients.createDefault();
-
     @SneakyThrows
     public Object wordCheck(String text) {
-        List<NameValuePair> formparams = new ArrayList<>();
-        formparams.add(new BasicNameValuePair("accessToken", getWbjcTokenCache()));
-        formparams.add(new BasicNameValuePair("text", text));
-        @Cleanup
-        UrlEncodedFormEntity params = new UrlEncodedFormEntity(formparams, Consts.UTF_8);
-
-        var httpPost = new HttpPost("https://api-open-wx-www.yqt365.com/dataapp/api/umei/fw/open/wbjc/article_correct_external");
-        httpPost.setEntity(params);
-        var body = client.execute(httpPost,new BasicHttpClientResponseHandler());
+
+        var body = Request.post("https://api-open-wx-www.yqt365.com/dataapp/api/umei/fw/open/wbjc/article_correct_external")
+                .bodyForm(List.of(new BasicNameValuePair("accessToken", getWbjcTokenCache()),
+                        new BasicNameValuePair("text", text)), StandardCharsets.UTF_8)
+                .execute()
+                .returnContent()
+                .asString();
+
         CheckWordResponse checkWordDto = objectMapper.readValue(body, CheckWordResponse.class);
         CheckWordResponse.DataDTO data = checkWordDto.getData();
 
@@ -161,4 +160,14 @@ public class YoumeiAccountServiceImpl extends ServiceImpl<YoumeiAccountMapper, Y
         return cache.get(text, this::wordCheck);
     }
 
+    public static void main(String[] args) throws IOException {
+        var s = Request.post("https://api-open-wx-www.yqt365.com/dataapp/api/umei/fw/open/wbjc/article_correct_external")
+                .bodyForm(List.of(new BasicNameValuePair("accessToken", "0378a08aac3b4ed69f68bb367ad22d4e"),
+                        new BasicNameValuePair("text", "傻逼")), StandardCharsets.UTF_8)
+                .execute()
+                .returnContent()
+                .asString();
+        System.out.println(s);
+    }
+
 }