|
@@ -47,6 +47,8 @@ public class AuthRedirectController {
|
|
|
private String pcUrl;
|
|
|
@Value("${privateDeployURL.mobUrl}")
|
|
|
private String mobUrl;
|
|
|
+ @Value("${corpId}")
|
|
|
+ private String corpId;
|
|
|
|
|
|
@Resource
|
|
|
SysConfigMapper sysConfigMapper;
|
|
@@ -63,13 +65,14 @@ public class AuthRedirectController {
|
|
|
|
|
|
|
|
|
@RequestMapping("/corpWXAuth")
|
|
|
- public ModelAndView auth(String code, String state) {
|
|
|
+ public ModelAndView auth(String code, String state) throws Exception{
|
|
|
Map<String,Object> reqParam = new HashMap<String,Object>(16);
|
|
|
String userAgent = request.getHeader("User-Agent");
|
|
|
//获取设备类型
|
|
|
String deviceType = UserAgentUtils.getDeviceType(userAgent);
|
|
|
+ WxCorpInfo corpInfo = wxCorpInfoMapper.selectById(corpId);
|
|
|
boolean isMobile = "MOBILE".equals(deviceType);
|
|
|
- String url = WeiXinCorpController.GET_CORP_USERINFO_URL.replace("SUITE_ACCESS_TOKEN", getSuiteAccessToken()).replace("CODE", code);
|
|
|
+ String url = WeiXinCorpController.GET_CORP_INSIDE_USERINFO_URL.replace("ACCESS_TOKEN",getCorpConcactAccessToken(corpInfo)).replace("CODE", code);
|
|
|
String forObject = this.restTemplate.getForObject(url, String.class);
|
|
|
JSONObject obj = JSONObject.parseObject(forObject);
|
|
|
String wxUserId = obj.getString("UserId");
|
|
@@ -245,4 +248,23 @@ public class AuthRedirectController {
|
|
|
return WeiXinCorpController.SUITE_ACCESS_TOKEN;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ //获取企业通讯录的accessToken,在私有化部署的企业内部服务器上跑
|
|
|
+ private String getCorpConcactAccessToken(WxCorpInfo corpInfo) throws Exception {
|
|
|
+ String url = WeiXinCorpController.GET_CORP_TOKEN.replace("ID", corpInfo.getCorpid()).replace("SECRET", corpInfo.getContactSecret());
|
|
|
+ ResponseEntity<String> responseEntity = this.restTemplate.exchange(url,
|
|
|
+ HttpMethod.GET, null, String.class);
|
|
|
+ if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
+ String resp = responseEntity.getBody();
|
|
|
+ JSONObject json = JSONObject.parseObject(resp);
|
|
|
+ if (json.getIntValue("errcode") == 0) {
|
|
|
+ String access_token = json.getString("access_token");
|
|
|
+ corpInfo.setAccessToken(access_token);
|
|
|
+ } else {
|
|
|
+ throw new Exception(json.toJSONString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return corpInfo.getAccessToken();
|
|
|
+ }
|
|
|
+
|
|
|
}
|