package com.slodon.b2b2c.investment.model;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.slodon.b2b2c.core.util.HttpClientUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;


/**
 * @author sunshihao
 * @version 1.0
 * @description: 消费业务
 * @date 2025/8/19 16:30
 */
@Component
@Slf4j
public class WordPressModel {
    public String getPostById(int id, String url) throws Exception {

        String path = url+"/wp-json/wp/v2/posts/"+id;
        String response = HttpClientUtil.httpGet(path,null);
        if (response == null) {
            throw new Exception("wordpress api 响应结果为空");
        }
        JSONObject postObject = JSONUtil.parseObj(response);
        String content = postObject.getByPath("content.rendered", String.class);
        if (content == null) {
            throw new Exception("查询文章内容失败：content.rendered字段为空");
        }
        return content;
    }
}
