|
@ -187,9 +187,10 @@ public class WxUserServiceImpl extends ServiceImpl<WxUserMapper, WxUser> impleme |
|
|
WxCpDefaultConfigImpl config =new WxCpDefaultConfigImpl(); |
|
|
WxCpDefaultConfigImpl config =new WxCpDefaultConfigImpl(); |
|
|
config.setAgentId(agentId); |
|
|
config.setAgentId(agentId); |
|
|
config.setCorpSecret(WxCpConfig.getSecret(agentId)); |
|
|
config.setCorpSecret(WxCpConfig.getSecret(agentId)); |
|
|
|
|
|
config.setOauth2redirectUri(""); |
|
|
config.setCorpId(wxApp.getId()); |
|
|
config.setCorpId(wxApp.getId()); |
|
|
wxCpService.setWxCpConfigStorage(config); |
|
|
wxCpService.setWxCpConfigStorage(config); |
|
|
|
|
|
log.debug("企业微信登录:appid:{} agId:{} code:{}",appId,agentId,code); |
|
|
// 授权方式登录
|
|
|
// 授权方式登录
|
|
|
WxCpOAuth2Service oauth2Service = wxCpService.getOauth2Service(); |
|
|
WxCpOAuth2Service oauth2Service = wxCpService.getOauth2Service(); |
|
|
WxCpOauth2UserInfo cpOauth2UserInfo = null; |
|
|
WxCpOauth2UserInfo cpOauth2UserInfo = null; |
|
@ -197,20 +198,40 @@ public class WxUserServiceImpl extends ServiceImpl<WxUserMapper, WxUser> impleme |
|
|
// 获取敏感信息
|
|
|
// 获取敏感信息
|
|
|
WxCpUserDetail wxCpUserDetail = null; |
|
|
WxCpUserDetail wxCpUserDetail = null; |
|
|
WxCpUser wxCpUser = null; |
|
|
WxCpUser wxCpUser = null; |
|
|
|
|
|
String userId = null; |
|
|
try { |
|
|
try { |
|
|
cpOauth2UserInfo = oauth2Service.getUserInfo(agentId,code); |
|
|
cpOauth2UserInfo = oauth2Service.getUserInfo(agentId,code); |
|
|
// 基础用户信息
|
|
|
log.debug("cpOauth2UserInfo=>{}", JsonUtil.objectToJson(cpOauth2UserInfo)); |
|
|
WxCpUserService wxCpUserService = wxCpService.getUserService(); |
|
|
if(wxLoginUser.getCodeType()!=null && wxLoginUser.getCodeType().equals(1)){ |
|
|
wxCpUser = wxCpUserService.getById(cpOauth2UserInfo.getUserId()); |
|
|
// web扫码登录方式
|
|
|
// 获取敏感信息
|
|
|
userId = cpOauth2UserInfo.getUserId(); |
|
|
wxCpUserDetail = oauth2Service.getUserDetail(cpOauth2UserInfo.getUserTicket()); |
|
|
WxCpUserService cpUserService = wxCpService.getUserService(); |
|
|
|
|
|
if(cpUserService==null){ |
|
|
|
|
|
Assert.throwEx("cpUserService is null"); |
|
|
|
|
|
} |
|
|
|
|
|
wxCpUser = cpUserService.getById(userId); |
|
|
|
|
|
if(wxCpUser==null){ |
|
|
|
|
|
Assert.throwEx("wxCpUser is null"); |
|
|
|
|
|
} |
|
|
|
|
|
}else { |
|
|
|
|
|
// 默认授权方式
|
|
|
|
|
|
// 基础用户信息
|
|
|
|
|
|
WxCpUserService wxCpUserService = wxCpService.getUserService(); |
|
|
|
|
|
wxCpUser = wxCpUserService.getById(cpOauth2UserInfo.getUserId()); |
|
|
|
|
|
// 获取敏感信息
|
|
|
|
|
|
wxCpUserDetail = oauth2Service.getUserDetail(cpOauth2UserInfo.getUserTicket()); |
|
|
|
|
|
if(wxCpUser==null){ |
|
|
|
|
|
Assert.throwEx("企业微信登录失败 002 :wxCpUser is null"); |
|
|
|
|
|
} |
|
|
|
|
|
userId = wxCpUserDetail.getUserId(); |
|
|
|
|
|
} |
|
|
} catch (WxErrorException e) { |
|
|
} catch (WxErrorException e) { |
|
|
log.error("企业微信登录失败:{}",e.getMessage()); |
|
|
log.error("企业微信登录失败:{}",e.getMessage()); |
|
|
} |
|
|
} |
|
|
if(wxCpUserDetail==null||wxCpUser==null){ |
|
|
if (userId==null){ |
|
|
Assert.throwEx("企业微信登录失败"); |
|
|
Assert.throwEx("企业微信登录失败 001 :userId is null"); |
|
|
} |
|
|
} |
|
|
String userId = wxCpUserDetail.getUserId(); |
|
|
|
|
|
wxUser = this.getByOpenId(appId,userId); |
|
|
wxUser = this.getByOpenId(appId,userId); |
|
|
if(wxUser == null){ |
|
|
if(wxUser == null){ |
|
|
wxUser = new WxUser(); |
|
|
wxUser = new WxUser(); |
|
@ -220,7 +241,7 @@ public class WxUserServiceImpl extends ServiceImpl<WxUserMapper, WxUser> impleme |
|
|
wxUser.setEmpName(wxCpUser.getName()); |
|
|
wxUser.setEmpName(wxCpUser.getName()); |
|
|
wxUser.setUnionId(userId); |
|
|
wxUser.setUnionId(userId); |
|
|
wxUser.setOpenId(userId); |
|
|
wxUser.setOpenId(userId); |
|
|
wxUser.setHeadimgUrl(wxCpUserDetail.getAvatar()); |
|
|
//wxUser.setHeadimgUrl(wxCpUserDetail.getAvatar());
|
|
|
} |
|
|
} |
|
|
//通过手机号绑定员工号
|
|
|
//通过手机号绑定员工号
|
|
|
//if(StringUtils.hasText(wxCpUser.getMobile())){
|
|
|
//if(StringUtils.hasText(wxCpUser.getMobile())){
|
|
|