Commit 20383abf by 孙喜旺

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

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