ZhaoonlineBiz.java
2.36 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.cjs.site.biz.pub;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.cjs.site.biz.ServiceException;
import com.cjs.site.util.lang.StringUtil;
import com.cjs.site.util.net.RestClient;
/**
* 赵涌在线相关
*
* @author tongyufu
*
*/
@Service
public class ZhaoonlineBiz {
private Logger log = LogManager.getLogger();
@Autowired
private RestClient restClient;
@Value("${env}")
private String environment;
/**
* 检查赵涌在线账号是否存在
*
* @param userId 赵涌在线用户ID
* @return
* 1. 客户存在:
{"result":"01","message":"ok","data":true}<br/>
2. 客户不存在:
{"result":"01","message":"ok","data":false}<br/>
3. identity 参数格式不正确
{"result":"02","message":"请求参数格式错误","data":null}
*/
@SuppressWarnings("unchecked")
public Map<String, Object> checkZhaoonlineId(String userId) {
if (!"prod".equals(environment)) {
return new HashMap<String, Object>();
}
if (StringUtil.isBlank(userId)) {
throw new ServiceException("请输入赵涌在线账号");
}
if (!NumberUtils.isDigits(userId)) {
throw new ServiceException("赵涌在线账号应为7位数字用户ID或11位手机号码");
}
if (userId.length() < 7 || userId.length() > 11) {
throw new ServiceException("赵涌在线账号应为7位数字用户ID或11位手机号码");
}
String uri = "https://appservices.zhaoonline.com";
uri += "/api/user/" + userId + "/exist";
Map<String, Object> response = restClient.getForObject(uri, Map.class);
log.info("检查赵涌在线账号是否存在[" + userId + "]:" + response);
if ("02".equals(response.get("result"))) {
throw new ServiceException((String) response.get("message"));
}
if (!(Boolean) response.get("data")) {
throw new ServiceException("赵涌在线账号不存在");
}
return response;
}
}