Commit f8c66105 by 水库浪子

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	linkwe-admin/pom.xml
#	linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeAccessTokenServiceImpl.java
2 parents e033f51a 8033f5f0
...@@ -120,4 +120,9 @@ xss: ...@@ -120,4 +120,9 @@ xss:
# forest配置 # forest配置
forest: forest:
interceptors: com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor
\ No newline at end of file \ No newline at end of file
interceptors: com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor
wecome:
serverUrl: https://qyapi.weixin.qq.com/
weComePrefix: cgi-bin
\ No newline at end of file \ No newline at end of file
package com.linkwechat.common.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @Author: Robin
* @Description: 企业微信配置文件相关
* @Date: create in 2020/9/3 0003 23:25
*/
@Component
@ConfigurationProperties(prefix = "wecome")
@Data
public class WeComeConfig {
/** 企业微信后台地址 */
private String serverUrl;
/** 企业微信后台地址前缀 */
private String weComePrefix;
}
...@@ -5,10 +5,16 @@ package com.linkwechat.common.constant; ...@@ -5,10 +5,16 @@ package com.linkwechat.common.constant;
* @author: HaoN * @author: HaoN
* @create: 2020-08-26 17:01 * @create: 2020-08-26 17:01
**/ **/
public class WxConstans { public class WeConstans {
/** /**
* 企业微信相关token * 企业微信相关token
*/ */
public static final String WX_ACCESS_TOKEN = "WxAccessToken"; public static final String WE_ACCESS_TOKEN = "WeAccessToken";
/**
* 企业微信接口返回成功code
*/
public static final Integer WE_SUCCESS_CODE = 0;
} }
...@@ -19,7 +19,7 @@ public interface WeAccessTokenClient { ...@@ -19,7 +19,7 @@ public interface WeAccessTokenClient {
* @param corpSecret 应用的凭证密钥 * @param corpSecret 应用的凭证密钥
* @return * @return
*/ */
@Request(url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken") @Request(url = "/gettoken")
WeAccessTokenDtoDto getToken(@Query("corpid")String corpId, @Query("corpsecret") String corpSecret); WeAccessTokenDtoDto getToken(@Query("corpid")String corpId, @Query("corpsecret") String corpSecret);
} }
\ No newline at end of file \ No newline at end of file
...@@ -19,7 +19,7 @@ public interface WeDepartMentClient { ...@@ -19,7 +19,7 @@ public interface WeDepartMentClient {
* @param weDepartMent * @param weDepartMent
* @return * @return
*/ */
@Request(url="https://qyapi.weixin.qq.com/cgi-bin/department/create", @Request(url="/department/create",
type = "POST" type = "POST"
) )
WeResultDto createWeDepartMent(@DataObject WeDepartMentDtoDto weDepartMent); WeResultDto createWeDepartMent(@DataObject WeDepartMentDtoDto weDepartMent);
...@@ -31,7 +31,7 @@ public interface WeDepartMentClient { ...@@ -31,7 +31,7 @@ public interface WeDepartMentClient {
* @param weDepartMent * @param weDepartMent
* @return * @return
*/ */
@Request(url="https://qyapi.weixin.qq.com/cgi-bin/department/update", @Request(url="/department/update",
type = "POST" type = "POST"
) )
WeResultDto updateWeDepartMent(@DataObject WeDepartMentDtoDto weDepartMent); WeResultDto updateWeDepartMent(@DataObject WeDepartMentDtoDto weDepartMent);
...@@ -42,7 +42,7 @@ public interface WeDepartMentClient { ...@@ -42,7 +42,7 @@ public interface WeDepartMentClient {
* @param departMnentId * @param departMnentId
* @return * @return
*/ */
@Request(url = "https://qyapi.weixin.qq.com/cgi-bin/department/delete") @Request(url = "/department/delete")
WeResultDto deleteWeDepartMent(@Query("id") String departMnentId); WeResultDto deleteWeDepartMent(@Query("id") String departMnentId);
...@@ -50,7 +50,7 @@ public interface WeDepartMentClient { ...@@ -50,7 +50,7 @@ public interface WeDepartMentClient {
* 获取部门列表 * 获取部门列表
* @return * @return
*/ */
@Request(url = "https://qyapi.weixin.qq.com/cgi-bin/department/list") @Request(url = "/department/list")
WeDepartMentDtoDto weDepartMents(); WeDepartMentDtoDto weDepartMents();
...@@ -59,7 +59,7 @@ public interface WeDepartMentClient { ...@@ -59,7 +59,7 @@ public interface WeDepartMentClient {
* @param sizeType qrcode尺寸类型,1: 171 x 171; 2: 399 x 399; 3: 741 x 741; 4: 2052 x 2052 * @param sizeType qrcode尺寸类型,1: 171 x 171; 2: 399 x 399; 3: 741 x 741; 4: 2052 x 2052
* @return * @return
*/ */
@Request(url = " https://qyapi.weixin.qq.com/cgi-bin/corp/get_join_qrcode") @Request(url = " /corp/get_join_qrcode")
WeUserQrcodeDto getJoinQrcode(@Query("size_type") Integer sizeType); WeUserQrcodeDto getJoinQrcode(@Query("size_type") Integer sizeType);
......
...@@ -18,7 +18,7 @@ public interface WeUserClient { ...@@ -18,7 +18,7 @@ public interface WeUserClient {
* @param weUserDto * @param weUserDto
* @return * @return
*/ */
@Request(url="https://qyapi.weixin.qq.com/cgi-bin/user/create", @Request(url="/user/create",
type = "POST" type = "POST"
) )
WeResultDto createUser(@DataObject WeUserDto weUserDto); WeResultDto createUser(@DataObject WeUserDto weUserDto);
...@@ -29,7 +29,7 @@ public interface WeUserClient { ...@@ -29,7 +29,7 @@ public interface WeUserClient {
* @param userid * @param userid
* @return * @return
*/ */
@Request(url = "https://qyapi.weixin.qq.com/cgi-bin/user/get") @Request(url = "/user/get")
WeUserDto getUserByUserId(@Query("userid") String userid); WeUserDto getUserByUserId(@Query("userid") String userid);
...@@ -38,7 +38,7 @@ public interface WeUserClient { ...@@ -38,7 +38,7 @@ public interface WeUserClient {
* @param weUserDto * @param weUserDto
* @return * @return
*/ */
@Request(url="https://qyapi.weixin.qq.com/cgi-bin/user/update", @Request(url="/user/update",
type = "POST" type = "POST"
) )
WeResultDto updateUser(@DataObject WeUserDto weUserDto); WeResultDto updateUser(@DataObject WeUserDto weUserDto);
...@@ -49,6 +49,6 @@ public interface WeUserClient { ...@@ -49,6 +49,6 @@ public interface WeUserClient {
* @param userid * @param userid
* @return * @return
*/ */
@Request(url = "https://qyapi.weixin.qq.com/cgi-bin/user/delete") @Request(url = "/user/delete")
WeResultDto deleteUserByUserId(@Query("userid")String userid); WeResultDto deleteUserByUserId(@Query("userid")String userid);
} }
...@@ -4,6 +4,9 @@ import com.dtflys.forest.exceptions.ForestRuntimeException; ...@@ -4,6 +4,9 @@ import com.dtflys.forest.exceptions.ForestRuntimeException;
import com.dtflys.forest.http.ForestRequest; import com.dtflys.forest.http.ForestRequest;
import com.dtflys.forest.http.ForestResponse; import com.dtflys.forest.http.ForestResponse;
import com.dtflys.forest.interceptor.Interceptor; import com.dtflys.forest.interceptor.Interceptor;
import com.linkwechat.common.config.WeComeConfig;
import com.linkwechat.wecom.service.IWeAccessTokenService;
import org.springframework.beans.factory.annotation.Autowired;
/** /**
* @description: 微信token拦截器 * @description: 微信token拦截器
...@@ -13,19 +16,26 @@ import com.dtflys.forest.interceptor.Interceptor; ...@@ -13,19 +16,26 @@ import com.dtflys.forest.interceptor.Interceptor;
public class WeAccessTokenInterceptor implements Interceptor { public class WeAccessTokenInterceptor implements Interceptor {
@Autowired
private IWeAccessTokenService iWeAccessTokenService;
@Autowired
private WeComeConfig weComeConfig;
/** /**
* 该方法在请求发送之前被调用, 若返回false则不会继续发送请求 * 该方法在请求发送之前被调用, 若返回false则不会继续发送请求
*/ */
@Override @Override
public boolean beforeExecute(ForestRequest request) { public boolean beforeExecute(ForestRequest request) {
//添加服务器统一请求地址
// 1.从缓存中获取token,如果缓存中不存在,则调用接口,重新获取。 request.setUrl(weComeConfig.getServerUrl()+weComeConfig.getWeComePrefix()+request.getUrl());
// 添加请求参数access_token
// 获取到的的token,校验是否失效,如果失效了,则重新获取 request.addQuery("access_token", iWeAccessTokenService.findToken());
return true;
request.addQuery("access_token", "11111111"); // 添加URL的Query参数
return true; // 继续执行请求返回true
} }
......
...@@ -58,4 +58,11 @@ public interface WeCorpAccountMapper ...@@ -58,4 +58,11 @@ public interface WeCorpAccountMapper
* @return 结果 * @return 结果
*/ */
public int deleteWeCorpAccountByIds(Long[] ids); public int deleteWeCorpAccountByIds(Long[] ids);
/**
* 获取有效cropid
* @return
*/
public WeCorpAccount findValidWeCorpAccount();
} }
...@@ -7,5 +7,5 @@ package com.linkwechat.wecom.service; ...@@ -7,5 +7,5 @@ package com.linkwechat.wecom.service;
**/ **/
public interface IWeAccessTokenService { public interface IWeAccessTokenService {
void findToken(); String findToken();
} }
\ No newline at end of file \ No newline at end of file
...@@ -60,11 +60,11 @@ public interface IWeCorpAccountService ...@@ -60,11 +60,11 @@ public interface IWeCorpAccountService
public int deleteWeCorpAccountById(Long id); public int deleteWeCorpAccountById(Long id);
// /** /**
// * 获取有效的企业id * 获取有效的企业id
// * *
// * @return 结果 * @return 结果
// */ */
// public WeCorpAccount findValidWeCorpAccount(); public WeCorpAccount findValidWeCorpAccount();
} }
package com.linkwechat.wecom.service.impl; package com.linkwechat.wecom.service.impl;
import com.linkwechat.wecom.client.WeAccessTokenClient; import com.linkwechat.wecom.client.WeAccessTokenClient;
import com.linkwechat.wecom.domain.dto.WeAccessTokenDtoDto;
import com.linkwechat.wecom.domain.WeCorpAccount;
import com.linkwechat.wecom.service.IWeAccessTokenService; import com.linkwechat.wecom.service.IWeAccessTokenService;
import com.linkwechat.wecom.service.IWeCorpAccountService; import com.linkwechat.wecom.service.IWeCorpAccountService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -24,30 +26,36 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService { ...@@ -24,30 +26,36 @@ public class WeAccessTokenServiceImpl implements IWeAccessTokenService {
@Autowired @Autowired
private RedisTemplate redisTemplate; private RedisCache redisCache;
/** /**
* 获取accessToken * 获取accessToken
*/ */
@Override @Override
public void findToken() { public String findToken() {
// WeCorpAccount wxCorpAccount WeCorpAccount wxCorpAccount
// = iWxCorpAccountService.findValidWxCorpAccount(); = iWxCorpAccountService.findValidWeCorpAccount();
// if(null == wxCorpAccount){ if(null == wxCorpAccount){
// //返回错误异常,让用户绑定企业id相关信息 //返回错误异常,让用户绑定企业id相关信息
// } }
// WeAccessTokenDtoDto accessToken
// = accessTokenClient.getToken(wxCorpAccount.getCorpId(), wxCorpAccount.getCorpSecret()); String weAccessToken = (String) redisCache.getCacheObject(WeConstans.WE_ACCESS_TOKEN);
// if(null != accessToken){
// //token存入redis中(清空原有的token)
//// redisTemplate.opsForValue().set();
//
//
// }
//为空,请求微信服务器同时缓存到redis中
if(StringUtils.isEmpty(weAccessToken)){
WeAccessTokenDtoDto accessToken
= accessTokenClient.getToken(wxCorpAccount.getCorpId(), wxCorpAccount.getCorpSecret());
if(accessToken.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)){
redisCache.setCacheObject(WeConstans.WE_ACCESS_TOKEN,accessToken.getAccess_token(),accessToken.getExpires_in().intValue(), TimeUnit.SECONDS);
weAccessToken=accessToken.getAccess_token();
}
}
return weAccessToken;
} }
......
...@@ -95,13 +95,16 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService { ...@@ -95,13 +95,16 @@ public class WeCorpAccountServiceImpl implements IWeCorpAccountService {
} }
// /**
// * 获取有效的企业id /**
// * * 获取有效的企业id
// * @return 结果 *
// */ * @return 结果
// @Override */
// public WeCorpAccount findValidWeCorpAccount() { @Override
// return null; public WeCorpAccount findValidWeCorpAccount() {
// } return weCorpAccountMapper.findValidWeCorpAccount();
}
} }
...@@ -88,5 +88,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -88,5 +88,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id} #{id}
</foreach> </foreach>
</delete> </delete>
<select id="findValidWeCorpAccount" resultMap="WeCorpAccountResult">
<include refid="selectWeCorpAccountVo"/>
WHERE
del_flag = 0
AND STATUS = 0
</select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!