package com.example.unusualsounds.common.utils; import jakarta.annotation.Resource; import lombok.extern.java.Log; import org.hibernate.validator.constraints.Length; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.*; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import java.io.IOException; import java.util.Map; /** * 音频算法分析类 */ @Log @Component public final class VoiceAnalysisUtils { private static RestTemplate restTemplateStatic; @Autowired public void setRestTemplate(RestTemplate restTemplate) { VoiceAnalysisUtils.restTemplateStatic = restTemplate; } public static String postVoxAnalysis(Map maps,String postAnalysisUrl){ HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.APPLICATION_JSON); HttpEntity> mapHttpEntity = new HttpEntity<>(maps, httpHeaders); try { ResponseEntity stringResponseEntity = restTemplateStatic.postForEntity(postAnalysisUrl, mapHttpEntity, String.class); if (stringResponseEntity.getStatusCode() == HttpStatus.OK){ return "通知算法成功"; } return "通知算法失败"; }catch (Exception e){ return "发送失败:"+e.getMessage(); } } }