| @@ -1,13 +1,16 @@ | |||||
| package me.chanjar.weixin.common.util.http; | package me.chanjar.weixin.common.util.http; | ||||
| import java.io.File; | |||||
| import java.io.IOException; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import me.chanjar.weixin.common.util.http.apache.ApacheMediaDownloadRequestExecutor; | import me.chanjar.weixin.common.util.http.apache.ApacheMediaDownloadRequestExecutor; | ||||
| import me.chanjar.weixin.common.util.http.jodd.JoddHttpMediaDownloadRequestExecutor; | import me.chanjar.weixin.common.util.http.jodd.JoddHttpMediaDownloadRequestExecutor; | ||||
| import me.chanjar.weixin.common.util.http.okhttp.OkHttpMediaDownloadRequestExecutor; | import me.chanjar.weixin.common.util.http.okhttp.OkHttpMediaDownloadRequestExecutor; | ||||
| import java.io.File; | |||||
| /** | /** | ||||
| * 下载媒体文件请求执行器,请求的参数是String, 返回的结果是File | |||||
| * 下载媒体文件请求执行器. | |||||
| * 请求的参数是String, 返回的结果是File | |||||
| * 视频文件不支持下载 | * 视频文件不支持下载 | ||||
| * | * | ||||
| * @author Daniel Qian | * @author Daniel Qian | ||||
| @@ -21,6 +24,11 @@ public abstract class BaseMediaDownloadRequestExecutor<H, P> implements RequestE | |||||
| this.tmpDirFile = tmpDirFile; | this.tmpDirFile = tmpDirFile; | ||||
| } | } | ||||
| @Override | |||||
| public void execute(String uri, String data, ResponseHandler<File> handler) throws WxErrorException, IOException { | |||||
| handler.handle(this.execute(uri, data)); | |||||
| } | |||||
| public static RequestExecutor<File, String> create(RequestHttp requestHttp, File tmpDirFile) { | public static RequestExecutor<File, String> create(RequestHttp requestHttp, File tmpDirFile) { | ||||
| switch (requestHttp.getRequestType()) { | switch (requestHttp.getRequestType()) { | ||||
| case APACHE_HTTP: | case APACHE_HTTP: | ||||
| @@ -1,14 +1,17 @@ | |||||
| package me.chanjar.weixin.common.util.http; | package me.chanjar.weixin.common.util.http; | ||||
| import java.io.File; | |||||
| import java.io.IOException; | |||||
| import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; | import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import me.chanjar.weixin.common.util.http.apache.ApacheMediaUploadRequestExecutor; | import me.chanjar.weixin.common.util.http.apache.ApacheMediaUploadRequestExecutor; | ||||
| import me.chanjar.weixin.common.util.http.jodd.JoddHttpMediaUploadRequestExecutor; | import me.chanjar.weixin.common.util.http.jodd.JoddHttpMediaUploadRequestExecutor; | ||||
| import me.chanjar.weixin.common.util.http.okhttp.OkHttpMediaUploadRequestExecutor; | import me.chanjar.weixin.common.util.http.okhttp.OkHttpMediaUploadRequestExecutor; | ||||
| import java.io.File; | |||||
| /** | /** | ||||
| * 上传媒体文件请求执行器,请求的参数是File, 返回的结果是String | |||||
| * 上传媒体文件请求执行器. | |||||
| * 请求的参数是File, 返回的结果是String | |||||
| * | * | ||||
| * @author Daniel Qian | * @author Daniel Qian | ||||
| */ | */ | ||||
| @@ -19,6 +22,11 @@ public abstract class MediaUploadRequestExecutor<H, P> implements RequestExecuto | |||||
| this.requestHttp = requestHttp; | this.requestHttp = requestHttp; | ||||
| } | } | ||||
| @Override | |||||
| public void execute(String uri, File data, ResponseHandler<WxMediaUploadResult> handler) throws WxErrorException, IOException { | |||||
| handler.handle(this.execute(uri, data)); | |||||
| } | |||||
| public static RequestExecutor<WxMediaUploadResult, File> create(RequestHttp requestHttp) { | public static RequestExecutor<WxMediaUploadResult, File> create(RequestHttp requestHttp) { | ||||
| switch (requestHttp.getRequestType()) { | switch (requestHttp.getRequestType()) { | ||||
| case APACHE_HTTP: | case APACHE_HTTP: | ||||
| @@ -18,6 +18,21 @@ public interface RequestExecutor<T, E> { | |||||
| * | * | ||||
| * @param uri uri | * @param uri uri | ||||
| * @param data 数据 | * @param data 数据 | ||||
| * @return 响应结果 | |||||
| * @throws WxErrorException 自定义异常 | |||||
| * @throws IOException io异常 | |||||
| */ | */ | ||||
| T execute(String uri, E data) throws WxErrorException, IOException; | T execute(String uri, E data) throws WxErrorException, IOException; | ||||
| /** | |||||
| * 执行http请求. | |||||
| * | |||||
| * @param uri uri | |||||
| * @param data 数据 | |||||
| * @param handler http响应处理器 | |||||
| * @throws WxErrorException 自定义异常 | |||||
| * @throws IOException io异常 | |||||
| */ | |||||
| void execute(String uri, E data, ResponseHandler<T> handler) throws WxErrorException, IOException; | |||||
| } | } | ||||
| @@ -2,21 +2,30 @@ package me.chanjar.weixin.common.util.http; | |||||
| /** | /** | ||||
| * Created by ecoolper on 2017/4/22. | * Created by ecoolper on 2017/4/22. | ||||
| * | |||||
| * @author ecoolper | |||||
| */ | */ | ||||
| public interface RequestHttp<H, P> { | public interface RequestHttp<H, P> { | ||||
| /** | /** | ||||
| * 返回httpClient | |||||
| * 返回httpClient. | |||||
| * | * | ||||
| * @return 返回httpClient | |||||
| */ | */ | ||||
| H getRequestHttpClient(); | H getRequestHttpClient(); | ||||
| /** | /** | ||||
| * 返回httpProxy | |||||
| * 返回httpProxy. | |||||
| * | * | ||||
| * @return 返回httpProxy | |||||
| */ | */ | ||||
| P getRequestHttpProxy(); | P getRequestHttpProxy(); | ||||
| /** | |||||
| * 返回HttpType. | |||||
| * | |||||
| * @return HttpType | |||||
| */ | |||||
| HttpType getRequestType(); | HttpType getRequestType(); | ||||
| } | } | ||||
| @@ -0,0 +1,19 @@ | |||||
| package me.chanjar.weixin.common.util.http; | |||||
| /** | |||||
| * <pre> | |||||
| * http请求响应回调处理接口. | |||||
| * Created by Binary Wang on 2018/12/8. | |||||
| * </pre> | |||||
| * | |||||
| * @param <T> 返回值类型 | |||||
| * @author <a href="https://github.com/binarywang">Binary Wang</a> | |||||
| */ | |||||
| public interface ResponseHandler<T> { | |||||
| /** | |||||
| * 响应结果处理. | |||||
| * | |||||
| * @param t 要处理的对象 | |||||
| */ | |||||
| void handle(T t); | |||||
| } | |||||
| @@ -1,11 +1,15 @@ | |||||
| package me.chanjar.weixin.common.util.http; | package me.chanjar.weixin.common.util.http; | ||||
| import java.io.IOException; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientSimpleGetRequestExecutor; | import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientSimpleGetRequestExecutor; | ||||
| import me.chanjar.weixin.common.util.http.jodd.JoddHttpSimpleGetRequestExecutor; | import me.chanjar.weixin.common.util.http.jodd.JoddHttpSimpleGetRequestExecutor; | ||||
| import me.chanjar.weixin.common.util.http.okhttp.OkHttpSimpleGetRequestExecutor; | import me.chanjar.weixin.common.util.http.okhttp.OkHttpSimpleGetRequestExecutor; | ||||
| /** | /** | ||||
| * 简单的GET请求执行器,请求的参数是String, 返回的结果也是String | |||||
| * 简单的GET请求执行器. | |||||
| * 请求的参数是String, 返回的结果也是String | |||||
| * | * | ||||
| * @author Daniel Qian | * @author Daniel Qian | ||||
| */ | */ | ||||
| @@ -16,6 +20,11 @@ public abstract class SimpleGetRequestExecutor<H, P> implements RequestExecutor< | |||||
| this.requestHttp = requestHttp; | this.requestHttp = requestHttp; | ||||
| } | } | ||||
| @Override | |||||
| public void execute(String uri, String data, ResponseHandler<String> handler) throws WxErrorException, IOException { | |||||
| handler.handle(this.execute(uri, data)); | |||||
| } | |||||
| public static RequestExecutor<String, String> create(RequestHttp requestHttp) { | public static RequestExecutor<String, String> create(RequestHttp requestHttp) { | ||||
| switch (requestHttp.getRequestType()) { | switch (requestHttp.getRequestType()) { | ||||
| case APACHE_HTTP: | case APACHE_HTTP: | ||||
| @@ -1,5 +1,8 @@ | |||||
| package me.chanjar.weixin.common.util.http; | package me.chanjar.weixin.common.util.http; | ||||
| import java.io.IOException; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import me.chanjar.weixin.common.util.http.apache.ApacheSimplePostRequestExecutor; | import me.chanjar.weixin.common.util.http.apache.ApacheSimplePostRequestExecutor; | ||||
| import me.chanjar.weixin.common.util.http.jodd.JoddHttpSimplePostRequestExecutor; | import me.chanjar.weixin.common.util.http.jodd.JoddHttpSimplePostRequestExecutor; | ||||
| import me.chanjar.weixin.common.util.http.okhttp.OkHttpSimplePostRequestExecutor; | import me.chanjar.weixin.common.util.http.okhttp.OkHttpSimplePostRequestExecutor; | ||||
| @@ -17,6 +20,11 @@ public abstract class SimplePostRequestExecutor<H, P> implements RequestExecutor | |||||
| this.requestHttp = requestHttp; | this.requestHttp = requestHttp; | ||||
| } | } | ||||
| @Override | |||||
| public void execute(String uri, String data, ResponseHandler<String> handler) throws WxErrorException, IOException { | |||||
| handler.handle(this.execute(uri, data)); | |||||
| } | |||||
| public static RequestExecutor<String, String> create(RequestHttp requestHttp) { | public static RequestExecutor<String, String> create(RequestHttp requestHttp) { | ||||
| switch (requestHttp.getRequestType()) { | switch (requestHttp.getRequestType()) { | ||||
| case APACHE_HTTP: | case APACHE_HTTP: | ||||
| @@ -1,16 +1,17 @@ | |||||
| package me.chanjar.weixin.common.util.http.apache; | package me.chanjar.weixin.common.util.http.apache; | ||||
| import me.chanjar.weixin.common.error.WxError; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import me.chanjar.weixin.common.util.http.RequestHttp; | |||||
| import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; | |||||
| import java.io.IOException; | |||||
| 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; | ||||
| import org.apache.http.client.methods.HttpGet; | import org.apache.http.client.methods.HttpGet; | ||||
| import org.apache.http.impl.client.CloseableHttpClient; | import org.apache.http.impl.client.CloseableHttpClient; | ||||
| import java.io.IOException; | |||||
| import me.chanjar.weixin.common.error.WxError; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import me.chanjar.weixin.common.util.http.RequestHttp; | |||||
| import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; | |||||
| /** | /** | ||||
| * Created by ecoolper on 2017/5/4. | * Created by ecoolper on 2017/5/4. | ||||
| @@ -25,7 +25,6 @@ import me.chanjar.weixin.common.util.http.RequestHttp; | |||||
| * Created by ecoolper on 2017/5/5. | * Created by ecoolper on 2017/5/5. | ||||
| */ | */ | ||||
| public class ApacheMediaDownloadRequestExecutor extends BaseMediaDownloadRequestExecutor<CloseableHttpClient, HttpHost> { | public class ApacheMediaDownloadRequestExecutor extends BaseMediaDownloadRequestExecutor<CloseableHttpClient, HttpHost> { | ||||
| public ApacheMediaDownloadRequestExecutor(RequestHttp requestHttp, File tmpDirFile) { | public ApacheMediaDownloadRequestExecutor(RequestHttp requestHttp, File tmpDirFile) { | ||||
| super(requestHttp, tmpDirFile); | super(requestHttp, tmpDirFile); | ||||
| } | } | ||||
| @@ -18,6 +18,7 @@ import me.chanjar.weixin.common.error.WxError; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| 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.ResponseHandler; | |||||
| 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; | ||||
| @@ -31,6 +32,11 @@ public class QrcodeBytesRequestExecutor implements RequestExecutor<byte[], Abstr | |||||
| this.requestHttp = requestHttp; | this.requestHttp = requestHttp; | ||||
| } | } | ||||
| @Override | |||||
| public void execute(String uri, AbstractWxMaQrcodeWrapper data, ResponseHandler<byte[]> handler) throws WxErrorException, IOException { | |||||
| handler.handle(this.execute(uri, data)); | |||||
| } | |||||
| @Override | @Override | ||||
| public byte[] execute(String uri, AbstractWxMaQrcodeWrapper qrcodeWrapper) throws WxErrorException, IOException { | public byte[] execute(String uri, AbstractWxMaQrcodeWrapper qrcodeWrapper) throws WxErrorException, IOException { | ||||
| HttpPost httpPost = new HttpPost(uri); | HttpPost httpPost = new HttpPost(uri); | ||||
| @@ -20,6 +20,7 @@ import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import me.chanjar.weixin.common.util.fs.FileUtils; | import me.chanjar.weixin.common.util.fs.FileUtils; | ||||
| 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.ResponseHandler; | |||||
| 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; | ||||
| @@ -33,6 +34,11 @@ public class QrcodeRequestExecutor implements RequestExecutor<File, AbstractWxMa | |||||
| this.requestHttp = requestHttp; | this.requestHttp = requestHttp; | ||||
| } | } | ||||
| @Override | |||||
| public void execute(String uri, AbstractWxMaQrcodeWrapper data, ResponseHandler<File> handler) throws WxErrorException, IOException { | |||||
| handler.handle(this.execute(uri, data)); | |||||
| } | |||||
| @Override | @Override | ||||
| public File execute(String uri, AbstractWxMaQrcodeWrapper qrcodeWrapper) throws WxErrorException, IOException { | public File execute(String uri, AbstractWxMaQrcodeWrapper qrcodeWrapper) throws WxErrorException, IOException { | ||||
| HttpPost httpPost = new HttpPost(uri); | HttpPost httpPost = new HttpPost(uri); | ||||
| @@ -52,6 +52,8 @@ import me.chanjar.weixin.mp.bean.result.WxMpUser; | |||||
| import me.chanjar.weixin.mp.enums.TicketType; | import me.chanjar.weixin.mp.enums.TicketType; | ||||
| /** | /** | ||||
| * 基础实现类. | |||||
| * | |||||
| * @author someone | * @author someone | ||||
| */ | */ | ||||
| public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestHttp<H, P> { | public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestHttp<H, P> { | ||||
| @@ -55,6 +55,7 @@ public class WxMpTemplateMessage implements Serializable { | |||||
| /** | /** | ||||
| * 模板数据. | * 模板数据. | ||||
| */ | */ | ||||
| @Builder.Default | |||||
| private List<WxMpTemplateData> data = new ArrayList<>(); | private List<WxMpTemplateData> data = new ArrayList<>(); | ||||
| public WxMpTemplateMessage addData(WxMpTemplateData datum) { | public WxMpTemplateMessage addData(WxMpTemplateData datum) { | ||||
| @@ -1,15 +1,21 @@ | |||||
| package me.chanjar.weixin.mp.util.requestexecuter.material; | package me.chanjar.weixin.mp.util.requestexecuter.material; | ||||
| import java.io.IOException; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import me.chanjar.weixin.common.WxType; | import me.chanjar.weixin.common.WxType; | ||||
| import me.chanjar.weixin.common.error.WxError; | import me.chanjar.weixin.common.error.WxError; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.common.util.http.RequestHttp; | import me.chanjar.weixin.common.util.http.RequestHttp; | ||||
| import me.chanjar.weixin.common.util.http.ResponseHandler; | |||||
| import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo; | import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo; | ||||
| import okhttp3.*; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import java.io.IOException; | |||||
| import okhttp3.FormBody; | |||||
| import okhttp3.OkHttpClient; | |||||
| import okhttp3.Request; | |||||
| import okhttp3.RequestBody; | |||||
| import okhttp3.Response; | |||||
| /** | /** | ||||
| * Created by ecoolper on 2017/5/5. | * Created by ecoolper on 2017/5/5. | ||||
| @@ -17,11 +23,15 @@ import java.io.IOException; | |||||
| public class MaterialDeleteOkhttpRequestExecutor extends MaterialDeleteRequestExecutor<OkHttpClient, OkHttpProxyInfo> { | public class MaterialDeleteOkhttpRequestExecutor extends MaterialDeleteRequestExecutor<OkHttpClient, OkHttpProxyInfo> { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| public MaterialDeleteOkhttpRequestExecutor(RequestHttp requestHttp) { | public MaterialDeleteOkhttpRequestExecutor(RequestHttp requestHttp) { | ||||
| super(requestHttp); | super(requestHttp); | ||||
| } | } | ||||
| @Override | |||||
| public void execute(String uri, String data, ResponseHandler<Boolean> handler) throws WxErrorException, IOException { | |||||
| handler.handle(this.execute(uri, data)); | |||||
| } | |||||
| @Override | @Override | ||||
| public Boolean execute(String uri, String materialId) throws WxErrorException, IOException { | public Boolean execute(String uri, String materialId) throws WxErrorException, IOException { | ||||
| logger.debug("MaterialDeleteOkhttpRequestExecutor is running"); | logger.debug("MaterialDeleteOkhttpRequestExecutor is running"); | ||||
| @@ -1,7 +1,11 @@ | |||||
| package me.chanjar.weixin.mp.util.requestexecuter.material; | package me.chanjar.weixin.mp.util.requestexecuter.material; | ||||
| import java.io.IOException; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| 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.ResponseHandler; | |||||
| public abstract class MaterialDeleteRequestExecutor<H, P> implements RequestExecutor<Boolean, String> { | public abstract class MaterialDeleteRequestExecutor<H, P> implements RequestExecutor<Boolean, String> { | ||||
| protected RequestHttp<H, P> requestHttp; | protected RequestHttp<H, P> requestHttp; | ||||
| @@ -10,6 +14,11 @@ public abstract class MaterialDeleteRequestExecutor<H, P> implements RequestExec | |||||
| this.requestHttp = requestHttp; | this.requestHttp = requestHttp; | ||||
| } | } | ||||
| @Override | |||||
| public void execute(String uri, String data, ResponseHandler<Boolean> handler) throws WxErrorException, IOException { | |||||
| handler.handle(this.execute(uri, data)); | |||||
| } | |||||
| public static RequestExecutor<Boolean, String> create(RequestHttp requestHttp) { | public static RequestExecutor<Boolean, String> create(RequestHttp requestHttp) { | ||||
| switch (requestHttp.getRequestType()) { | switch (requestHttp.getRequestType()) { | ||||
| case APACHE_HTTP: | case APACHE_HTTP: | ||||
| @@ -1,7 +1,11 @@ | |||||
| package me.chanjar.weixin.mp.util.requestexecuter.material; | package me.chanjar.weixin.mp.util.requestexecuter.material; | ||||
| import java.io.IOException; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| 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.ResponseHandler; | |||||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; | import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; | ||||
| public abstract class MaterialNewsInfoRequestExecutor<H, P> implements RequestExecutor<WxMpMaterialNews, String> { | public abstract class MaterialNewsInfoRequestExecutor<H, P> implements RequestExecutor<WxMpMaterialNews, String> { | ||||
| @@ -11,6 +15,11 @@ public abstract class MaterialNewsInfoRequestExecutor<H, P> implements RequestEx | |||||
| this.requestHttp = requestHttp; | this.requestHttp = requestHttp; | ||||
| } | } | ||||
| @Override | |||||
| public void execute(String uri, String data, ResponseHandler<WxMpMaterialNews> handler) throws WxErrorException, IOException { | |||||
| handler.handle(this.execute(uri, data)); | |||||
| } | |||||
| public static RequestExecutor<WxMpMaterialNews, String> create(RequestHttp requestHttp) { | public static RequestExecutor<WxMpMaterialNews, String> create(RequestHttp requestHttp) { | ||||
| switch (requestHttp.getRequestType()) { | switch (requestHttp.getRequestType()) { | ||||
| case APACHE_HTTP: | case APACHE_HTTP: | ||||
| @@ -1,7 +1,11 @@ | |||||
| package me.chanjar.weixin.mp.util.requestexecuter.material; | package me.chanjar.weixin.mp.util.requestexecuter.material; | ||||
| import java.io.IOException; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| 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.ResponseHandler; | |||||
| 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; | ||||
| @@ -15,6 +19,11 @@ public abstract class MaterialUploadRequestExecutor<H, P> implements RequestExec | |||||
| this.requestHttp = requestHttp; | this.requestHttp = requestHttp; | ||||
| } | } | ||||
| @Override | |||||
| public void execute(String uri, WxMpMaterial data, ResponseHandler<WxMpMaterialUploadResult> handler) throws WxErrorException, IOException { | |||||
| handler.handle(this.execute(uri, data)); | |||||
| } | |||||
| public static RequestExecutor<WxMpMaterialUploadResult, WxMpMaterial> create(RequestHttp requestHttp) { | public static RequestExecutor<WxMpMaterialUploadResult, WxMpMaterial> create(RequestHttp requestHttp) { | ||||
| switch (requestHttp.getRequestType()) { | switch (requestHttp.getRequestType()) { | ||||
| case APACHE_HTTP: | case APACHE_HTTP: | ||||
| @@ -1,30 +1,37 @@ | |||||
| package me.chanjar.weixin.mp.util.requestexecuter.material; | package me.chanjar.weixin.mp.util.requestexecuter.material; | ||||
| import me.chanjar.weixin.common.util.http.RequestExecutor; | |||||
| import me.chanjar.weixin.common.util.http.RequestHttp; | |||||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialVideoInfoResult; | |||||
| import java.io.IOException; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import me.chanjar.weixin.common.util.http.RequestExecutor; | |||||
| import me.chanjar.weixin.common.util.http.RequestHttp; | |||||
| import me.chanjar.weixin.common.util.http.ResponseHandler; | |||||
| import me.chanjar.weixin.mp.bean.material.WxMpMaterialVideoInfoResult; | |||||
| public abstract class MaterialVideoInfoRequestExecutor<H, P> implements RequestExecutor<WxMpMaterialVideoInfoResult, String> { | public abstract class MaterialVideoInfoRequestExecutor<H, P> implements RequestExecutor<WxMpMaterialVideoInfoResult, String> { | ||||
| protected RequestHttp<H, P> requestHttp; | protected RequestHttp<H, P> requestHttp; | ||||
| public MaterialVideoInfoRequestExecutor(RequestHttp requestHttp) { | public MaterialVideoInfoRequestExecutor(RequestHttp requestHttp) { | ||||
| this.requestHttp = requestHttp; | |||||
| } | |||||
| public static RequestExecutor<WxMpMaterialVideoInfoResult, String> create(RequestHttp requestHttp) { | |||||
| switch (requestHttp.getRequestType()) { | |||||
| case APACHE_HTTP: | |||||
| return new MaterialVideoInfoApacheHttpRequestExecutor(requestHttp); | |||||
| case JODD_HTTP: | |||||
| return new MaterialVideoInfoJoddHttpRequestExecutor(requestHttp); | |||||
| case OK_HTTP: | |||||
| return new MaterialVideoInfoOkhttpRequestExecutor(requestHttp); | |||||
| default: | |||||
| return null; | |||||
| } | |||||
| } | |||||
| } | |||||
| this.requestHttp = requestHttp; | |||||
| } | |||||
| @Override | |||||
| public void execute(String uri, String data, ResponseHandler<WxMpMaterialVideoInfoResult> handler) throws WxErrorException, IOException { | |||||
| handler.handle(this.execute(uri, data)); | |||||
| } | |||||
| public static RequestExecutor<WxMpMaterialVideoInfoResult, String> create(RequestHttp requestHttp) { | |||||
| switch (requestHttp.getRequestType()) { | |||||
| case APACHE_HTTP: | |||||
| return new MaterialVideoInfoApacheHttpRequestExecutor(requestHttp); | |||||
| case JODD_HTTP: | |||||
| return new MaterialVideoInfoJoddHttpRequestExecutor(requestHttp); | |||||
| case OK_HTTP: | |||||
| return new MaterialVideoInfoOkhttpRequestExecutor(requestHttp); | |||||
| default: | |||||
| return null; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,13 +1,15 @@ | |||||
| package me.chanjar.weixin.mp.util.requestexecuter.material; | package me.chanjar.weixin.mp.util.requestexecuter.material; | ||||
| import me.chanjar.weixin.common.util.http.RequestExecutor; | |||||
| import me.chanjar.weixin.common.util.http.RequestHttp; | |||||
| import java.io.File; | import java.io.File; | ||||
| import java.io.IOException; | |||||
| import java.io.InputStream; | import java.io.InputStream; | ||||
| public abstract class MaterialVoiceAndImageDownloadRequestExecutor<H, P> | |||||
| implements RequestExecutor<InputStream, String> { | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import me.chanjar.weixin.common.util.http.RequestExecutor; | |||||
| import me.chanjar.weixin.common.util.http.RequestHttp; | |||||
| import me.chanjar.weixin.common.util.http.ResponseHandler; | |||||
| public abstract class MaterialVoiceAndImageDownloadRequestExecutor<H, P> implements RequestExecutor<InputStream, String> { | |||||
| protected RequestHttp<H, P> requestHttp; | protected RequestHttp<H, P> requestHttp; | ||||
| protected File tmpDirFile; | protected File tmpDirFile; | ||||
| @@ -16,6 +18,11 @@ public abstract class MaterialVoiceAndImageDownloadRequestExecutor<H, P> | |||||
| this.tmpDirFile = tmpDirFile; | this.tmpDirFile = tmpDirFile; | ||||
| } | } | ||||
| @Override | |||||
| public void execute(String uri, String data, ResponseHandler<InputStream> handler) throws WxErrorException, IOException { | |||||
| handler.handle(this.execute(uri, data)); | |||||
| } | |||||
| public static RequestExecutor<InputStream, String> create(RequestHttp requestHttp, File tmpDirFile) { | public static RequestExecutor<InputStream, String> create(RequestHttp requestHttp, File tmpDirFile) { | ||||
| switch (requestHttp.getRequestType()) { | switch (requestHttp.getRequestType()) { | ||||
| case APACHE_HTTP: | case APACHE_HTTP: | ||||
| @@ -1,11 +1,14 @@ | |||||
| package me.chanjar.weixin.mp.util.requestexecuter.media; | package me.chanjar.weixin.mp.util.requestexecuter.media; | ||||
| import java.io.File; | |||||
| import java.io.IOException; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| 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.ResponseHandler; | |||||
| import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult; | import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult; | ||||
| import java.io.File; | |||||
| /** | /** | ||||
| * @author miller | * @author miller | ||||
| */ | */ | ||||
| @@ -16,6 +19,11 @@ public abstract class MediaImgUploadRequestExecutor<H, P> implements RequestExec | |||||
| this.requestHttp = requestHttp; | this.requestHttp = requestHttp; | ||||
| } | } | ||||
| @Override | |||||
| public void execute(String uri, File data, ResponseHandler<WxMediaImgUploadResult> handler) throws WxErrorException, IOException { | |||||
| handler.handle(this.execute(uri, data)); | |||||
| } | |||||
| public static RequestExecutor<WxMediaImgUploadResult, File> create(RequestHttp requestHttp) { | public static RequestExecutor<WxMediaImgUploadResult, File> create(RequestHttp requestHttp) { | ||||
| switch (requestHttp.getRequestType()) { | switch (requestHttp.getRequestType()) { | ||||
| case APACHE_HTTP: | case APACHE_HTTP: | ||||
| @@ -1,15 +1,17 @@ | |||||
| package me.chanjar.weixin.mp.util.requestexecuter.qrcode; | package me.chanjar.weixin.mp.util.requestexecuter.qrcode; | ||||
| import java.io.File; | |||||
| import java.io.IOException; | |||||
| import me.chanjar.weixin.common.error.WxError; | import me.chanjar.weixin.common.error.WxError; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| 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.ResponseHandler; | |||||
| import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; | import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; | ||||
| import java.io.File; | |||||
| /** | /** | ||||
| * 获得QrCode图片 请求执行器 | |||||
| * 获得QrCode图片 请求执行器. | |||||
| * | * | ||||
| * @author chanjarster | * @author chanjarster | ||||
| */ | */ | ||||
| @@ -20,6 +22,11 @@ public abstract class QrCodeRequestExecutor<H, P> implements RequestExecutor<Fil | |||||
| this.requestHttp = requestHttp; | this.requestHttp = requestHttp; | ||||
| } | } | ||||
| @Override | |||||
| public void execute(String uri, WxMpQrCodeTicket data, ResponseHandler<File> handler) throws WxErrorException, IOException { | |||||
| handler.handle(this.execute(uri, data)); | |||||
| } | |||||
| public static RequestExecutor<File, WxMpQrCodeTicket> create(RequestHttp requestHttp) throws WxErrorException { | public static RequestExecutor<File, WxMpQrCodeTicket> create(RequestHttp requestHttp) throws WxErrorException { | ||||
| switch (requestHttp.getRequestType()) { | switch (requestHttp.getRequestType()) { | ||||
| case APACHE_HTTP: | case APACHE_HTTP: | ||||
| @@ -1,9 +1,12 @@ | |||||
| package me.chanjar.weixin.mp.util.requestexecuter.voice; | package me.chanjar.weixin.mp.util.requestexecuter.voice; | ||||
| import java.io.File; | |||||
| import java.io.IOException; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| 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 java.io.File; | |||||
| import me.chanjar.weixin.common.util.http.ResponseHandler; | |||||
| /** | /** | ||||
| * <pre> | * <pre> | ||||
| @@ -19,6 +22,11 @@ public abstract class VoiceUploadRequestExecutor<H, P> implements RequestExecuto | |||||
| this.requestHttp = requestHttp; | this.requestHttp = requestHttp; | ||||
| } | } | ||||
| @Override | |||||
| public void execute(String uri, File data, ResponseHandler<Boolean> handler) throws WxErrorException, IOException { | |||||
| handler.handle(this.execute(uri, data)); | |||||
| } | |||||
| public static RequestExecutor<Boolean, File> create(RequestHttp requestHttp) { | public static RequestExecutor<Boolean, File> create(RequestHttp requestHttp) { | ||||
| switch (requestHttp.getRequestType()) { | switch (requestHttp.getRequestType()) { | ||||
| case APACHE_HTTP: | case APACHE_HTTP: | ||||
| @@ -1,5 +1,10 @@ | |||||
| package me.chanjar.weixin.open.api.impl; | package me.chanjar.weixin.open.api.impl; | ||||
| import java.io.IOException; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import me.chanjar.weixin.common.error.WxError; | import me.chanjar.weixin.common.error.WxError; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.common.util.http.RequestExecutor; | import me.chanjar.weixin.common.util.http.RequestExecutor; | ||||
| @@ -7,17 +12,13 @@ import me.chanjar.weixin.common.util.http.RequestHttp; | |||||
| import me.chanjar.weixin.open.api.WxOpenComponentService; | import me.chanjar.weixin.open.api.WxOpenComponentService; | ||||
| import me.chanjar.weixin.open.api.WxOpenConfigStorage; | import me.chanjar.weixin.open.api.WxOpenConfigStorage; | ||||
| import me.chanjar.weixin.open.api.WxOpenService; | import me.chanjar.weixin.open.api.WxOpenService; | ||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import java.io.IOException; | |||||
| /** | /** | ||||
| * @author <a href="https://github.com/007gzs">007</a> | * @author <a href="https://github.com/007gzs">007</a> | ||||
| */ | */ | ||||
| public abstract class WxOpenServiceAbstractImpl<H, P> implements WxOpenService, RequestHttp<H, P> { | public abstract class WxOpenServiceAbstractImpl<H, P> implements WxOpenService, RequestHttp<H, P> { | ||||
| protected final Logger log = LoggerFactory.getLogger(this.getClass()); | |||||
| protected WxOpenComponentService wxOpenComponentService = new WxOpenComponentServiceImpl(this); | |||||
| private final Logger log = LoggerFactory.getLogger(this.getClass()); | |||||
| private WxOpenComponentService wxOpenComponentService = new WxOpenComponentServiceImpl(this); | |||||
| private WxOpenConfigStorage wxOpenConfigStorage; | private WxOpenConfigStorage wxOpenConfigStorage; | ||||
| @Override | @Override | ||||
| @@ -37,7 +38,7 @@ public abstract class WxOpenServiceAbstractImpl<H, P> implements WxOpenService, | |||||
| } | } | ||||
| /** | /** | ||||
| * 初始化 RequestHttp | |||||
| * 初始化 RequestHttp. | |||||
| */ | */ | ||||
| public abstract void initHttp(); | public abstract void initHttp(); | ||||
| @@ -1,15 +1,17 @@ | |||||
| package me.chanjar.weixin.open.util.requestexecuter.ma; | package me.chanjar.weixin.open.util.requestexecuter.ma; | ||||
| import java.io.File; | |||||
| import java.io.IOException; | |||||
| import me.chanjar.weixin.common.error.WxError; | import me.chanjar.weixin.common.error.WxError; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| 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.ResponseHandler; | |||||
| import me.chanjar.weixin.open.bean.ma.WxMaQrcodeParam; | import me.chanjar.weixin.open.bean.ma.WxMaQrcodeParam; | ||||
| import java.io.File; | |||||
| /** | /** | ||||
| * 获得小程序体验QrCode图片 请求执行器 | |||||
| * 获得小程序体验QrCode图片 请求执行器. | |||||
| * | * | ||||
| * @author yqx | * @author yqx | ||||
| * @date 2018-09-13 | * @date 2018-09-13 | ||||
| @@ -21,6 +23,11 @@ public abstract class MaQrCodeRequestExecutor<H, P> implements RequestExecutor<F | |||||
| this.requestHttp = requestHttp; | this.requestHttp = requestHttp; | ||||
| } | } | ||||
| @Override | |||||
| public void execute(String uri, WxMaQrcodeParam data, ResponseHandler<File> handler) throws WxErrorException, IOException { | |||||
| handler.handle(this.execute(uri, data)); | |||||
| } | |||||
| public static RequestExecutor<File, WxMaQrcodeParam> create(RequestHttp requestHttp) throws WxErrorException { | public static RequestExecutor<File, WxMaQrcodeParam> create(RequestHttp requestHttp) throws WxErrorException { | ||||
| switch (requestHttp.getRequestType()) { | switch (requestHttp.getRequestType()) { | ||||
| case APACHE_HTTP: | case APACHE_HTTP: | ||||