package com.agri.api.controller;

import com.agri.api.util.HttpJsonUtil;
import com.agri.generator.dto.ApiConfigDTO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.validation.Valid;

public class TestController {


    /**
     * 测试调用三方接口
     */
    @PostMapping("/test-third-api")
    public String testThirdApi(@Valid @RequestBody ApiConfigDTO apiConfig) {
        try {
            // 调用三方GET接口示例
            // String result = HttpJsonUtil.doGet("http://third-party-api.com/api/test?name=test", String.class);

            // 调用三方POST JSON接口示例
            String result = HttpJsonUtil.doPostJson(
                    "https://api.wl1688.net/iotc/getway",
                    apiConfig,
                    String.class
            );
            return "调用三方接口成功，响应：" + result;
        } catch (Exception e) {
            return "调用三方接口失败：" + e.getMessage();
        }
    }
}
