mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 10:38:42 +08:00 
			
		
		
		
	Merge branch 'develop' into develop
This commit is contained in:
		
							
								
								
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							| @ -5,7 +5,7 @@ | |||||||
|   <modelVersion>4.0.0</modelVersion> |   <modelVersion>4.0.0</modelVersion> | ||||||
|   <groupId>com.github.binarywang</groupId> |   <groupId>com.github.binarywang</groupId> | ||||||
|   <artifactId>weixin-java-parent</artifactId> |   <artifactId>weixin-java-parent</artifactId> | ||||||
|   <version>2.6.0</version> |   <version>2.7.0-SNAPSHOT</version> | ||||||
|   <packaging>pom</packaging> |   <packaging>pom</packaging> | ||||||
|   <name>WeiXin Java Tools - Parent</name> |   <name>WeiXin Java Tools - Parent</name> | ||||||
|   <description>微信公众号、企业号上级POM</description> |   <description>微信公众号、企业号上级POM</description> | ||||||
|  | |||||||
| @ -52,7 +52,7 @@ | |||||||
| --------------------------------- | --------------------------------- | ||||||
| ## Maven & Gradle 最新正式版本 | ## Maven & Gradle 最新正式版本 | ||||||
|  |  | ||||||
| * 微信支付(暂时为测试版本): | * 微信支付: | ||||||
|  |  | ||||||
| maven: | maven: | ||||||
| ```xml | ```xml | ||||||
|  | |||||||
| @ -6,7 +6,7 @@ | |||||||
|   <parent> |   <parent> | ||||||
|     <groupId>com.github.binarywang</groupId> |     <groupId>com.github.binarywang</groupId> | ||||||
|     <artifactId>weixin-java-parent</artifactId> |     <artifactId>weixin-java-parent</artifactId> | ||||||
|     <version>2.6.0</version> |     <version>2.7.0-SNAPSHOT</version> | ||||||
|   </parent> |   </parent> | ||||||
|  |  | ||||||
|   <artifactId>weixin-java-common</artifactId> |   <artifactId>weixin-java-common</artifactId> | ||||||
| @ -39,6 +39,11 @@ | |||||||
|       <artifactId>jetty-servlet</artifactId> |       <artifactId>jetty-servlet</artifactId> | ||||||
|       <scope>test</scope> |       <scope>test</scope> | ||||||
|     </dependency> |     </dependency> | ||||||
|  |     <dependency> | ||||||
|  |       <groupId>org.jodd</groupId> | ||||||
|  |       <artifactId>jodd-http</artifactId> | ||||||
|  |       <version>3.7</version> | ||||||
|  |     </dependency> | ||||||
|   </dependencies> |   </dependencies> | ||||||
|  |  | ||||||
|   <build> |   <build> | ||||||
|  | |||||||
| @ -10,6 +10,7 @@ import me.chanjar.weixin.common.exception.WxErrorException; | |||||||
| import me.chanjar.weixin.common.util.fs.FileUtils; | import me.chanjar.weixin.common.util.fs.FileUtils; | ||||||
| import me.chanjar.weixin.common.util.http.apache.InputStreamResponseHandler; | import me.chanjar.weixin.common.util.http.apache.InputStreamResponseHandler; | ||||||
| import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | ||||||
| import okhttp3.*; | import okhttp3.*; | ||||||
|  |  | ||||||
| @ -111,7 +112,7 @@ public class MediaDownloadRequestExecutor extends AbstractRequestExecutor<File, | |||||||
|         } |         } | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       String fileName = getFileName(response); |       String fileName = getFileNameApache(response); | ||||||
|       if (StringUtils.isBlank(fileName)) { |       if (StringUtils.isBlank(fileName)) { | ||||||
|         return null; |         return null; | ||||||
|       } |       } | ||||||
| @ -128,7 +129,6 @@ public class MediaDownloadRequestExecutor extends AbstractRequestExecutor<File, | |||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * jodd-http实现方式 |    * jodd-http实现方式 | ||||||
|    * |  | ||||||
|    * @param provider |    * @param provider | ||||||
|    * @param proxyInfo |    * @param proxyInfo | ||||||
|    * @param uri |    * @param uri | ||||||
| @ -237,7 +237,23 @@ public class MediaDownloadRequestExecutor extends AbstractRequestExecutor<File, | |||||||
|     if (m.matches()) { |     if (m.matches()) { | ||||||
|       return m.group(1); |       return m.group(1); | ||||||
|     } |     } | ||||||
|     throw new WxErrorException(WxError.newBuilder().setErrorMsg("无法获取到文件名").build()); |     request.withConnectionProvider(provider); | ||||||
|  |     HttpResponse response = request.send(); | ||||||
|  |     String contentType = response.header("Content-Type"); | ||||||
|  |     if (contentType != null && contentType.startsWith("application/json")) { | ||||||
|  |       // application/json; encoding=utf-8 下载媒体文件出错 | ||||||
|  |       throw new WxErrorException(WxError.fromJson(response.bodyText())); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     String fileName = getFileNameJodd(response); | ||||||
|  |     if (StringUtils.isBlank(fileName)) { | ||||||
|  |       return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     InputStream inputStream = new ByteArrayInputStream(response.bodyBytes()); | ||||||
|  |     String[] nameAndExt = fileName.split("\\."); | ||||||
|  |     return FileUtils.createTmpFile(inputStream, nameAndExt[0], nameAndExt[1], this.tmpDirFile); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -8,6 +8,7 @@ import me.chanjar.weixin.common.bean.result.WxError; | |||||||
| import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; | import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; | ||||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
| import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | ||||||
| import okhttp3.*; | import okhttp3.*; | ||||||
|  |  | ||||||
|  | |||||||
| @ -3,6 +3,7 @@ package me.chanjar.weixin.common.util.http; | |||||||
| import jodd.http.HttpConnectionProvider; | import jodd.http.HttpConnectionProvider; | ||||||
| import jodd.http.ProxyInfo; | import jodd.http.ProxyInfo; | ||||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | ||||||
| import okhttp3.ConnectionPool; | import okhttp3.ConnectionPool; | ||||||
|  |  | ||||||
| @ -63,5 +64,4 @@ public interface RequestExecutor<T, E> { | |||||||
|    */ |    */ | ||||||
|   T executeOkhttp(ConnectionPool pool, final OkhttpProxyInfo proxyInfo, String uri, E data) throws WxErrorException, IOException; |   T executeOkhttp(ConnectionPool pool, final OkhttpProxyInfo proxyInfo, String uri, E data) throws WxErrorException, IOException; | ||||||
|  |  | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -7,6 +7,7 @@ import jodd.http.ProxyInfo; | |||||||
| import me.chanjar.weixin.common.bean.result.WxError; | import me.chanjar.weixin.common.bean.result.WxError; | ||||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
| import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | ||||||
| import okhttp3.*; | import okhttp3.*; | ||||||
|  |  | ||||||
| @ -28,6 +29,7 @@ import java.util.concurrent.TimeUnit; | |||||||
|  */ |  */ | ||||||
| public class SimpleGetRequestExecutor extends AbstractRequestExecutor<String, String> { | public class SimpleGetRequestExecutor extends AbstractRequestExecutor<String, String> { | ||||||
|  |  | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * apache-http实现方式 |    * apache-http实现方式 | ||||||
|    * |    * | ||||||
| @ -98,6 +100,7 @@ public class SimpleGetRequestExecutor extends AbstractRequestExecutor<String, St | |||||||
|     return responseContent; |     return responseContent; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * okHttp实现方式 |    * okHttp实现方式 | ||||||
|    * |    * | ||||||
| @ -146,5 +149,4 @@ public class SimpleGetRequestExecutor extends AbstractRequestExecutor<String, St | |||||||
|     return responseContent; |     return responseContent; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -7,6 +7,7 @@ import jodd.http.ProxyInfo; | |||||||
| import me.chanjar.weixin.common.bean.result.WxError; | import me.chanjar.weixin.common.bean.result.WxError; | ||||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
| import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | ||||||
| import okhttp3.*; | import okhttp3.*; | ||||||
|  |  | ||||||
| @ -40,6 +41,7 @@ public class SimplePostRequestExecutor extends AbstractRequestExecutor<String, S | |||||||
|    * @throws IOException |    * @throws IOException | ||||||
|    */ |    */ | ||||||
|   public String executeApache(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String postEntity) throws WxErrorException, IOException { |   public String executeApache(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String postEntity) throws WxErrorException, IOException { | ||||||
|  |  | ||||||
|     HttpPost httpPost = new HttpPost(uri); |     HttpPost httpPost = new HttpPost(uri); | ||||||
|     if (httpProxy != null) { |     if (httpProxy != null) { | ||||||
|       RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build(); |       RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build(); | ||||||
|  | |||||||
| @ -6,7 +6,7 @@ | |||||||
|   <parent> |   <parent> | ||||||
|     <groupId>com.github.binarywang</groupId> |     <groupId>com.github.binarywang</groupId> | ||||||
|     <artifactId>weixin-java-parent</artifactId> |     <artifactId>weixin-java-parent</artifactId> | ||||||
|     <version>2.6.0</version> |     <version>2.7.0-SNAPSHOT</version> | ||||||
|   </parent> |   </parent> | ||||||
|  |  | ||||||
|   <artifactId>weixin-java-cp</artifactId> |   <artifactId>weixin-java-cp</artifactId> | ||||||
|  | |||||||
| @ -1,6 +1,5 @@ | |||||||
| package me.chanjar.weixin.cp.api.impl.apache; | package me.chanjar.weixin.cp.api.impl.apache; | ||||||
|  |  | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.bean.WxAccessToken; | import me.chanjar.weixin.common.bean.WxAccessToken; | ||||||
| import me.chanjar.weixin.common.bean.result.WxError; | import me.chanjar.weixin.common.bean.result.WxError; | ||||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
| @ -8,6 +7,7 @@ import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder; | |||||||
| import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder; | import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder; | ||||||
| import me.chanjar.weixin.cp.api.impl.AbstractWxCpService; | import me.chanjar.weixin.cp.api.impl.AbstractWxCpService; | ||||||
|  |  | ||||||
|  |  | ||||||
| import org.apache.http.HttpHost; | import org.apache.http.HttpHost; | ||||||
| import org.apache.http.client.config.RequestConfig; | import org.apache.http.client.config.RequestConfig; | ||||||
| import org.apache.http.client.methods.CloseableHttpResponse; | import org.apache.http.client.methods.CloseableHttpResponse; | ||||||
| @ -73,6 +73,7 @@ public class WxCpServiceImpl extends AbstractWxCpService<CloseableHttpClient, Ht | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   @Override |   @Override | ||||||
|  |  | ||||||
|   public void initHttp() { |   public void initHttp() { | ||||||
|     ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage |     ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage | ||||||
|       .getApacheHttpClientBuilder(); |       .getApacheHttpClientBuilder(); | ||||||
| @ -91,4 +92,5 @@ public class WxCpServiceImpl extends AbstractWxCpService<CloseableHttpClient, Ht | |||||||
|  |  | ||||||
|     this.httpClient = apacheHttpClientBuilder.build(); |     this.httpClient = apacheHttpClientBuilder.build(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -19,6 +19,7 @@ public class WxCpServiceImpl extends AbstractWxCpService<HttpConnectionProvider, | |||||||
|   @Override |   @Override | ||||||
|   public ProxyInfo getRequestHttpProxy() { |   public ProxyInfo getRequestHttpProxy() { | ||||||
|     return httpProxy; |     return httpProxy; | ||||||
|  |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   @Override |   @Override | ||||||
| @ -56,10 +57,12 @@ public class WxCpServiceImpl extends AbstractWxCpService<HttpConnectionProvider, | |||||||
|  |  | ||||||
|   @Override |   @Override | ||||||
|   public void initHttp() { |   public void initHttp() { | ||||||
|  |  | ||||||
|     if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) { |     if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) { | ||||||
|       httpProxy = new ProxyInfo(ProxyInfo.ProxyType.HTTP, configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort(), configStorage.getHttpProxyUsername(), configStorage.getHttpProxyPassword()); |       httpProxy = new ProxyInfo(ProxyInfo.ProxyType.HTTP, configStorage.getHttpProxyHost(), configStorage.getHttpProxyPort(), configStorage.getHttpProxyUsername(), configStorage.getHttpProxyPassword()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     httpClient = JoddHttp.httpConnectionProvider; |     httpClient = JoddHttp.httpConnectionProvider; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -61,6 +61,10 @@ public class WxCpMessageGsonAdapter implements JsonSerializer<WxCpMessage> { | |||||||
|       messageJson.add("voice", voice); |       messageJson.add("voice", voice); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     if (StringUtils.isNotBlank(message.getSafe())) { | ||||||
|  |       messageJson.addProperty("safe", message.getSafe()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     if (WxConsts.CUSTOM_MSG_VIDEO.equals(message.getMsgType())) { |     if (WxConsts.CUSTOM_MSG_VIDEO.equals(message.getMsgType())) { | ||||||
|       JsonObject video = new JsonObject(); |       JsonObject video = new JsonObject(); | ||||||
|       video.addProperty("media_id", message.getMediaId()); |       video.addProperty("media_id", message.getMediaId()); | ||||||
|  | |||||||
| @ -6,7 +6,7 @@ | |||||||
|   <parent> |   <parent> | ||||||
|     <groupId>com.github.binarywang</groupId> |     <groupId>com.github.binarywang</groupId> | ||||||
|     <artifactId>weixin-java-parent</artifactId> |     <artifactId>weixin-java-parent</artifactId> | ||||||
|     <version>2.6.0</version> |     <version>2.7.0-SNAPSHOT</version> | ||||||
|   </parent> |   </parent> | ||||||
|   <artifactId>weixin-java-mp</artifactId> |   <artifactId>weixin-java-mp</artifactId> | ||||||
|   <name>WeiXin Java Tools - MP</name> |   <name>WeiXin Java Tools - MP</name> | ||||||
|  | |||||||
| @ -350,4 +350,5 @@ public interface WxMpService { | |||||||
|    */ |    */ | ||||||
|   void initHttp(); |   void initHttp(); | ||||||
|  |  | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,5 +1,6 @@ | |||||||
| package me.chanjar.weixin.mp.api.impl.apache; | package me.chanjar.weixin.mp.api.impl.apache; | ||||||
|  |  | ||||||
|  |  | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
| import java.util.concurrent.locks.Lock; | import java.util.concurrent.locks.Lock; | ||||||
|  |  | ||||||
| @ -71,11 +72,13 @@ public class WxMpServiceImpl extends AbstractWxMpService<CloseableHttpClient,Htt | |||||||
|           + this.getWxMpConfigStorage().getSecret(); |           + this.getWxMpConfigStorage().getSecret(); | ||||||
|         try { |         try { | ||||||
|           HttpGet httpGet = new HttpGet(url); |           HttpGet httpGet = new HttpGet(url); | ||||||
|  |  | ||||||
|           if (this.getRequestHttpProxy() != null) { |           if (this.getRequestHttpProxy() != null) { | ||||||
|             RequestConfig config = RequestConfig.custom().setProxy(this.getRequestHttpProxy()).build(); |             RequestConfig config = RequestConfig.custom().setProxy(this.getRequestHttpProxy()).build(); | ||||||
|             httpGet.setConfig(config); |             httpGet.setConfig(config); | ||||||
|           } |           } | ||||||
|           try (CloseableHttpResponse response = getRequestHttpClient().execute(httpGet)) { |           try (CloseableHttpResponse response = getRequestHttpClient().execute(httpGet)) { | ||||||
|  |  | ||||||
|             String resultContent = new BasicResponseHandler().handleResponse(response); |             String resultContent = new BasicResponseHandler().handleResponse(response); | ||||||
|             WxError error = WxError.fromJson(resultContent); |             WxError error = WxError.fromJson(resultContent); | ||||||
|             if (error.getErrorCode() != 0) { |             if (error.getErrorCode() != 0) { | ||||||
| @ -96,4 +99,5 @@ public class WxMpServiceImpl extends AbstractWxMpService<CloseableHttpClient,Htt | |||||||
|     } |     } | ||||||
|     return this.getWxMpConfigStorage().getAccessToken(); |     return this.getWxMpConfigStorage().getAccessToken(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,6 +1,5 @@ | |||||||
| package me.chanjar.weixin.mp.api.impl.jodd; | package me.chanjar.weixin.mp.api.impl.jodd; | ||||||
|  |  | ||||||
|  |  | ||||||
| import jodd.http.*; | import jodd.http.*; | ||||||
| import jodd.http.net.SocketHttpConnectionProvider; | import jodd.http.net.SocketHttpConnectionProvider; | ||||||
| import me.chanjar.weixin.common.bean.WxAccessToken; | import me.chanjar.weixin.common.bean.WxAccessToken; | ||||||
| @ -30,6 +29,7 @@ public class WxMpServiceImpl extends AbstractWxMpService<HttpConnectionProvider, | |||||||
|  |  | ||||||
|   @Override |   @Override | ||||||
|   public void initHttp() { |   public void initHttp() { | ||||||
|  |  | ||||||
|     WxMpConfigStorage configStorage = this.getWxMpConfigStorage(); |     WxMpConfigStorage configStorage = this.getWxMpConfigStorage(); | ||||||
|  |  | ||||||
|     if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) { |     if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) { | ||||||
| @ -40,7 +40,6 @@ public class WxMpServiceImpl extends AbstractWxMpService<HttpConnectionProvider, | |||||||
|   } |   } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|   @Override |   @Override | ||||||
|   public String getAccessToken(boolean forceRefresh) throws WxErrorException { |   public String getAccessToken(boolean forceRefresh) throws WxErrorException { | ||||||
|     Lock lock = this.getWxMpConfigStorage().getAccessTokenLock(); |     Lock lock = this.getWxMpConfigStorage().getAccessTokenLock(); | ||||||
| @ -57,9 +56,11 @@ public class WxMpServiceImpl extends AbstractWxMpService<HttpConnectionProvider, | |||||||
|           + this.getWxMpConfigStorage().getSecret(); |           + this.getWxMpConfigStorage().getSecret(); | ||||||
|  |  | ||||||
|         HttpRequest request = HttpRequest.get(url); |         HttpRequest request = HttpRequest.get(url); | ||||||
|  |  | ||||||
|         if (this.getRequestHttpProxy() != null) { |         if (this.getRequestHttpProxy() != null) { | ||||||
|           SocketHttpConnectionProvider provider = new SocketHttpConnectionProvider(); |           SocketHttpConnectionProvider provider = new SocketHttpConnectionProvider(); | ||||||
|           provider.useProxy(getRequestHttpProxy()); |           provider.useProxy(getRequestHttpProxy()); | ||||||
|  |  | ||||||
|           request.withConnectionProvider(provider); |           request.withConnectionProvider(provider); | ||||||
|         } |         } | ||||||
|         HttpResponse response = request.send(); |         HttpResponse response = request.send(); | ||||||
| @ -77,4 +78,5 @@ public class WxMpServiceImpl extends AbstractWxMpService<HttpConnectionProvider, | |||||||
|     } |     } | ||||||
|     return this.getWxMpConfigStorage().getAccessToken(); |     return this.getWxMpConfigStorage().getAccessToken(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -10,7 +10,9 @@ import me.chanjar.weixin.common.util.http.AbstractRequestExecutor; | |||||||
| import me.chanjar.weixin.common.util.http.RequestExecutor; | import me.chanjar.weixin.common.util.http.RequestExecutor; | ||||||
| import me.chanjar.weixin.common.util.http.RequestHttp; | import me.chanjar.weixin.common.util.http.RequestHttp; | ||||||
| import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.util.json.WxGsonBuilder; | import me.chanjar.weixin.common.util.json.WxGsonBuilder; | ||||||
| import okhttp3.*; | import okhttp3.*; | ||||||
|  |  | ||||||
| @ -57,6 +59,7 @@ public class MaterialDeleteRequestExecutor extends AbstractRequestExecutor<Boole | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |  | ||||||
|   @Override |   @Override | ||||||
|   public Boolean executeJodd(HttpConnectionProvider provider, ProxyInfo proxyInfo, String uri, String materialId) throws WxErrorException, IOException { |   public Boolean executeJodd(HttpConnectionProvider provider, ProxyInfo proxyInfo, String uri, String materialId) throws WxErrorException, IOException { | ||||||
|     HttpRequest request = HttpRequest.post(uri); |     HttpRequest request = HttpRequest.post(uri); | ||||||
| @ -108,5 +111,4 @@ public class MaterialDeleteRequestExecutor extends AbstractRequestExecutor<Boole | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -10,7 +10,9 @@ import me.chanjar.weixin.common.util.http.AbstractRequestExecutor; | |||||||
| import me.chanjar.weixin.common.util.http.RequestExecutor; | import me.chanjar.weixin.common.util.http.RequestExecutor; | ||||||
| import me.chanjar.weixin.common.util.http.RequestHttp; | import me.chanjar.weixin.common.util.http.RequestHttp; | ||||||
| import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.util.json.WxGsonBuilder; | import me.chanjar.weixin.common.util.json.WxGsonBuilder; | ||||||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; | import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; | ||||||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | ||||||
| @ -57,6 +59,7 @@ public class MaterialNewsInfoRequestExecutor extends AbstractRequestExecutor<WxM | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |  | ||||||
|   @Override |   @Override | ||||||
|   public WxMpMaterialNews executeJodd(HttpConnectionProvider httpclient, ProxyInfo httpProxy, String uri, String materialId) throws WxErrorException, IOException { |   public WxMpMaterialNews executeJodd(HttpConnectionProvider httpclient, ProxyInfo httpProxy, String uri, String materialId) throws WxErrorException, IOException { | ||||||
|     HttpRequest request = HttpRequest.post(uri); |     HttpRequest request = HttpRequest.post(uri); | ||||||
| @ -102,6 +105,7 @@ public class MaterialNewsInfoRequestExecutor extends AbstractRequestExecutor<WxM | |||||||
|  |  | ||||||
|     Response response = client.newCall(request).execute(); |     Response response = client.newCall(request).execute(); | ||||||
|     String responseContent = response.body().toString(); |     String responseContent = response.body().toString(); | ||||||
|  |  | ||||||
|     WxError error = WxError.fromJson(responseContent); |     WxError error = WxError.fromJson(responseContent); | ||||||
|     if (error.getErrorCode() != 0) { |     if (error.getErrorCode() != 0) { | ||||||
|       throw new WxErrorException(error); |       throw new WxErrorException(error); | ||||||
|  | |||||||
| @ -10,7 +10,9 @@ import me.chanjar.weixin.common.util.http.AbstractRequestExecutor; | |||||||
| import me.chanjar.weixin.common.util.http.RequestExecutor; | import me.chanjar.weixin.common.util.http.RequestExecutor; | ||||||
| import me.chanjar.weixin.common.util.http.RequestHttp; | import me.chanjar.weixin.common.util.http.RequestHttp; | ||||||
| import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.util.json.WxGsonBuilder; | import me.chanjar.weixin.common.util.json.WxGsonBuilder; | ||||||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterial; | import me.chanjar.weixin.mp.bean.material.WxMpMaterial; | ||||||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialUploadResult; | import me.chanjar.weixin.mp.bean.material.WxMpMaterialUploadResult; | ||||||
|  | |||||||
| @ -10,7 +10,9 @@ import me.chanjar.weixin.common.util.http.AbstractRequestExecutor; | |||||||
| import me.chanjar.weixin.common.util.http.RequestExecutor; | import me.chanjar.weixin.common.util.http.RequestExecutor; | ||||||
| import me.chanjar.weixin.common.util.http.RequestHttp; | import me.chanjar.weixin.common.util.http.RequestHttp; | ||||||
| import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.util.json.WxGsonBuilder; | import me.chanjar.weixin.common.util.json.WxGsonBuilder; | ||||||
| import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult; | import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult; | ||||||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialVideoInfoResult; | import me.chanjar.weixin.mp.bean.material.WxMpMaterialVideoInfoResult; | ||||||
|  | |||||||
| @ -6,6 +6,7 @@ import jodd.http.HttpResponse; | |||||||
| import jodd.http.ProxyInfo; | import jodd.http.ProxyInfo; | ||||||
| import me.chanjar.weixin.common.bean.result.WxError; | import me.chanjar.weixin.common.bean.result.WxError; | ||||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.util.http.AbstractRequestExecutor; | import me.chanjar.weixin.common.util.http.AbstractRequestExecutor; | ||||||
| import me.chanjar.weixin.common.util.http.RequestExecutor; | import me.chanjar.weixin.common.util.http.RequestExecutor; | ||||||
| import me.chanjar.weixin.common.util.http.RequestHttp; | import me.chanjar.weixin.common.util.http.RequestHttp; | ||||||
| @ -95,6 +96,7 @@ public class MaterialVoiceAndImageDownloadRequestExecutor extends AbstractReques | |||||||
|     Response response = client.newCall(request).execute(); |     Response response = client.newCall(request).execute(); | ||||||
|  |  | ||||||
|     try (InputStream inputStream = new ByteArrayInputStream(response.body().bytes())) { |     try (InputStream inputStream = new ByteArrayInputStream(response.body().bytes())) { | ||||||
|  |  | ||||||
|       // 下载媒体文件出错 |       // 下载媒体文件出错 | ||||||
|       byte[] responseContent = IOUtils.toByteArray(inputStream); |       byte[] responseContent = IOUtils.toByteArray(inputStream); | ||||||
|       String responseContentString = new String(responseContent, "UTF-8"); |       String responseContentString = new String(responseContent, "UTF-8"); | ||||||
|  | |||||||
| @ -4,7 +4,9 @@ import jodd.http.HttpConnectionProvider; | |||||||
| import jodd.http.HttpRequest; | import jodd.http.HttpRequest; | ||||||
| import jodd.http.HttpResponse; | import jodd.http.HttpResponse; | ||||||
| import jodd.http.ProxyInfo; | import jodd.http.ProxyInfo; | ||||||
|  |  | ||||||
| import jodd.util.MimeTypes; | import jodd.util.MimeTypes; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.bean.result.WxError; | import me.chanjar.weixin.common.bean.result.WxError; | ||||||
| import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; | import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; | ||||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
| @ -13,7 +15,9 @@ import me.chanjar.weixin.common.util.http.AbstractRequestExecutor; | |||||||
| import me.chanjar.weixin.common.util.http.RequestExecutor; | import me.chanjar.weixin.common.util.http.RequestExecutor; | ||||||
| import me.chanjar.weixin.common.util.http.RequestHttp; | import me.chanjar.weixin.common.util.http.RequestHttp; | ||||||
| import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult; | import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult; | ||||||
| import okhttp3.*; | import okhttp3.*; | ||||||
|  |  | ||||||
| @ -38,7 +42,6 @@ import java.util.UUID; | |||||||
|  */ |  */ | ||||||
| public class MediaImgUploadRequestExecutor extends AbstractRequestExecutor<WxMediaImgUploadResult, File> { | public class MediaImgUploadRequestExecutor extends AbstractRequestExecutor<WxMediaImgUploadResult, File> { | ||||||
|  |  | ||||||
|  |  | ||||||
|   @Override |   @Override | ||||||
|   public WxMediaImgUploadResult executeJodd(HttpConnectionProvider provider, ProxyInfo proxyInfo, String uri, File data) throws WxErrorException, IOException { |   public WxMediaImgUploadResult executeJodd(HttpConnectionProvider provider, ProxyInfo proxyInfo, String uri, File data) throws WxErrorException, IOException { | ||||||
|     if (data == null) { |     if (data == null) { | ||||||
| @ -99,6 +102,7 @@ public class MediaImgUploadRequestExecutor extends AbstractRequestExecutor<WxMed | |||||||
|   @Override |   @Override | ||||||
|   public WxMediaImgUploadResult executeApache(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, |   public WxMediaImgUploadResult executeApache(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, | ||||||
|                                               File data) throws WxErrorException, IOException { |                                               File data) throws WxErrorException, IOException { | ||||||
|  |  | ||||||
|     if (data == null) { |     if (data == null) { | ||||||
|       throw new WxErrorException(WxError.newBuilder().setErrorMsg("文件对象为空").build()); |       throw new WxErrorException(WxError.newBuilder().setErrorMsg("文件对象为空").build()); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -8,11 +8,13 @@ import jodd.util.MimeTypes; | |||||||
| import me.chanjar.weixin.common.bean.result.WxError; | import me.chanjar.weixin.common.bean.result.WxError; | ||||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
| import me.chanjar.weixin.common.util.fs.FileUtils; | import me.chanjar.weixin.common.util.fs.FileUtils; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.common.util.http.AbstractRequestExecutor; | import me.chanjar.weixin.common.util.http.AbstractRequestExecutor; | ||||||
| import me.chanjar.weixin.common.util.http.RequestHttp; | import me.chanjar.weixin.common.util.http.RequestHttp; | ||||||
| import me.chanjar.weixin.common.util.http.apache.InputStreamResponseHandler; | import me.chanjar.weixin.common.util.http.apache.InputStreamResponseHandler; | ||||||
| import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | import me.chanjar.weixin.common.util.http.apache.Utf8ResponseHandler; | ||||||
| import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | import me.chanjar.weixin.common.util.http.okhttp.OkhttpProxyInfo; | ||||||
|  |  | ||||||
| import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; | import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; | ||||||
| import okhttp3.*; | import okhttp3.*; | ||||||
|  |  | ||||||
| @ -101,6 +103,7 @@ public class QrCodeRequestExecutor extends AbstractRequestExecutor<File, WxMpQrC | |||||||
|   @Override |   @Override | ||||||
|   public File executeApache(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, |   public File executeApache(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, | ||||||
|                             WxMpQrCodeTicket ticket) throws WxErrorException, IOException { |                             WxMpQrCodeTicket ticket) throws WxErrorException, IOException { | ||||||
|  |  | ||||||
|     if (ticket != null) { |     if (ticket != null) { | ||||||
|       if (uri.indexOf('?') == -1) { |       if (uri.indexOf('?') == -1) { | ||||||
|         uri += '?'; |         uri += '?'; | ||||||
|  | |||||||
| @ -4,6 +4,8 @@ import me.chanjar.weixin.common.bean.result.WxError; | |||||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
| import me.chanjar.weixin.common.util.http.RequestExecutor; | import me.chanjar.weixin.common.util.http.RequestExecutor; | ||||||
|  |  | ||||||
|  | import me.chanjar.weixin.mp.api.impl.apache.WxMpServiceImpl; | ||||||
|  |  | ||||||
| import org.testng.annotations.DataProvider; | import org.testng.annotations.DataProvider; | ||||||
| import org.testng.annotations.Test; | import org.testng.annotations.Test; | ||||||
|  |  | ||||||
|  | |||||||
| @ -7,6 +7,8 @@ import me.chanjar.weixin.common.util.xml.XStreamInitializer; | |||||||
| import me.chanjar.weixin.mp.api.WxMpConfigStorage; | import me.chanjar.weixin.mp.api.WxMpConfigStorage; | ||||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||||
|  |  | ||||||
|  | import me.chanjar.weixin.mp.api.impl.apache.WxMpServiceImpl; | ||||||
|  |  | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
| import java.io.InputStream; | import java.io.InputStream; | ||||||
| import java.util.concurrent.locks.ReentrantLock; | import java.util.concurrent.locks.ReentrantLock; | ||||||
|  | |||||||
| @ -6,6 +6,8 @@ import me.chanjar.weixin.mp.api.WxMpMessageHandler; | |||||||
| import me.chanjar.weixin.mp.api.WxMpMessageRouter; | import me.chanjar.weixin.mp.api.WxMpMessageRouter; | ||||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||||
|  |  | ||||||
|  | import me.chanjar.weixin.mp.api.impl.apache.WxMpServiceImpl; | ||||||
|  |  | ||||||
| import org.eclipse.jetty.server.Server; | import org.eclipse.jetty.server.Server; | ||||||
| import org.eclipse.jetty.servlet.ServletHandler; | import org.eclipse.jetty.servlet.ServletHandler; | ||||||
| import org.eclipse.jetty.servlet.ServletHolder; | import org.eclipse.jetty.servlet.ServletHolder; | ||||||
|  | |||||||
| @ -5,7 +5,7 @@ | |||||||
|   <parent> |   <parent> | ||||||
|     <artifactId>weixin-java-parent</artifactId> |     <artifactId>weixin-java-parent</artifactId> | ||||||
|     <groupId>com.github.binarywang</groupId> |     <groupId>com.github.binarywang</groupId> | ||||||
|     <version>2.6.0</version> |     <version>2.7.0-SNAPSHOT</version> | ||||||
|   </parent> |   </parent> | ||||||
|   <modelVersion>4.0.0</modelVersion> |   <modelVersion>4.0.0</modelVersion> | ||||||
|  |  | ||||||
|  | |||||||
| @ -188,17 +188,37 @@ public class WxPayServiceImpl implements WxPayService { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     Map<String, String> payInfo = new HashMap<>(); |     Map<String, String> payInfo = new HashMap<>(); | ||||||
|     payInfo.put("appId", getConfig().getAppId()); |  | ||||||
|     // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。 |  | ||||||
|     // 但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符 |  | ||||||
|     payInfo.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000)); |  | ||||||
|     payInfo.put("nonceStr", String.valueOf(System.currentTimeMillis())); |  | ||||||
|     payInfo.put("package", "prepay_id=" + prepayId); |  | ||||||
|     payInfo.put("signType", "MD5"); |  | ||||||
|     if ("NATIVE".equals(request.getTradeType())) { |     if ("NATIVE".equals(request.getTradeType())) { | ||||||
|       payInfo.put("codeUrl", unifiedOrderResult.getCodeURL()); |       payInfo.put("codeUrl", unifiedOrderResult.getCodeURL()); | ||||||
|  |     } else if ("APP".equals(request.getTradeType())) { | ||||||
|  |       // APP支付绑定的是微信开放平台上的账号,APPID为开放平台上绑定APP后发放的参数 | ||||||
|  |       String appId = getConfig().getAppId(); | ||||||
|  |       Map<String, String> configMap = new HashMap<>(); | ||||||
|  |       // 此map用于参与调起sdk支付的二次签名,格式全小写,timestamp只能是10位,格式固定,切勿修改 | ||||||
|  |       String partnerid = getConfig().getMchId(); | ||||||
|  |       configMap.put("prepayid", prepayId); | ||||||
|  |       configMap.put("partnerid", partnerid); | ||||||
|  |       configMap.put("package", "Sign=WXPay"); | ||||||
|  |       configMap.put("timestamp", String.valueOf(System.currentTimeMillis() / 1000)); | ||||||
|  |       configMap.put("noncestr", String.valueOf(System.currentTimeMillis())); | ||||||
|  |       configMap.put("appid", appId); | ||||||
|  |       // 此map用于客户端与微信服务器交互 | ||||||
|  |       payInfo.put("paySign", SignUtils.createSign(payInfo, this.getConfig().getMchKey())); | ||||||
|  |       payInfo.put("prepayId", prepayId); | ||||||
|  |       payInfo.put("partnerId", partnerid); | ||||||
|  |       payInfo.put("appId", appId); | ||||||
|  |       payInfo.put("packageValue", "Sign=WXPay"); | ||||||
|  |       payInfo.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000)); | ||||||
|  |       payInfo.put("nonceStr", String.valueOf(System.currentTimeMillis())); | ||||||
|  |     } else if ("JSAPI".equals(request.getTradeType())) { | ||||||
|  |       payInfo.put("appId", unifiedOrderResult.getAppid()); | ||||||
|  |       // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符 | ||||||
|  |       payInfo.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000)); | ||||||
|  |       payInfo.put("nonceStr", String.valueOf(System.currentTimeMillis())); | ||||||
|  |       payInfo.put("package", "prepay_id=" + prepayId); | ||||||
|  |       payInfo.put("signType", "MD5"); | ||||||
|  |       payInfo.put("paySign", SignUtils.createSign(payInfo, this.getConfig().getMchKey())); | ||||||
|     } |     } | ||||||
|     payInfo.put("paySign", SignUtils.createSign(payInfo, this.getConfig().getMchKey())); |  | ||||||
|     return payInfo; |     return payInfo; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 crskyp
					crskyp