AI绘画

AI 绘画 智能文生图-API 文档-文档中心-腾讯云

使用HTTP请求直接调用

然后,在你的Controller类中,你可以使用Spring的RestTemplate类来发送HTTP请求。以下是一个简单的示例:

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class PaintController {
    @PostMapping("/api/paint/create")
    public ResponseEntity createPainting(@RequestBody String inputText) {
        RestTemplate restTemplate = new RestTemplate();
        String apiUrl = "https://aiart.tencentcloudapi.com/";
        HttpHeaders headers = new HttpHeaders();
        headers.set("Content-Type", "application/json");
        HttpEntity entity = new HttpEntity<>(inputText, headers);
        ResponseEntity response = restTemplate.exchange(apiUrl, HttpMethod.POST, entity, String.class);
        return ResponseEntity.ok(response.getBody());
    }
}

在上面的示例中,我们使用类RestTemplate发送POST请求到腾讯云API URL,并将请求体和头部信息设置好。然后,我们处理返回的响应,并将结果返回给调用者。

你可能感兴趣的:(AI绘画)