InboxUserProxyService.java
2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.yohoufo.inboxclient.sdk;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohoufo.common.ApiResponse;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* Created by chenchao on 2018/9/18.
*/
@Service
public class InboxUserProxyService {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
ServiceCaller serviceCaller;
@Value("${erp-gateway.url}")
private String erpGatewayUrl;
@Value("${uic.url:http://uic.yohoops.org/uic}")
private String uicUrl;
/**
* http://java-yoho-uic.test3.ingress.dev.yohocorp.com/uic
* //profile/getProfile?uid=600032978
* @param uid
* @return
*/
public static final String PRFILE_API = "/profile/getProfile";
public String getMobile(int uid){
String url = uicUrl + PRFILE_API;
Map<String,Object> params = Maps.newHashMap();
params.put("uid", uid);
logger.info("InboxUserProxyService in getMobile enter, uid {}", uid);
ApiResponse userInfo ;
try {
userInfo = serviceCaller.get("users.getAddress", url, params,
ApiResponse.class, null).get(500, TimeUnit.MILLISECONDS);
}catch (Exception ex){
logger.warn("InboxUserProxyService in getMobile fail, uid {}", uid, ex);
throw new ServiceException(ServiceError.USER_IS_NOT_EXIST);
}
JSONObject jsonObject;
String mobile;
if (userInfo == null || (jsonObject = (JSONObject)userInfo.getData()) == null
|| StringUtils.isBlank(mobile = jsonObject.getString("mobile_phone"))){
logger.warn("InboxUserProxyService in getMobile fail, uid {}, userInfo {}", uid, userInfo);
throw new ServiceException(ServiceError.PROFILE_IS_NULL);
}
return mobile;
}
}