提交 d5dcedbb 编写于 作者: 孙喜旺

Merge remote-tracking branch 'origin/back_end_dev' into back_end_dev

...@@ -131,6 +131,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -131,6 +131,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
//微信授权接口 //微信授权接口
.antMatchers("/weixin/auth/**").anonymous() .antMatchers("/weixin/auth/**").anonymous()
.antMatchers("/wecom/user/synchWeUser").anonymous()
// 除上面外的所有请求全部需要鉴权认证 // 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()
......
...@@ -13,7 +13,7 @@ import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor; ...@@ -13,7 +13,7 @@ import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor;
* @author: HaoN * @author: HaoN
* @create: 2020-08-26 14:33 * @create: 2020-08-26 14:33
**/ **/
@BaseRequest(interceptor = WeAccessTokenInterceptor.class) //@BaseRequest(interceptor = WeAccessTokenInterceptor.class)
public interface WeAccessTokenClient { public interface WeAccessTokenClient {
/** /**
* 获取token(常用token,联系人token) * 获取token(常用token,联系人token)
......
package com.linkwechat.wecom.client; package com.linkwechat.wecom.client;
import com.dtflys.forest.annotation.BaseRequest;
import com.dtflys.forest.annotation.DataObject; import com.dtflys.forest.annotation.DataObject;
import com.dtflys.forest.annotation.Header;
import com.dtflys.forest.annotation.Query; import com.dtflys.forest.annotation.Query;
import com.dtflys.forest.annotation.Request; import com.dtflys.forest.annotation.Request;
import com.linkwechat.wecom.domain.dto.WeAppDetailDto; import com.linkwechat.wecom.domain.dto.WeAppDetailDto;
import com.linkwechat.wecom.domain.dto.WeAppDto; import com.linkwechat.wecom.domain.dto.WeAppDto;
import com.linkwechat.wecom.domain.dto.WeResultDto; import com.linkwechat.wecom.domain.dto.WeResultDto;
import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor;
/** /**
* 应用管理相关接口 * 应用管理相关接口
*/ */
@BaseRequest(interceptor = WeAccessTokenInterceptor.class)
public interface WeAppClient { public interface WeAppClient {
/** /**
...@@ -35,6 +33,6 @@ public interface WeAppClient { ...@@ -35,6 +33,6 @@ public interface WeAppClient {
* @param weAppDetailDto * @param weAppDetailDto
* @return * @return
*/ */
@Request(url = "/agent/set") @Request(url = "/agent/set",type = "POST")
WeResultDto updateAgentById(@DataObject WeAppDetailDto weAppDetailDto); WeResultDto updateAgentById(@DataObject WeAppDetailDto weAppDetailDto,@Header("agentid")String agentid);
} }
package com.linkwechat.wecom.interceptor; package com.linkwechat.wecom.interceptor;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.dtflys.forest.exceptions.ForestRuntimeException; import com.dtflys.forest.exceptions.ForestRuntimeException;
import com.dtflys.forest.http.ForestRequest; import com.dtflys.forest.http.ForestRequest;
...@@ -58,7 +59,14 @@ public class WeAccessTokenInterceptor implements Interceptor{ ...@@ -58,7 +59,14 @@ public class WeAccessTokenInterceptor implements Interceptor{
}else if(Arrays.asList(weComeConfig.getNeedChatTokenUrl()).contains(uri)){ //需要会话存档token }else if(Arrays.asList(weComeConfig.getNeedChatTokenUrl()).contains(uri)){ //需要会话存档token
token=iWeAccessTokenService.findChatAccessToken(); token=iWeAccessTokenService.findChatAccessToken();
}else if(Arrays.asList(weComeConfig.getThirdAppUrl()).contains(uri)){ //第三方自建应用token }else if(Arrays.asList(weComeConfig.getThirdAppUrl()).contains(uri)){ //第三方自建应用token
token=iWeAccessTokenService.findThirdAppAccessToken(request.getHeaderValue(WeConstans.THIRD_APP_PARAM_TIP));
token=iWeAccessTokenService.findThirdAppAccessToken(
StrUtil.isEmpty(request.getHeaderValue(WeConstans.THIRD_APP_PARAM_TIP))?(String) request.getQuery(WeConstans.THIRD_APP_PARAM_TIP):request.getHeaderValue(WeConstans.THIRD_APP_PARAM_TIP)
);
} else{ } else{
token=iWeAccessTokenService.findCommonAccessToken(); token=iWeAccessTokenService.findCommonAccessToken();
} }
......
package com.linkwechat.wecom.service; package com.linkwechat.wecom.service;
import com.linkwechat.wecom.domain.WeApp;
/** /**
* @description: 微信token相关接口 * @description: 微信token相关接口
* @author: My * @author: My
...@@ -21,5 +23,7 @@ public interface IWeAccessTokenService { ...@@ -21,5 +23,7 @@ public interface IWeAccessTokenService {
public String findThirdAppAccessToken(String agentId); public String findThirdAppAccessToken(String agentId);
public void removeToken(); public void removeToken();
} }
\ No newline at end of file
...@@ -106,6 +106,15 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService { ...@@ -106,6 +106,15 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
.eq(WeApp::getAgentId, agentId) .eq(WeApp::getAgentId, agentId)
.eq(WeApp::getDelFlag, Constants.NORMAL_CODE) .eq(WeApp::getDelFlag, Constants.NORMAL_CODE)
.eq(WeApp::getStatus, Constants.NORMAL_CODE)); .eq(WeApp::getStatus, Constants.NORMAL_CODE));
return findThirdAppAccessToken(weApp);
}
private String findThirdAppAccessToken(WeApp weApp){
if(weApp == null){ if(weApp == null){
throw new WeComException("当前agentId不可用或不存在"); throw new WeComException("当前agentId不可用或不存在");
} }
...@@ -118,14 +127,15 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService { ...@@ -118,14 +127,15 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
WeAccessTokenDtoDto weAccessTokenDtoDto WeAccessTokenDtoDto weAccessTokenDtoDto
= accessTokenClient.getToken(wxCorpAccount.getCorpId(),weApp.getAgentSecret()); = accessTokenClient.getToken(wxCorpAccount.getCorpId(),weApp.getAgentSecret());
token=weAccessTokenDtoDto.getAccess_token();
if(StringUtils.isNotEmpty(token)){
redisCache.setCacheObject(WeConstans.WE_THIRD_APP_TOKEN+"::"+agentId,token,weAccessTokenDtoDto.getExpires_in().intValue(), TimeUnit.SECONDS); if(StringUtils.isNotEmpty(weAccessTokenDtoDto.getAccess_token())){
redisCache.setCacheObject(WeConstans.WE_THIRD_APP_TOKEN+"::"+weApp.getAgentId(),weAccessTokenDtoDto.getAccess_token(),weAccessTokenDtoDto.getExpires_in().intValue(), TimeUnit.SECONDS);
} }
return token; return weAccessTokenDtoDto.getAccess_token();
} }
......
...@@ -11,6 +11,7 @@ import com.linkwechat.wecom.domain.WeDepartment; ...@@ -11,6 +11,7 @@ import com.linkwechat.wecom.domain.WeDepartment;
import com.linkwechat.wecom.domain.dto.WeAppDetailDto; import com.linkwechat.wecom.domain.dto.WeAppDetailDto;
import com.linkwechat.wecom.domain.dto.WeAppDto; import com.linkwechat.wecom.domain.dto.WeAppDto;
import com.linkwechat.wecom.mapper.WeAppMapper; import com.linkwechat.wecom.mapper.WeAppMapper;
import com.linkwechat.wecom.service.IWeAccessTokenService;
import com.linkwechat.wecom.service.IWeAppService; import com.linkwechat.wecom.service.IWeAppService;
import com.linkwechat.wecom.service.IWeDepartmentService; import com.linkwechat.wecom.service.IWeDepartmentService;
import com.linkwechat.wecom.service.IWeUserService; import com.linkwechat.wecom.service.IWeUserService;
...@@ -43,6 +44,10 @@ public class WeAppServiceImpl extends ServiceImpl<WeAppMapper, WeApp> implements ...@@ -43,6 +44,10 @@ public class WeAppServiceImpl extends ServiceImpl<WeAppMapper, WeApp> implements
IWeUserService iWeUserService; IWeUserService iWeUserService;
@Autowired
IWeAccessTokenService iWeAccessTokenService;
/** /**
* 保存应用 * 保存应用
* @param weApp * @param weApp
...@@ -51,6 +56,7 @@ public class WeAppServiceImpl extends ServiceImpl<WeAppMapper, WeApp> implements ...@@ -51,6 +56,7 @@ public class WeAppServiceImpl extends ServiceImpl<WeAppMapper, WeApp> implements
@Transactional @Transactional
public void addWeApp(WeApp weApp) { public void addWeApp(WeApp weApp) {
if(null !=this.getOne(new LambdaQueryWrapper<WeApp>() if(null !=this.getOne(new LambdaQueryWrapper<WeApp>()
.eq(WeApp::getAgentId, weApp.getAgentId()) .eq(WeApp::getAgentId, weApp.getAgentId())
.eq(WeApp::getDelFlag, Constants.SUCCESS))){ .eq(WeApp::getDelFlag, Constants.SUCCESS))){
...@@ -58,19 +64,25 @@ public class WeAppServiceImpl extends ServiceImpl<WeAppMapper, WeApp> implements ...@@ -58,19 +64,25 @@ public class WeAppServiceImpl extends ServiceImpl<WeAppMapper, WeApp> implements
} }
weApp.setCreateTime(new Date());
if(this.save(weApp)){
WeAppDetailDto weAppDetailDto WeAppDetailDto weAppDetailDto
= weAppClient.findAgentById(weApp.getAgentId()); = weAppClient.findAgentById(weApp.getAgentId());
if(null != weAppDetailDto){ if(null != weAppDetailDto){
weApp.setAgentName(weAppDetailDto.getName()); weApp.setAgentName(weAppDetailDto.getName());
weApp.setCreateTime(new Date()); weApp.setCreateTime(new Date());
weApp.setSquareLogoUrl(weAppDetailDto.getSquare_logo_url()); weApp.setSquareLogoUrl(weAppDetailDto.getSquare_logo_url());
weApp.setDescription(weAppDetailDto.getDescription()); weApp.setDescription(weAppDetailDto.getDescription());
weApp.setAllowPartys(StringUtils.join(weAppDetailDto.getAllow_partys().getPartyid(),",")); weApp.setAllowPartys(StringUtils.join(weAppDetailDto.getAllow_partys().getPartyid(),","));
weApp.setAllowUserinfos(StringUtils.join(weAppDetailDto.getAllow_userinfos().getUser(),",")); weApp.setAllowUserinfos(StringUtils.join(weAppDetailDto.getAllow_userinfos().getUser(),","));
this.save(weApp); System.out.println("============================================");
this.updateById(weApp);
}
} }
} }
...@@ -85,7 +97,7 @@ public class WeAppServiceImpl extends ServiceImpl<WeAppMapper, WeApp> implements ...@@ -85,7 +97,7 @@ public class WeAppServiceImpl extends ServiceImpl<WeAppMapper, WeApp> implements
.logo_mediaid(weApp.getLogoMediaid()) .logo_mediaid(weApp.getLogoMediaid())
.description(weApp.getDescription()) .description(weApp.getDescription())
.name(weApp.getAgentName()) .name(weApp.getAgentName())
.build() .build(),weApp.getAgentId()
); );
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册