Commit 20383abf by 孙喜旺

拦截器优化,取消使用request.setUrl()方法导致的get方法参数丢失问题

1 parent 90363e80
...@@ -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(baseURL = "${weComServerUrl}${weComePrefix}", interceptor = WeAccessTokenInterceptor.class)
public interface WeAccessTokenClient { public interface WeAccessTokenClient {
/** /**
* 获取token(常用token,联系人token) * 获取token(常用token,联系人token)
......
...@@ -9,7 +9,7 @@ import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor; ...@@ -9,7 +9,7 @@ import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor;
/** /**
* 应用管理相关接口 * 应用管理相关接口
*/ */
@BaseRequest(interceptor = WeAccessTokenInterceptor.class) @BaseRequest(baseURL = "${weComServerUrl}${weComePrefix}", interceptor = WeAccessTokenInterceptor.class)
public interface WeAppClient { public interface WeAppClient {
/** /**
......
...@@ -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-10-17 11:00 * @create: 2020-10-17 11:00
**/ **/
@BaseRequest(interceptor = WeAccessTokenInterceptor.class) @BaseRequest(baseURL = "${weComServerUrl}${weComePrefix}", interceptor = WeAccessTokenInterceptor.class)
public interface WeCropTagClient { public interface WeCropTagClient {
/** /**
......
...@@ -15,7 +15,7 @@ import java.util.Map; ...@@ -15,7 +15,7 @@ import java.util.Map;
* @author: HaoN * @author: HaoN
* @create: 2020-09-15 14:15 * @create: 2020-09-15 14:15
**/ **/
@BaseRequest(interceptor = WeAccessTokenInterceptor.class) @BaseRequest(baseURL = "${weComServerUrl}${weComePrefix}", interceptor = WeAccessTokenInterceptor.class)
public interface WeCustomerClient { public interface WeCustomerClient {
/** /**
......
...@@ -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-10-20 21:50 * @create: 2020-10-20 21:50
**/ **/
@BaseRequest(interceptor = WeAccessTokenInterceptor.class) @BaseRequest(baseURL = "${weComServerUrl}${weComePrefix}", interceptor = WeAccessTokenInterceptor.class)
public interface WeCustomerGroupClient { public interface WeCustomerGroupClient {
......
...@@ -12,7 +12,7 @@ import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor; ...@@ -12,7 +12,7 @@ import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor;
* @author: KeWen * @author: KeWen
* @create: 2020-10-25 21:34 * @create: 2020-10-25 21:34
**/ **/
@BaseRequest(interceptor = WeAccessTokenInterceptor.class) @BaseRequest(baseURL = "${weComServerUrl}${weComePrefix}", interceptor = WeAccessTokenInterceptor.class)
public interface WeCustomerMessagePushClient { public interface WeCustomerMessagePushClient {
......
...@@ -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-27 16:40 * @create: 2020-08-27 16:40
**/ **/
@BaseRequest(interceptor = WeAccessTokenInterceptor.class) @BaseRequest(baseURL = "${weComServerUrl}${weComePrefix}", interceptor = WeAccessTokenInterceptor.class)
public interface WeDepartMentClient { public interface WeDepartMentClient {
/** /**
......
...@@ -12,7 +12,7 @@ import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor; ...@@ -12,7 +12,7 @@ import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor;
* @author: HaoN * @author: HaoN
* @create: 2020-10-13 10:39 * @create: 2020-10-13 10:39
**/ **/
@BaseRequest(interceptor = WeAccessTokenInterceptor.class) @BaseRequest(baseURL = "${weComServerUrl}${weComePrefix}", interceptor = WeAccessTokenInterceptor.class)
public interface WeExternalContactClient { public interface WeExternalContactClient {
@Request(url = "/externalcontact/add_contact_way", @Request(url = "/externalcontact/add_contact_way",
......
...@@ -17,7 +17,7 @@ import java.io.InputStream; ...@@ -17,7 +17,7 @@ import java.io.InputStream;
* @Description: * @Description:
* @Date: create in 2020/9/24 0024 0:14 * @Date: create in 2020/9/24 0024 0:14
*/ */
@BaseRequest(interceptor = WeAccessTokenInterceptor.class) @BaseRequest(baseURL = "${weComServerUrl}${weComePrefix}", interceptor = WeAccessTokenInterceptor.class)
public interface WeMediaClient { public interface WeMediaClient {
/** /**
* 上传图片 * 上传图片
......
...@@ -15,7 +15,7 @@ import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor; ...@@ -15,7 +15,7 @@ import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor;
* @create: 2020-10-17 22:41 * @create: 2020-10-17 22:41
**/ **/
@SuppressWarnings("all") @SuppressWarnings("all")
@BaseRequest(interceptor = WeAccessTokenInterceptor.class) @BaseRequest(baseURL = "${weComServerUrl}${weComePrefix}", interceptor = WeAccessTokenInterceptor.class)
public interface WeMessagePushClient { public interface WeMessagePushClient {
/** /**
......
...@@ -13,7 +13,7 @@ import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor; ...@@ -13,7 +13,7 @@ import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor;
* @description 会话存档接口 * @description 会话存档接口
* @date 2020/12/2 16:45 * @date 2020/12/2 16:45
**/ **/
@BaseRequest(interceptor = WeAccessTokenInterceptor.class) @BaseRequest(baseURL = "${weComServerUrl}${weComePrefix}", interceptor = WeAccessTokenInterceptor.class)
public interface WeMsgAuditClient { public interface WeMsgAuditClient {
/** /**
......
...@@ -11,7 +11,7 @@ import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor; ...@@ -11,7 +11,7 @@ import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor;
* @description h5获取签名 * @description h5获取签名
* @date 2021/1/6 11:51 * @date 2021/1/6 11:51
**/ **/
@BaseRequest(interceptor = WeAccessTokenInterceptor.class) @BaseRequest(baseURL = "${weComServerUrl}${weComePrefix}", interceptor = WeAccessTokenInterceptor.class)
public interface WeTicketClient { public interface WeTicketClient {
/** /**
* 获取去企业jsapi_ticket * 获取去企业jsapi_ticket
......
...@@ -9,7 +9,7 @@ import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor; ...@@ -9,7 +9,7 @@ import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor;
* @author: HaoN * @author: HaoN
* @create: 2020-08-27 16:42 * @create: 2020-08-27 16:42
**/ **/
@BaseRequest(interceptor = WeAccessTokenInterceptor.class) @BaseRequest(baseURL = "${weComServerUrl}${weComePrefix}", interceptor = WeAccessTokenInterceptor.class)
public interface WeUserClient { public interface WeUserClient {
/** /**
......
...@@ -2,6 +2,7 @@ package com.linkwechat.wecom.interceptor; ...@@ -2,6 +2,7 @@ package com.linkwechat.wecom.interceptor;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.dtflys.forest.config.ForestConfiguration;
import com.dtflys.forest.exceptions.ForestRuntimeException; 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;
...@@ -15,7 +16,10 @@ import lombok.extern.slf4j.Slf4j; ...@@ -15,7 +16,10 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
/** /**
* @description: 微信token拦截器 * @description: 微信token拦截器
...@@ -34,6 +38,9 @@ public class WeAccessTokenInterceptor implements Interceptor{ ...@@ -34,6 +38,9 @@ public class WeAccessTokenInterceptor implements Interceptor{
@Autowired @Autowired
private WeComeConfig weComeConfig; private WeComeConfig weComeConfig;
@Resource
private ForestConfiguration forestConfiguration;
/** /**
...@@ -41,9 +48,11 @@ public class WeAccessTokenInterceptor implements Interceptor{ ...@@ -41,9 +48,11 @@ public class WeAccessTokenInterceptor implements Interceptor{
*/ */
@Override @Override
public boolean beforeExecute(ForestRequest request) { public boolean beforeExecute(ForestRequest request) {
String uri=request.getUrl().replace("http://",""); String weComServerUrl = String.valueOf(forestConfiguration.getVariableValue("weComServerUrl"));
String weComePrefix = String.valueOf(forestConfiguration.getVariableValue("weComePrefix"));
String uri=request.getUrl().replace(weComServerUrl+weComePrefix,"");
log.info(">>>>>>>>>>>>>>>>>>>>>>>>uri:{}",uri); log.info(">>>>>>>>>>>>>>>>>>>>>>>>uri:{}",uri);
//request.setContentType("application/json");
if(!Arrays.asList(weComeConfig.getFileUplodUrl()).contains(uri)){ if(!Arrays.asList(weComeConfig.getFileUplodUrl()).contains(uri)){
request.setDataType(ForestDataType.JSON); request.setDataType(ForestDataType.JSON);
request.setContentType("application/json"); request.setContentType("application/json");
...@@ -59,26 +68,19 @@ public class WeAccessTokenInterceptor implements Interceptor{ ...@@ -59,26 +68,19 @@ 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( 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) 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();
} }
if (uri.contains("ticket/get")){ if (uri.contains("ticket/get")){
request.addQuery("type","agent_config"); request.addQuery("type","agent_config");
} }
request.addQuery("access_token",token); request.addQuery("access_token",token);
} }
//添加服务器统一请求地址 //添加服务器统一请求地址
request.setUrl(weComeConfig.getServerUrl()+weComeConfig.getWeComePrefix()+uri); // request.setUrl(weComeConfig.getServerUrl()+weComeConfig.getWeComePrefix()+uri);
return true; return true;
} }
......
...@@ -12,8 +12,7 @@ import com.linkwechat.wecom.interceptor.WeiXinAuthInterceptor; ...@@ -12,8 +12,7 @@ import com.linkwechat.wecom.interceptor.WeiXinAuthInterceptor;
* @description * @description
* @date 2021/4/5 15:47 * @date 2021/4/5 15:47
**/ **/
@BaseRequest(baseURL = "https://api.weixin.qq.com/sns",contentType = "application/json" @BaseRequest(baseURL = "${wxServerUrl}${wxPrefix}",contentType = "application/json",interceptor = WeiXinAuthInterceptor.class)
,interceptor = WeiXinAuthInterceptor.class)
public interface WxAuthClient { public interface WxAuthClient {
/** /**
* 获取微信授权token * 获取微信授权token
......
...@@ -11,7 +11,7 @@ import com.linkwechat.wecom.interceptor.WeiXinAccessTokenInterceptor; ...@@ -11,7 +11,7 @@ import com.linkwechat.wecom.interceptor.WeiXinAccessTokenInterceptor;
* @description * @description
* @date 2021/4/5 17:11 * @date 2021/4/5 17:11
**/ **/
@BaseRequest(baseURL = "https://api.weixin.qq.com/cgi-bin",contentType = "application/json") @BaseRequest(baseURL = "${wxServerUrl}${weComePrefix}",contentType = "application/json")
public interface WxCommonClient { public interface WxCommonClient {
/** /**
* 获取微信token * 获取微信token
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!