parent
d37579aa39
commit
2faa608070
@ -0,0 +1,13 @@
|
|||||||
|
package com.luoo.user.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class RestTemplateConfig {
|
||||||
|
@Bean
|
||||||
|
RestTemplate restTemplate() {
|
||||||
|
return new RestTemplate();
|
||||||
|
}
|
||||||
|
}
|
@ -1,17 +1,67 @@
|
|||||||
package com.luoo.user.service;
|
package com.luoo.user.service;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.luoo.user.dao.FeedbackDao;
|
import com.luoo.user.dao.FeedbackDao;
|
||||||
import com.luoo.user.pojo.Feedback;
|
import com.luoo.user.pojo.Feedback;
|
||||||
|
import com.luoo.user.util.EmojiConverterUtil;
|
||||||
|
|
||||||
|
import constants.Constants;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class FeedbackService {
|
public class FeedbackService {
|
||||||
|
private static final String[] EMPTY_IMAGE_ARRAY = new String[] {};
|
||||||
|
private static final String FEI_SHU_URL = "https://open.feishu.cn/open-apis/bot/v2/hook/84316603-355a-4dea-bb86-65f4b8919431";
|
||||||
@Autowired
|
@Autowired
|
||||||
private FeedbackDao feedbackDao;
|
private FeedbackDao feedbackDao;
|
||||||
|
@Autowired
|
||||||
|
private RestTemplate restTemplate;
|
||||||
|
|
||||||
|
@Async
|
||||||
|
public void send(Feedback feedback) {
|
||||||
|
feedbackDao.save(feedback);
|
||||||
|
seedToFeishu(feedback);
|
||||||
|
}
|
||||||
|
|
||||||
public void save(Feedback appFeedback) {
|
private void seedToFeishu(Feedback feedback) {
|
||||||
feedbackDao.save(appFeedback);
|
String images = feedback.getImages();
|
||||||
|
String[] imagesArray = null == images ? EMPTY_IMAGE_ARRAY : images.split(",");
|
||||||
|
String robotImage = "";
|
||||||
|
for (String image : imagesArray) {
|
||||||
|
robotImage = robotImage + Constants.RESOURCE_PREFIX + "user/feedback/" + image + "\r\n";
|
||||||
|
}
|
||||||
|
Map<String, Object> robot = new HashMap<>();
|
||||||
|
Map<String, String> contentMap = new HashMap<>();
|
||||||
|
contentMap.put("text", "反馈内容:" + EmojiConverterUtil.decode(feedback.getContent()) + "\r\n反馈人:"
|
||||||
|
+ EmojiConverterUtil.decode(feedback.getNickName()) + "\r\n附件:" + robotImage);
|
||||||
|
robot.put("msg_type", "text");
|
||||||
|
robot.put("content", contentMap);
|
||||||
|
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("msg_type", "text");
|
||||||
|
jsonObject.put("content", contentMap);
|
||||||
|
HttpEntity<String> requestEntity = new HttpEntity<>(jsonObject.toString(), httpHeaders);
|
||||||
|
List<HttpMessageConverter<?>> list = restTemplate.getMessageConverters();
|
||||||
|
for (HttpMessageConverter<?> converter : list) {
|
||||||
|
if (converter instanceof StringHttpMessageConverter) {
|
||||||
|
((StringHttpMessageConverter) converter).setDefaultCharset(Charset.forName("UTF-8"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
restTemplate.postForEntity(FEI_SHU_URL, requestEntity, Map.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue