TestUtil.java 3.14 KB
package com.glsk.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

public class TestUtil {
    public static void main(String[] args) throws Exception {
        // 1. 准备主题数组(与之前生成的数组一致)
        String[] topicCombinations = {
                "安利卖点,操作倾向",
                "市场涨跌,网感词语",
                "基金净值,市场涨跌,操作倾向",
                "安利卖点,网感词语,基金净值",
                "操作倾向,市场涨跌,安利卖点,网感词语",
                "基金净值,安利卖点,操作倾向,市场涨跌",
                "网感词语,基金净值,市场涨跌,操作倾向,安利卖点",
                "市场涨跌,操作倾向,网感词语,基金净值",
                "安利卖点,基金净值",
                "操作倾向,网感词语",
                "基金净值,操作倾向,安利卖点",
                "网感词语,市场涨跌,基金净值",
                "安利卖点,市场涨跌,操作倾向,网感词语",
                "基金净值,网感词语,操作倾向,市场涨跌",
                "市场涨跌,基金净值,安利卖点,操作倾向,网感词语",
                "操作倾向,安利卖点",
                "网感词语,安利卖点,市场涨跌",
                "基金净值,市场涨跌",
                "操作倾向,基金净值,网感词语,安利卖点",
                "安利卖点,操作倾向,基金净值,市场涨跌,网感词语"
        };

        String postDate = "2025-11-19";

        // 2. 创建HttpClient
        CloseableHttpClient httpClient = HttpClients.createDefault();

        try {
            // 3. 构建请求

            String baseUrl = "http://localhost:8090/api/ai/common/post_merge_summary";


            for (String theme : topicCombinations) {

                String url = baseUrl + "?post_date=" + URLEncoder.encode(postDate, StandardCharsets.UTF_8.name())
                        + "&themes=" + theme;
                // 6. 创建POST请求(参数在URL中)
                HttpPost request = new HttpPost(url);
                request.setHeader("Content-Type", "application/json; charset=UTF-8");

                // 7. 执行请求
                try (CloseableHttpResponse response = httpClient.execute(request)) {
                    // 8. 处理响应
                    int statusCode = response.getStatusLine().getStatusCode();
                    String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);

                    System.out.println("Status: " + statusCode);
                    System.out.println("Response: " + responseBody);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        httpClient.close();
    }
}