|
@@ -24,13 +24,15 @@ import com.zanxiang.module.util.bean.BeanUtil;
|
|
|
import com.zanxiang.module.util.exception.BaseException;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.http.HttpEntity;
|
|
|
-import org.springframework.http.HttpHeaders;
|
|
|
-import org.springframework.http.HttpMethod;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.core.io.Resource;
|
|
|
+import org.springframework.http.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.springframework.web.util.UriComponentsBuilder;
|
|
|
|
|
|
+import java.net.URI;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -58,6 +60,50 @@ public class KfMsgContentServiceImpl extends ServiceImpl<KfMsgContentMapper, KfM
|
|
|
@Autowired
|
|
|
private IGameAppletService gameAppletService;
|
|
|
|
|
|
+ @Override
|
|
|
+ public String uploadMsg(KfApiParam param, MultipartFile files) {
|
|
|
+ log.error("发送图片消息参数, param : {}", JsonUtil.toString(param));
|
|
|
+ //查询用户授权信息
|
|
|
+ KfUser kfUser = kfUserService.getKfUser(SecurityUtil.getUserId(), param.getAppId());
|
|
|
+ //图片上传腾讯
|
|
|
+ String uploadResult = this.imgUploadApi(kfUser, files);
|
|
|
+ //发送客服消息
|
|
|
+ Map<String, Object> paramMap = param.getParam();
|
|
|
+ paramMap.put("msg_content", uploadResult);
|
|
|
+ //腾讯api
|
|
|
+ return this.commKfApi(kfUser, param.getAction().getValue(), KfApiEnum.getApiUrl(param.getAction()), paramMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String imgUploadApi(KfUser kfUser, MultipartFile files) {
|
|
|
+ //请求地址
|
|
|
+ URI uri = UriComponentsBuilder.fromHttpUrl(KfApiEnum.UPLOAD_MSG.getApiUrl())
|
|
|
+ .queryParam("action", KfActionEnum.UPLOAD_PIC_MSG.getValue())
|
|
|
+ .queryParam("token", kfUser.getToken())
|
|
|
+ .queryParam("lang", "zh_CN")
|
|
|
+ .build().toUri();
|
|
|
+ //最外层请求头
|
|
|
+ HttpHeaders httpHeaders = new HttpHeaders();
|
|
|
+ httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
|
|
|
+ httpHeaders.add("cookie", kfUser.getCookie());
|
|
|
+ LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
|
|
|
+ //文件内容请求头
|
|
|
+ HttpHeaders formHeader = new HttpHeaders();
|
|
|
+ formHeader.setContentType(MediaType.MULTIPART_FORM_DATA);
|
|
|
+ formHeader.setContentDispositionFormData("image", files.getOriginalFilename());
|
|
|
+ HttpEntity<Resource> formEntity = new HttpEntity<>(files.getResource(), formHeader);
|
|
|
+ map.add("image", formEntity);
|
|
|
+ //http请求头
|
|
|
+ HttpEntity<LinkedMultiValueMap<String, Object>> httpEntity = new HttpEntity<>(map, httpHeaders);
|
|
|
+ Object result;
|
|
|
+ try {
|
|
|
+ result = restTemplate.postForObject(uri, httpEntity, Object.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("腾讯上传图片接口调用异常, uri : {}, e : {}", uri, e.getMessage());
|
|
|
+ throw new BaseException("腾讯上传图片接口调用异常!");
|
|
|
+ }
|
|
|
+ return JsonUtil.toString(result);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<KfGameVO> getKfGameList() {
|
|
|
List<GameAuth> gameAuthList = gameAuthService.list(new LambdaQueryWrapper<GameAuth>()
|
|
@@ -95,7 +141,6 @@ public class KfMsgContentServiceImpl extends ServiceImpl<KfMsgContentMapper, KfM
|
|
|
|
|
|
@Override
|
|
|
public String kfApi(KfApiParam param) {
|
|
|
- log.error("请求参数, param : {}", JsonUtil.toString(param));
|
|
|
//查询用户授权信息
|
|
|
KfUser kfUser = kfUserService.getKfUser(SecurityUtil.getUserId(), param.getAppId());
|
|
|
//请求调用腾讯接口
|
|
@@ -114,7 +159,7 @@ public class KfMsgContentServiceImpl extends ServiceImpl<KfMsgContentMapper, KfM
|
|
|
responseEntity = restTemplate.exchange(URIUtil.fillUrlParams(url, pathParam, Boolean.FALSE),
|
|
|
HttpMethod.POST, new HttpEntity<>(param, headers), String.class);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("腾讯接口调用异常, e : {}", e.getMessage());
|
|
|
+ log.error("腾讯接口调用异常, url : {}, param : {}, e : {}", url, param, e.getMessage());
|
|
|
throw new BaseException("腾讯接口调用异常!");
|
|
|
}
|
|
|
return responseEntity.getBody();
|