mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 02:28:25 +08:00 
			
		
		
		
	🎨【公共】修复下载文件相关接口获取文件名的问题
This commit is contained in:
		| @ -1,15 +1,11 @@ | |||||||
| package me.chanjar.weixin.common.util.http; | package me.chanjar.weixin.common.util.http; | ||||||
|  |  | ||||||
| import jodd.http.HttpResponse; | import jodd.http.HttpResponse; | ||||||
| import me.chanjar.weixin.common.error.WxError; |  | ||||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||||
| import okhttp3.Response; | import okhttp3.Response; | ||||||
| import org.apache.http.Header; | import org.apache.http.Header; | ||||||
| import org.apache.http.client.methods.CloseableHttpResponse; | import org.apache.http.client.methods.CloseableHttpResponse; | ||||||
|  |  | ||||||
| import java.util.regex.Matcher; |  | ||||||
| import java.util.regex.Pattern; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * <pre> |  * <pre> | ||||||
|  * 三种http框架的response代理类,方便提取公共方法 |  * 三种http框架的response代理类,方便提取公共方法 | ||||||
| @ -19,7 +15,6 @@ import java.util.regex.Pattern; | |||||||
|  * @author <a href="https://github.com/binarywang">Binary Wang</a> |  * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||||
|  */ |  */ | ||||||
| public class HttpResponseProxy { | public class HttpResponseProxy { | ||||||
|   private static final Pattern PATTERN = Pattern.compile(".*filename=\"(.*)\""); |  | ||||||
|  |  | ||||||
|   private CloseableHttpResponse apacheHttpResponse; |   private CloseableHttpResponse apacheHttpResponse; | ||||||
|   private HttpResponse joddHttpResponse; |   private HttpResponse joddHttpResponse; | ||||||
| @ -79,9 +74,11 @@ public class HttpResponseProxy { | |||||||
|       throw new WxErrorException("无法获取到文件名,content为空"); |       throw new WxErrorException("无法获取到文件名,content为空"); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     Matcher m = PATTERN.matcher(content); |     int startIndex = content.indexOf("filename=\""); | ||||||
|     if (m.matches()) { |     if (startIndex != -1) { | ||||||
|       return m.group(1); |       startIndex += "filename=\"".length(); | ||||||
|  |       int endIndex = content.indexOf('"', startIndex); | ||||||
|  |       return content.substring(startIndex, endIndex); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     throw new WxErrorException("无法获取到文件名,header信息有问题"); |     throw new WxErrorException("无法获取到文件名,header信息有问题"); | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 rayL
					rayL