forked from binarywang/WxJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:Wechat-Group/weixin-java-tools i…
…nto develop * 'develop' of github.com:Wechat-Group/weixin-java-tools: (132 commits) 发布临时测试版本2.8.1.BETA 修正一个错误的类属性命名 修复单元测试 清理代码 pay模块显式指定commons-lang3,以便用户项目可能会优先使用所依赖设置的版本 清理代码,避免过度依赖容易引起冲突的类库代码 精简代码 Fix issue binarywang#335: 重构WxMpInRedisConfigStorage,改用连接池 binarywang#136 修复WxMenuRule反序列化的问题tag_id为空的问题 Update readme.md Update readme.md 修改版本号为正式版本2.8.0 binarywang#320 增加“拉取订单评价数据“接口方法 binarywang#319 增加“退款结果通知“处理方法,并优化调整微信支付相关代码 binarywang#322 为me.chanjar.weixin.mp.bean下的bean类实现Serializable接口,并增加serialVersionUID binarywang#324: 修复分布式刷新access_token冲突问题 binarywang#324: 修复分布式刷新access_token冲突问题 微信支付增加获取微信的请求和响应数据的方法getWxApiData(),方便使用者获取使用该数据 微信支付优化部分代码,方便扩展 微信支付接口抽取部分常量 ...
- Loading branch information
Showing
192 changed files
with
3,637 additions
and
1,224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/HttpResponseProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package me.chanjar.weixin.common.util.http; | ||
|
||
import jodd.http.HttpResponse; | ||
import me.chanjar.weixin.common.bean.result.WxError; | ||
import me.chanjar.weixin.common.exception.WxErrorException; | ||
import okhttp3.Response; | ||
import org.apache.http.Header; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* <pre> | ||
* 三种http框架的response代理类,方便提取公共方法 | ||
* Created by Binary Wang on 2017-8-3. | ||
* </pre> | ||
* | ||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | ||
*/ | ||
public class HttpResponseProxy { | ||
private CloseableHttpResponse apacheHttpResponse; | ||
private HttpResponse joddHttpResponse; | ||
private Response okHttpResponse; | ||
|
||
public HttpResponseProxy(CloseableHttpResponse apacheHttpResponse) { | ||
this.apacheHttpResponse = apacheHttpResponse; | ||
} | ||
|
||
public HttpResponseProxy(HttpResponse joddHttpResponse) { | ||
this.joddHttpResponse = joddHttpResponse; | ||
} | ||
|
||
public HttpResponseProxy(Response okHttpResponse) { | ||
this.okHttpResponse = okHttpResponse; | ||
} | ||
|
||
public String getFileName() throws WxErrorException { | ||
//由于对象只能由一个构造方法实现,因此三个response对象必定且只有一个不为空 | ||
if (this.apacheHttpResponse != null) { | ||
return this.getFileName(this.apacheHttpResponse); | ||
} | ||
|
||
if (this.joddHttpResponse != null) { | ||
return this.getFileName(this.joddHttpResponse); | ||
} | ||
|
||
if (this.okHttpResponse != null) { | ||
return this.getFileName(this.okHttpResponse); | ||
} | ||
|
||
//cannot happen | ||
return null; | ||
} | ||
|
||
private String getFileName(CloseableHttpResponse response) throws WxErrorException { | ||
Header[] contentDispositionHeader = response.getHeaders("Content-disposition"); | ||
if (contentDispositionHeader == null || contentDispositionHeader.length == 0) { | ||
throw new WxErrorException(WxError.newBuilder().setErrorMsg("无法获取到文件名").build()); | ||
} | ||
|
||
return this.extractFileNameFromContentString(contentDispositionHeader[0].getValue()); | ||
} | ||
|
||
private String getFileName(HttpResponse response) throws WxErrorException { | ||
String content = response.header("Content-disposition"); | ||
return this.extractFileNameFromContentString(content); | ||
} | ||
|
||
private String getFileName(Response response) throws WxErrorException { | ||
String content = response.header("Content-disposition"); | ||
return this.extractFileNameFromContentString(content); | ||
} | ||
|
||
private String extractFileNameFromContentString(String content) throws WxErrorException { | ||
if (content == null || content.length() == 0) { | ||
throw new WxErrorException(WxError.newBuilder().setErrorMsg("无法获取到文件名").build()); | ||
} | ||
|
||
Pattern p = Pattern.compile(".*filename=\"(.*)\""); | ||
Matcher m = p.matcher(content); | ||
if (m.matches()) { | ||
return m.group(1); | ||
} | ||
throw new WxErrorException(WxError.newBuilder().setErrorMsg("无法获取到文件名").build()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.