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

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

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