Commit 48409765 4840976550912462155787223e7e576a04751cf9 by xianghan

1.优化

1 parent 5ffa9270
...@@ -21,6 +21,7 @@ import com.topdraw.config.RedisKeyUtil; ...@@ -21,6 +21,7 @@ import com.topdraw.config.RedisKeyUtil;
21 import com.topdraw.exception.BadRequestException; 21 import com.topdraw.exception.BadRequestException;
22 import com.topdraw.exception.EntityNotFoundException; 22 import com.topdraw.exception.EntityNotFoundException;
23 import com.topdraw.exception.GlobeExceptionMsg; 23 import com.topdraw.exception.GlobeExceptionMsg;
24 import com.topdraw.resttemplate.RestTemplateClient;
24 import com.topdraw.util.Base64Util; 25 import com.topdraw.util.Base64Util;
25 import com.topdraw.util.JSONUtil; 26 import com.topdraw.util.JSONUtil;
26 import com.topdraw.utils.RedisUtils; 27 import com.topdraw.utils.RedisUtils;
...@@ -266,7 +267,9 @@ public class UserOperationController { ...@@ -266,7 +267,9 @@ public class UserOperationController {
266 267
267 if (StringUtils.isNotBlank(headimgurl)) { 268 if (StringUtils.isNotBlank(headimgurl)) {
268 String headimgurlDecode = URLDecoder.decode(headimgurl, "UTF-8"); 269 String headimgurlDecode = URLDecoder.decode(headimgurl, "UTF-8");
269 memberDTO.setAvatarUrl(headimgurlDecode); 270 String imageEncode = Base64Util.encode(headimgurlDecode);
271 String image = RestTemplateClient.chooseImage(imageEncode, "image");
272 memberDTO.setAvatarUrl(StringUtils.isNotBlank(image) == true ? image:headimgurlDecode);
270 } 273 }
271 }catch (Exception e) { 274 }catch (Exception e) {
272 log.info("headimgurl , nickname ===>> encode error!"); 275 log.info("headimgurl , nickname ===>> encode error!");
......
1 package com.topdraw.resttemplate;
2
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject;
5 import com.topdraw.business.module.member.address.domain.MemberAddress;
6 import com.topdraw.business.module.member.domain.Member;
7 import com.topdraw.business.module.member.relatedinfo.domain.MemberRelatedInfo;
8 import lombok.Data;
9 import lombok.extern.slf4j.Slf4j;
10 import org.apache.commons.lang3.StringUtils;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.core.env.Environment;
13 import org.springframework.http.ResponseEntity;
14 import org.springframework.http.client.SimpleClientHttpRequestFactory;
15 import org.springframework.stereotype.Component;
16 import org.springframework.web.client.RestTemplate;
17
18 import javax.annotation.PostConstruct;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Objects;
22
23 @Slf4j
24 @Component
25 public class RestTemplateClient {
26
27 private static RestTemplate restTemplate;
28
29 private static String BASE_URL;
30
31 @Autowired
32 private Environment environment;
33
34 @PostConstruct
35 private void init() {
36 BASE_URL = environment.getProperty("api.uc-service");
37 SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
38 // 设置连接超时
39 factory.setConnectTimeout(5000);
40 // 设置读取超时
41 factory.setReadTimeout(3000);
42 restTemplate = new RestTemplate(factory);
43 }
44
45 public static String chooseImage(String base64Url, String entity) {
46 Image image = new Image(base64Url, entity);
47 String entityBody = "";
48 String url = BASE_URL + "/ucService/api/upload/chooseImage";
49 log.info("request uc : url is " + url + ", memberId is " + com.alibaba.fastjson.JSONObject.toJSONString(image));
50 ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, image, String.class);
51 if (responseEntity.getStatusCode().is2xxSuccessful()) {
52 entityBody = responseEntity.getBody();
53 JSONObject parseObject = JSON.parseObject(entityBody);
54 List<Object> resultSet = (List)parseObject.get("resultSet");
55 Object o = resultSet.get(0);
56 return Objects.nonNull(o)?o.toString():"";
57 }
58 return entityBody;
59 }
60
61 @Data
62 static class Image {
63
64 private String base64URL;
65 private String entity;
66
67 public Image(String base64Url, String entity){
68 this.base64URL = base64Url;
69 this.entity = entity;
70 }
71
72 }
73 }
...@@ -141,4 +141,5 @@ weixin: ...@@ -141,4 +141,5 @@ weixin:
141 qrCodeExpireSeconds: 300 141 qrCodeExpireSeconds: 300
142 env: dev 142 env: dev
143 143
144 144 api:
145 uc-service: https://inet.dev1.topmall.topdraw.cn
...\ No newline at end of file ...\ No newline at end of file
......