合并 Develop,发布3.1.0正式版 (#640)

* #519 修复小程序客服消息 URL 被转义的问题

* 优化单元测试提示信息

* 网页授权url增加&connect_redirect=1参数解决两次重定向跳转问题: https://blog.csdn.net/jiangguilong2000/article/details/79416615

* 修复错误的feeToYuan方法名为fenToYuan

* #529 EntPayBankRequest增加默认构造函数

* #529 EntPayBankResult中cmmsAmount的数据类型改为Integer

* #528 WxMpUser类增加三个属性:subscribe_scene、 qr_scene 和qr_scene_str

* 修复代码

* 发布3.0.1.BETA测试版本

* #533 微信刷卡支付请求类增加缺少的三个参数

* #536 企业号模块增加获取企业号应用相关接口

* 定义《企业号应用》的bean

* 增加《获取企业号应用》接口实现

* 增加获取测试企业号应用信息测试类

* #535 修复Tomcat 不能正常关闭的问题,增加线程池shutdown相关的操作

* #541 企业号增加实现管理标签的(获取标签成员)接口 

* 定义《企业号应用》的bean

* 增加《获取企业号应用》接口实现

* 增加获取测试企业号应用信息测试类

* tag service增加获取标签成员方法
http://qydev.weixin.qq.com/wiki/index.php?title=管理标签

* #534 公众号发送模版消息中的小程序path改回pagepath

* 发布3.0.2.BETA测试版本

* #547 开放平台模块 componentAccessToken 增加过期自动刷新

* createOrder方法增加H5支付的支持

* #551 文本卡片消息增加btntext字段

* #550 企业微信删除标签成员接口增加部门列表参数

* 清理无用代码

* #530 微信支付申请退款接口结果类增加单个代金券相关参数 ,并根据官方文档整理其他参数

* #531 小程序WxMaMessage类增加小程序卡片消息相关的几个属性

* #520 企业微信网页授权增加使用user_ticket获取成员详情的接口

* 发布3.0.3.BETA测试版本

* 优化代码

* 完善测试

* #559 微信开放平台:1. WxOpenInRedisConfigStorage 支持 JedisPool/JedisSentinelPool 等 Pool<Jedis> 的子类;2. WxOpenInRedisConfigStorage 增加 keyPrefix 以支持可配置的前缀;

* #560 微信开放平台:增加小程序代码模板库管理 

* 微信开放平台:1. WxOpenInRedisConfigStorage 支持 JedisPool/JedisSentinelPool 等 Pool<Jedis> 的子类;2. WxOpenInRedisConfigStorage 增加 keyPrefix 以支持可配置的前缀;

* 微信开放平台:增加小程序代码模板库管理

* #562 小程序增加代码管理相关 API

* 微信开放平台:1. WxOpenInRedisConfigStorage 支持 JedisPool/JedisSentinelPool 等 Pool<Jedis> 的子类;2. WxOpenInRedisConfigStorage 增加 keyPrefix 以支持可配置的前缀;

* 微信开放平台:增加小程序代码模板库管理

* 小程序:增加代码管理相关 API

* #563 小程序增加修改服务器地址、成员管理 API 

* 微信开放平台:1. WxOpenInRedisConfigStorage 支持 JedisPool/JedisSentinelPool 等 Pool<Jedis> 的子类;2. WxOpenInRedisConfigStorage 增加 keyPrefix 以支持可配置的前缀;

* 微信开放平台:增加小程序代码模板库管理

* 小程序:增加代码管理相关 API

* 小程序:增加修改服务器地址、成员管理 API

* #565 小程序增加数据分析相关 API 

* 微信开放平台:1. WxOpenInRedisConfigStorage 支持 JedisPool/JedisSentinelPool 等 Pool<Jedis> 的子类;2. WxOpenInRedisConfigStorage 增加 keyPrefix 以支持可配置的前缀;

* 微信开放平台:增加小程序代码模板库管理

* 小程序:增加代码管理相关 API

* 小程序:增加修改服务器地址、成员管理 API

* 小程序:增加数据分析相关 API

* #567 微信开放平台增加 HTTP proxy 机制

* 微信开放平台:1. WxOpenInRedisConfigStorage 支持 JedisPool/JedisSentinelPool 等 Pool<Jedis> 的子类;2. WxOpenInRedisConfigStorage 增加 keyPrefix 以支持可配置的前缀;

* 微信开放平台:增加小程序代码模板库管理

* 小程序:增加代码管理相关 API

* 小程序:增加修改服务器地址、成员管理 API

* 小程序:增加数据分析相关 API

* 微信开放平台:增加 HTTP proxy 机制

* #568 修复三方平台多次授权时,RefreshToken 没有刷新的问题

* fix 多次授权时,RefreshToken 没有刷新

* null 判断

* 发布3.0.4.BETA测试版本

* fix code

* #569 微信支付几个查询关闭对账下载相关接口增加重载方法,以方便客户端指定更多参数

* #578 微信开放平台增加 WxMaUserService 的实现

* 微信开放平台:1. WxOpenInRedisConfigStorage 支持 JedisPool/JedisSentinelPool 等 Pool<Jedis> 的子类;2. WxOpenInRedisConfigStorage 增加 keyPrefix 以支持可配置的前缀;

* 微信开放平台:增加小程序代码模板库管理

* 小程序:增加代码管理相关 API

* 小程序:增加修改服务器地址、成员管理 API

* 小程序:增加数据分析相关 API

* 微信开放平台:增加 HTTP proxy 机制

* 微信开放平台:增加 WxMaUserService 的实现

* 修复小程序码的相关方法命名:WxCode->WxaCode, WxCodeLimit -> WxaCodeUnlimit

* #556 日志信息中如果含有secret值的,将其值隐藏掉

* #585 小程序二维码支持is_hyaline参数生成透明背景二维码

* 发布3.0.5.BETA测试版本

* #584 修复企业付款到银行卡接口签名失败的问题

* 简化代码

* #586 微信支付 WxPayConfig增加支持byte数组方式设置证书

* #581 增加微信公众号错误信息枚举类WxMpErrorMsg,并提供方法,方便根据错误代码查询错误信息内容

* #555 修复微信支付服务商模式支付验证签名失败的问题

* #521 微信支付回调通知类WxPayOrderNotifyResult增加version参数

* #583 企业微信新增人员接口新增字段to_invite

* #583 企业微信通讯录管理增加邀请成员接口

* #587 企业微信几个接口增加个人二维码字段

* 修复字符

* 修复单元测试

* 发布3.0.6.BETA测试版本

* 重构WxError相关代码,自动根据代码补充错误中文说明

* 优化微信支付代码

* #584 修复企业付款queryEntPay签名失败问题

* #591 文件上传接口不自动关闭inputStream,由调用方自己控制

* #595 优化WxPayException

* 发布3.0.7.BETA测试版本

* 更新pom

* 优化代码

* #615 公众号客服消息添加 "发送小程序卡片" 类型

* 优化XStreamTransformer

* 微信支付模块jodd-http修改scope

* 发布3.0.8.BETA测试版本

* #623 群发接口增加clientmsgid

* add author for some files

* clean code

* 重构规范RequestExecuter代码

* #532 实现微信AI开放接口的三个接口:语音上传、查询识别结果和微信翻译功能

* 发布3.0.9.BETA测试版本

* #516 增加获取Wi-Fi门店列表接口

* #629 修复WxPayOrderNotifyResult解析xml报错问题

* #639 修复小程序代码模版库管理 access_token key 错误

* 发布3.1.0正式版本
This commit is contained in:
Binary Wang
2018-06-22 23:29:17 +08:00
committed by GitHub
parent 2d84939be0
commit 9d66d582db
304 changed files with 6960 additions and 1452 deletions

View File

@@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.util.json;
import com.google.gson.*;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.api.WxConsts.KefuMsgType;
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
import org.apache.commons.lang3.StringUtils;
@@ -79,6 +80,15 @@ public class WxMpKefuMessageGsonAdapter implements JsonSerializer<WxMpKefuMessag
messageJson.add("wxcard", wxcard);
}
if (KefuMsgType.MINIPROGRAMPAGE.equals(message.getMsgType())) {
JsonObject miniProgramPage = new JsonObject();
miniProgramPage.addProperty("title", message.getTitle());
miniProgramPage.addProperty("appid", message.getMiniProgramAppId());
miniProgramPage.addProperty("pagepath", message.getMiniProgramPagePath());
miniProgramPage.addProperty("thumb_media_id", message.getThumbMediaId());
messageJson.add("miniprogrampage", miniProgramPage);
}
if (StringUtils.isNotBlank(message.getKfAccount())) {
JsonObject newsJsonObject = new JsonObject();
newsJsonObject.addProperty("kf_account", message.getKfAccount());

View File

@@ -3,9 +3,13 @@ package me.chanjar.weixin.mp.util.json;
import com.google.gson.*;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage;
import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.Type;
/**
* @author someone
*/
public class WxMpMassOpenIdsMessageGsonAdapter implements JsonSerializer<WxMpMassOpenIdsMessage> {
@Override
@@ -45,6 +49,11 @@ public class WxMpMassOpenIdsMessageGsonAdapter implements JsonSerializer<WxMpMas
}
messageJson.addProperty("msgtype", message.getMsgType());
messageJson.addProperty("send_ignore_reprint", message.isSendIgnoreReprint() ? 0 : 1);
if(StringUtils.isNotEmpty(message.getClientMsgId())){
messageJson.addProperty("clientmsgid", message.getClientMsgId());
}
return messageJson;
}

View File

@@ -6,9 +6,13 @@ import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.mp.bean.WxMpMassTagMessage;
import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.Type;
/**
* @author someone
*/
public class WxMpMassTagMessageGsonAdapter implements JsonSerializer<WxMpMassTagMessage> {
@Override
@@ -51,6 +55,11 @@ public class WxMpMassTagMessageGsonAdapter implements JsonSerializer<WxMpMassTag
}
messageJson.addProperty("msgtype", message.getMsgType());
messageJson.addProperty("send_ignore_reprint", message.isSendIgnoreReprint() ? 0 : 1);
if (StringUtils.isNotEmpty(message.getClientMsgId())) {
messageJson.addProperty("clientmsgid", message.getClientMsgId());
}
return messageJson;
}

View File

@@ -23,7 +23,7 @@ public class WxMpTemplateMessageGsonAdapter implements JsonSerializer<WxMpTempla
if (message.getMiniProgram() != null) {
JsonObject miniProgramJson = new JsonObject();
miniProgramJson.addProperty("appid", message.getMiniProgram().getAppid());
miniProgramJson.addProperty("path", message.getMiniProgram().getPath());
miniProgramJson.addProperty("pagepath", message.getMiniProgram().getPagePath());
messageJson.add("miniprogram", miniProgramJson);
}

View File

@@ -33,6 +33,9 @@ public class WxMpUserGsonAdapter implements JsonDeserializer<WxMpUser> {
user.setGroupId(GsonHelper.getInteger(o, "groupid"));
user.setTagIds(GsonHelper.getLongArray(o, "tagid_list"));
user.setPrivileges(GsonHelper.getStringArray(o, "privilege"));
user.setSubscribeScene(GsonHelper.getString(o, "subscribe_scene"));
user.setQrScene(GsonHelper.getString(o, "qr_scene"));
user.setQrSceneStr(GsonHelper.getString(o, "qr_scene_str"));
Integer sex = GsonHelper.getInteger(o, "sex");
if (sex != null) {

View File

@@ -1,11 +1,11 @@
package me.chanjar.weixin.mp.util.http.apache;
package me.chanjar.weixin.mp.util.requestexecuter.material;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
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.apache.Utf8ResponseHandler;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.util.http.MaterialDeleteRequestExecutor;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -20,8 +20,8 @@ import java.util.Map;
/**
* Created by ecoolper on 2017/5/5.
*/
public class ApacheMaterialDeleteRequestExecutor extends MaterialDeleteRequestExecutor<CloseableHttpClient, HttpHost> {
public ApacheMaterialDeleteRequestExecutor(RequestHttp requestHttp) {
public class MaterialDeleteApacheHttpRequestExecutor extends MaterialDeleteRequestExecutor<CloseableHttpClient, HttpHost> {
public MaterialDeleteApacheHttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@@ -38,7 +38,7 @@ public class ApacheMaterialDeleteRequestExecutor extends MaterialDeleteRequestEx
httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) {
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
WxError error = WxError.fromJson(responseContent);
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {

View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.mp.util.http.jodd;
package me.chanjar.weixin.mp.util.requestexecuter.material;
import jodd.http.HttpConnectionProvider;
import jodd.http.HttpRequest;
@@ -6,18 +6,18 @@ import jodd.http.HttpResponse;
import jodd.http.ProxyInfo;
import jodd.util.StringPool;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
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.mp.util.http.MaterialDeleteRequestExecutor;
import java.io.IOException;
/**
* Created by ecoolper on 2017/5/5.
*/
public class JoddMaterialDeleteRequestExecutor extends MaterialDeleteRequestExecutor<HttpConnectionProvider, ProxyInfo> {
public JoddMaterialDeleteRequestExecutor(RequestHttp requestHttp) {
public class MaterialDeleteJoddHttpRequestExecutor extends MaterialDeleteRequestExecutor<HttpConnectionProvider, ProxyInfo> {
public MaterialDeleteJoddHttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@@ -33,7 +33,7 @@ public class JoddMaterialDeleteRequestExecutor extends MaterialDeleteRequestExec
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent);
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {

View File

@@ -1,10 +1,10 @@
package me.chanjar.weixin.mp.util.http.okhttp;
package me.chanjar.weixin.mp.util.requestexecuter.material;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
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.okhttp.OkHttpProxyInfo;
import me.chanjar.weixin.mp.util.http.MaterialDeleteRequestExecutor;
import okhttp3.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -14,17 +14,17 @@ import java.io.IOException;
/**
* Created by ecoolper on 2017/5/5.
*/
public class OkhttpMaterialDeleteRequestExecutor extends MaterialDeleteRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
public class MaterialDeleteOkhttpRequestExecutor extends MaterialDeleteRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public OkhttpMaterialDeleteRequestExecutor(RequestHttp requestHttp) {
public MaterialDeleteOkhttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@Override
public Boolean execute(String uri, String materialId) throws WxErrorException, IOException {
logger.debug("OkhttpMaterialDeleteRequestExecutor is running");
logger.debug("MaterialDeleteOkhttpRequestExecutor is running");
//得到httpClient
OkHttpClient client = requestHttp.getRequestHttpClient();
@@ -32,7 +32,7 @@ public class OkhttpMaterialDeleteRequestExecutor extends MaterialDeleteRequestEx
Request request = new Request.Builder().url(uri).post(requestBody).build();
Response response = client.newCall(request).execute();
String responseContent = response.body().string();
WxError error = WxError.fromJson(responseContent);
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {

View File

@@ -1,10 +1,7 @@
package me.chanjar.weixin.mp.util.http;
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.util.http.apache.ApacheMaterialDeleteRequestExecutor;
import me.chanjar.weixin.mp.util.http.jodd.JoddMaterialDeleteRequestExecutor;
import me.chanjar.weixin.mp.util.http.okhttp.OkhttpMaterialDeleteRequestExecutor;
public abstract class MaterialDeleteRequestExecutor<H, P> implements RequestExecutor<Boolean, String> {
protected RequestHttp<H, P> requestHttp;
@@ -16,11 +13,11 @@ public abstract class MaterialDeleteRequestExecutor<H, P> implements RequestExec
public static RequestExecutor<Boolean, String> create(RequestHttp requestHttp) {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheMaterialDeleteRequestExecutor(requestHttp);
return new MaterialDeleteApacheHttpRequestExecutor(requestHttp);
case JODD_HTTP:
return new JoddMaterialDeleteRequestExecutor(requestHttp);
return new MaterialDeleteJoddHttpRequestExecutor(requestHttp);
case OK_HTTP:
return new OkhttpMaterialDeleteRequestExecutor(requestHttp);
return new MaterialDeleteOkhttpRequestExecutor(requestHttp);
default:
return null;
}

View File

@@ -1,13 +1,13 @@
package me.chanjar.weixin.mp.util.http.apache;
package me.chanjar.weixin.mp.util.requestexecuter.material;
import com.google.common.collect.ImmutableMap;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
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.apache.Utf8ResponseHandler;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews;
import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
@@ -19,8 +19,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* httpclient 实现的素材请求执行器.
@@ -28,11 +26,11 @@ import java.util.Map;
* @author ecoolper
* @date 2017/5/5
*/
public class ApacheMaterialNewsInfoRequestExecutor
public class MaterialNewsInfoApacheHttpRequestExecutor
extends MaterialNewsInfoRequestExecutor<CloseableHttpClient, HttpHost> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public ApacheMaterialNewsInfoRequestExecutor(RequestHttp requestHttp) {
public MaterialNewsInfoApacheHttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@@ -48,7 +46,7 @@ public class ApacheMaterialNewsInfoRequestExecutor
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) {
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
this.logger.debug("响应原始数据:{}", responseContent);
WxError error = WxError.fromJson(responseContent);
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {

View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.mp.util.http.jodd;
package me.chanjar.weixin.mp.util.requestexecuter.material;
import com.google.common.collect.ImmutableMap;
import jodd.http.HttpConnectionProvider;
@@ -7,12 +7,12 @@ import jodd.http.HttpResponse;
import jodd.http.ProxyInfo;
import jodd.util.StringPool;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
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.json.WxGsonBuilder;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews;
import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -22,9 +22,9 @@ import java.io.IOException;
/**
* Created by ecoolper on 2017/5/5.
*/
public class JoddMaterialNewsInfoRequestExecutor extends MaterialNewsInfoRequestExecutor<HttpConnectionProvider, ProxyInfo> {
public class MaterialNewsInfoJoddHttpRequestExecutor extends MaterialNewsInfoRequestExecutor<HttpConnectionProvider, ProxyInfo> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public JoddMaterialNewsInfoRequestExecutor(RequestHttp requestHttp) {
public MaterialNewsInfoJoddHttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@@ -42,7 +42,7 @@ public class JoddMaterialNewsInfoRequestExecutor extends MaterialNewsInfoRequest
String responseContent = response.bodyText();
this.logger.debug("响应原始数据:{}", responseContent);
WxError error = WxError.fromJson(responseContent);
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {

View File

@@ -1,13 +1,13 @@
package me.chanjar.weixin.mp.util.http.okhttp;
package me.chanjar.weixin.mp.util.requestexecuter.material;
import com.google.common.collect.ImmutableMap;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
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.okhttp.OkHttpProxyInfo;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews;
import me.chanjar.weixin.mp.util.http.MaterialNewsInfoRequestExecutor;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import okhttp3.*;
import org.slf4j.Logger;
@@ -18,9 +18,9 @@ import java.io.IOException;
/**
* Created by ecoolper on 2017/5/5.
*/
public class OkhttpMaterialNewsInfoRequestExecutor extends MaterialNewsInfoRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
public class MaterialNewsInfoOkhttpRequestExecutor extends MaterialNewsInfoRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public OkhttpMaterialNewsInfoRequestExecutor(RequestHttp requestHttp) {
public MaterialNewsInfoOkhttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@@ -38,7 +38,7 @@ public class OkhttpMaterialNewsInfoRequestExecutor extends MaterialNewsInfoReque
String responseContent = response.body().string();
this.logger.debug("响应原始数据:{}", responseContent);
WxError error = WxError.fromJson(responseContent);
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {

View File

@@ -1,11 +1,8 @@
package me.chanjar.weixin.mp.util.http;
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.WxMpMaterialNews;
import me.chanjar.weixin.mp.util.http.apache.ApacheMaterialNewsInfoRequestExecutor;
import me.chanjar.weixin.mp.util.http.jodd.JoddMaterialNewsInfoRequestExecutor;
import me.chanjar.weixin.mp.util.http.okhttp.OkhttpMaterialNewsInfoRequestExecutor;
public abstract class MaterialNewsInfoRequestExecutor<H, P> implements RequestExecutor<WxMpMaterialNews, String> {
protected RequestHttp<H, P> requestHttp;
@@ -17,11 +14,11 @@ public abstract class MaterialNewsInfoRequestExecutor<H, P> implements RequestEx
public static RequestExecutor<WxMpMaterialNews, String> create(RequestHttp requestHttp) {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheMaterialNewsInfoRequestExecutor(requestHttp);
return new MaterialNewsInfoApacheHttpRequestExecutor(requestHttp);
case JODD_HTTP:
return new JoddMaterialNewsInfoRequestExecutor(requestHttp);
return new MaterialNewsInfoJoddHttpRequestExecutor(requestHttp);
case OK_HTTP:
return new OkhttpMaterialNewsInfoRequestExecutor(requestHttp);
return new MaterialNewsInfoOkhttpRequestExecutor(requestHttp);
default:
//TODO 需要优化抛出异常
return null;

View File

@@ -1,13 +1,13 @@
package me.chanjar.weixin.mp.util.http.apache;
package me.chanjar.weixin.mp.util.requestexecuter.material;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
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.apache.Utf8ResponseHandler;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.bean.material.WxMpMaterial;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialUploadResult;
import me.chanjar.weixin.mp.util.http.MaterialUploadRequestExecutor;
import org.apache.http.Consts;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
@@ -27,8 +27,8 @@ import java.util.Map;
/**
* Created by ecoolper on 2017/5/5.
*/
public class ApacheMaterialUploadRequestExecutor extends MaterialUploadRequestExecutor<CloseableHttpClient, HttpHost> {
public ApacheMaterialUploadRequestExecutor(RequestHttp requestHttp) {
public class MaterialUploadApacheHttpRequestExecutor extends MaterialUploadRequestExecutor<CloseableHttpClient, HttpHost> {
public MaterialUploadApacheHttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@@ -64,7 +64,7 @@ public class ApacheMaterialUploadRequestExecutor extends MaterialUploadRequestEx
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) {
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
WxError error = WxError.fromJson(responseContent);
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {

View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.mp.util.http.jodd;
package me.chanjar.weixin.mp.util.requestexecuter.material;
import jodd.http.HttpConnectionProvider;
import jodd.http.HttpRequest;
@@ -6,13 +6,13 @@ import jodd.http.HttpResponse;
import jodd.http.ProxyInfo;
import jodd.util.StringPool;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
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.json.WxGsonBuilder;
import me.chanjar.weixin.mp.bean.material.WxMpMaterial;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialUploadResult;
import me.chanjar.weixin.mp.util.http.MaterialUploadRequestExecutor;
import java.io.File;
import java.io.FileNotFoundException;
@@ -22,8 +22,8 @@ import java.util.Map;
/**
* Created by ecoolper on 2017/5/5.
*/
public class JoddMaterialUploadRequestExecutor extends MaterialUploadRequestExecutor<HttpConnectionProvider, ProxyInfo> {
public JoddMaterialUploadRequestExecutor(RequestHttp requestHttp) {
public class MaterialUploadJoddHttpRequestExecutor extends MaterialUploadRequestExecutor<HttpConnectionProvider, ProxyInfo> {
public MaterialUploadJoddHttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@@ -52,7 +52,7 @@ public class JoddMaterialUploadRequestExecutor extends MaterialUploadRequestExec
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent);
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {

View File

@@ -1,13 +1,13 @@
package me.chanjar.weixin.mp.util.http.okhttp;
package me.chanjar.weixin.mp.util.requestexecuter.material;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
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.okhttp.OkHttpProxyInfo;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.bean.material.WxMpMaterial;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialUploadResult;
import me.chanjar.weixin.mp.util.http.MaterialUploadRequestExecutor;
import okhttp3.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -20,16 +20,16 @@ import java.util.Map;
/**
* Created by ecoolper on 2017/5/5.
*/
public class OkhttpMaterialUploadRequestExecutor extends MaterialUploadRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
public class MaterialUploadOkhttpRequestExecutor extends MaterialUploadRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public OkhttpMaterialUploadRequestExecutor(RequestHttp requestHttp) {
public MaterialUploadOkhttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@Override
public WxMpMaterialUploadResult execute(String uri, WxMpMaterial material) throws WxErrorException, IOException {
logger.debug("OkhttpMaterialUploadRequestExecutor is running");
logger.debug("MaterialUploadOkhttpRequestExecutor is running");
if (material == null) {
throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("非法请求material参数为空").build());
}
@@ -55,7 +55,7 @@ public class OkhttpMaterialUploadRequestExecutor extends MaterialUploadRequestEx
Request request = new Request.Builder().url(uri).post(bodyBuilder.build()).build();
Response response = client.newCall(request).execute();
String responseContent = response.body().string();
WxError error = WxError.fromJson(responseContent);
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {

View File

@@ -1,13 +1,13 @@
package me.chanjar.weixin.mp.util.http;
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.WxMpMaterial;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialUploadResult;
import me.chanjar.weixin.mp.util.http.apache.ApacheMaterialUploadRequestExecutor;
import me.chanjar.weixin.mp.util.http.jodd.JoddMaterialUploadRequestExecutor;
import me.chanjar.weixin.mp.util.http.okhttp.OkhttpMaterialUploadRequestExecutor;
/**
* @author codepiano
*/
public abstract class MaterialUploadRequestExecutor<H, P> implements RequestExecutor<WxMpMaterialUploadResult, WxMpMaterial> {
protected RequestHttp<H, P> requestHttp;
@@ -18,11 +18,11 @@ public abstract class MaterialUploadRequestExecutor<H, P> implements RequestExec
public static RequestExecutor<WxMpMaterialUploadResult, WxMpMaterial> create(RequestHttp requestHttp) {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheMaterialUploadRequestExecutor(requestHttp);
return new MaterialUploadApacheHttpRequestExecutor(requestHttp);
case JODD_HTTP:
return new JoddMaterialUploadRequestExecutor(requestHttp);
return new MaterialUploadJoddHttpRequestExecutor(requestHttp);
case OK_HTTP:
return new OkhttpMaterialUploadRequestExecutor(requestHttp);
return new MaterialUploadOkhttpRequestExecutor(requestHttp);
default:
return null;
}

View File

@@ -1,12 +1,12 @@
package me.chanjar.weixin.mp.util.http.apache;
package me.chanjar.weixin.mp.util.requestexecuter.material;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
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.apache.Utf8ResponseHandler;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialVideoInfoResult;
import me.chanjar.weixin.mp.util.http.MaterialVideoInfoRequestExecutor;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -21,8 +21,8 @@ import java.util.Map;
/**
* Created by ecoolper on 2017/5/5.
*/
public class ApacheMaterialVideoInfoRequestExecutor extends MaterialVideoInfoRequestExecutor<CloseableHttpClient, HttpHost> {
public ApacheMaterialVideoInfoRequestExecutor(RequestHttp requestHttp) {
public class MaterialVideoInfoApacheHttpRequestExecutor extends MaterialVideoInfoRequestExecutor<CloseableHttpClient, HttpHost> {
public MaterialVideoInfoApacheHttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@@ -39,7 +39,7 @@ public class ApacheMaterialVideoInfoRequestExecutor extends MaterialVideoInfoReq
httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) {
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
WxError error = WxError.fromJson(responseContent);
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {

View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.mp.util.http.jodd;
package me.chanjar.weixin.mp.util.requestexecuter.material;
import jodd.http.HttpConnectionProvider;
import jodd.http.HttpRequest;
@@ -6,19 +6,19 @@ import jodd.http.HttpResponse;
import jodd.http.ProxyInfo;
import jodd.util.StringPool;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
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.mp.bean.material.WxMpMaterialVideoInfoResult;
import me.chanjar.weixin.mp.util.http.MaterialVideoInfoRequestExecutor;
import java.io.IOException;
/**
* Created by ecoolper on 2017/5/5.
*/
public class JoddMaterialVideoInfoRequestExecutor extends MaterialVideoInfoRequestExecutor<HttpConnectionProvider, ProxyInfo> {
public JoddMaterialVideoInfoRequestExecutor(RequestHttp requestHttp) {
public class MaterialVideoInfoJoddHttpRequestExecutor extends MaterialVideoInfoRequestExecutor<HttpConnectionProvider, ProxyInfo> {
public MaterialVideoInfoJoddHttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@@ -34,7 +34,7 @@ public class JoddMaterialVideoInfoRequestExecutor extends MaterialVideoInfoReque
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent);
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {

View File

@@ -1,11 +1,11 @@
package me.chanjar.weixin.mp.util.http.okhttp;
package me.chanjar.weixin.mp.util.requestexecuter.material;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
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.okhttp.OkHttpProxyInfo;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialVideoInfoResult;
import me.chanjar.weixin.mp.util.http.MaterialVideoInfoRequestExecutor;
import okhttp3.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -15,16 +15,16 @@ import java.io.IOException;
/**
* Created by ecoolper on 2017/5/5.
*/
public class OkhttpMaterialVideoInfoRequestExecutor extends MaterialVideoInfoRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
public class MaterialVideoInfoOkhttpRequestExecutor extends MaterialVideoInfoRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public OkhttpMaterialVideoInfoRequestExecutor(RequestHttp requestHttp) {
public MaterialVideoInfoOkhttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@Override
public WxMpMaterialVideoInfoResult execute(String uri, String materialId) throws WxErrorException, IOException {
logger.debug("OkhttpMaterialVideoInfoRequestExecutor is running");
logger.debug("MaterialVideoInfoOkhttpRequestExecutor is running");
//得到httpClient
OkHttpClient client = requestHttp.getRequestHttpClient();
@@ -32,7 +32,7 @@ public class OkhttpMaterialVideoInfoRequestExecutor extends MaterialVideoInfoReq
Request request = new Request.Builder().url(uri).post(requestBody).build();
Response response = client.newCall(request).execute();
String responseContent = response.body().string();
WxError error = WxError.fromJson(responseContent);
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {

View File

@@ -1,13 +1,10 @@
package me.chanjar.weixin.mp.util.http;
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 me.chanjar.weixin.mp.util.http.apache.ApacheMaterialVideoInfoRequestExecutor;
import me.chanjar.weixin.mp.util.http.jodd.JoddMaterialVideoInfoRequestExecutor;
import me.chanjar.weixin.mp.util.http.okhttp.OkhttpMaterialVideoInfoRequestExecutor;
public abstract class MaterialVideoInfoRequestExecutor<H, P> implements RequestExecutor<WxMpMaterialVideoInfoResult, String> {
@@ -20,11 +17,11 @@ public abstract class MaterialVideoInfoRequestExecutor<H, P> implements RequestE
public static RequestExecutor<WxMpMaterialVideoInfoResult, String> create(RequestHttp requestHttp) {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheMaterialVideoInfoRequestExecutor(requestHttp);
return new MaterialVideoInfoApacheHttpRequestExecutor(requestHttp);
case JODD_HTTP:
return new JoddMaterialVideoInfoRequestExecutor(requestHttp);
return new MaterialVideoInfoJoddHttpRequestExecutor(requestHttp);
case OK_HTTP:
return new OkhttpMaterialVideoInfoRequestExecutor(requestHttp);
return new MaterialVideoInfoOkhttpRequestExecutor(requestHttp);
default:
return null;
}

View File

@@ -1,11 +1,10 @@
package me.chanjar.weixin.mp.util.http.apache;
package me.chanjar.weixin.mp.util.requestexecuter.material;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
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.apache.InputStreamResponseHandler;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.util.http.MaterialVoiceAndImageDownloadRequestExecutor;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
@@ -25,8 +24,8 @@ import java.util.Map;
/**
* Created by ecoolper on 2017/5/5.
*/
public class ApacheMaterialVoiceAndImageDownloadRequestExecutor extends MaterialVoiceAndImageDownloadRequestExecutor<CloseableHttpClient, HttpHost> {
public ApacheMaterialVoiceAndImageDownloadRequestExecutor(RequestHttp requestHttp, File tmpDirFile) {
public class MaterialVoiceAndImageDownloadApacheHttpRequestExecutor extends MaterialVoiceAndImageDownloadRequestExecutor<CloseableHttpClient, HttpHost> {
public MaterialVoiceAndImageDownloadApacheHttpRequestExecutor(RequestHttp requestHttp, File tmpDirFile) {
super(requestHttp, tmpDirFile);
}

View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.mp.util.http.jodd;
package me.chanjar.weixin.mp.util.requestexecuter.material;
import jodd.http.HttpConnectionProvider;
import jodd.http.HttpRequest;
@@ -6,11 +6,10 @@ import jodd.http.HttpResponse;
import jodd.http.ProxyInfo;
import jodd.util.StringPool;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
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.json.WxGsonBuilder;
import me.chanjar.weixin.mp.util.http.MaterialVoiceAndImageDownloadRequestExecutor;
import org.apache.commons.io.IOUtils;
import java.io.ByteArrayInputStream;
@@ -22,8 +21,8 @@ import java.nio.charset.StandardCharsets;
/**
* Created by ecoolper on 2017/5/5.
*/
public class JoddMaterialVoiceAndImageDownloadRequestExecutor extends MaterialVoiceAndImageDownloadRequestExecutor<HttpConnectionProvider, ProxyInfo> {
public JoddMaterialVoiceAndImageDownloadRequestExecutor(RequestHttp requestHttp, File tmpDirFile) {
public class MaterialVoiceAndImageDownloadJoddHttpRequestExecutor extends MaterialVoiceAndImageDownloadRequestExecutor<HttpConnectionProvider, ProxyInfo> {
public MaterialVoiceAndImageDownloadJoddHttpRequestExecutor(RequestHttp requestHttp, File tmpDirFile) {
super(requestHttp, tmpDirFile);
}

View File

@@ -1,15 +1,13 @@
package me.chanjar.weixin.mp.util.http.okhttp;
package me.chanjar.weixin.mp.util.requestexecuter.material;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
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.okhttp.OkHttpProxyInfo;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.util.http.MaterialVoiceAndImageDownloadRequestExecutor;
import okhttp3.*;
import okio.BufferedSink;
import okio.Okio;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -18,16 +16,16 @@ import java.io.*;
/**
* Created by ecoolper on 2017/5/5.
*/
public class OkhttpMaterialVoiceAndImageDownloadRequestExecutor extends MaterialVoiceAndImageDownloadRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
public class MaterialVoiceAndImageDownloadOkhttpRequestExecutor extends MaterialVoiceAndImageDownloadRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public OkhttpMaterialVoiceAndImageDownloadRequestExecutor(RequestHttp requestHttp, File tmpDirFile) {
public MaterialVoiceAndImageDownloadOkhttpRequestExecutor(RequestHttp requestHttp, File tmpDirFile) {
super(requestHttp, tmpDirFile);
}
@Override
public InputStream execute(String uri, String materialId) throws WxErrorException, IOException {
logger.debug("OkhttpMaterialVoiceAndImageDownloadRequestExecutor is running");
logger.debug("MaterialVoiceAndImageDownloadOkhttpRequestExecutor is running");
OkHttpClient client = requestHttp.getRequestHttpClient();
RequestBody requestBody = new FormBody.Builder().add("media_id", materialId).build();
Request request = new Request.Builder().url(uri).get().post(requestBody).build();
@@ -35,7 +33,7 @@ public class OkhttpMaterialVoiceAndImageDownloadRequestExecutor extends Material
String contentTypeHeader = response.header("Content-Type");
if ("text/plain".equals(contentTypeHeader)) {
String responseContent = response.body().string();
throw new WxErrorException(WxError.fromJson(responseContent));
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
}
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BufferedSink sink = Okio.buffer(Okio.sink(outputStream))) {
sink.writeAll(response.body().source());

View File

@@ -1,10 +1,7 @@
package me.chanjar.weixin.mp.util.http;
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.util.http.apache.ApacheMaterialVoiceAndImageDownloadRequestExecutor;
import me.chanjar.weixin.mp.util.http.jodd.JoddMaterialVoiceAndImageDownloadRequestExecutor;
import me.chanjar.weixin.mp.util.http.okhttp.OkhttpMaterialVoiceAndImageDownloadRequestExecutor;
import java.io.File;
import java.io.InputStream;
@@ -22,11 +19,11 @@ public abstract class MaterialVoiceAndImageDownloadRequestExecutor<H, P>
public static RequestExecutor<InputStream, String> create(RequestHttp requestHttp, File tmpDirFile) {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheMaterialVoiceAndImageDownloadRequestExecutor(requestHttp, tmpDirFile);
return new MaterialVoiceAndImageDownloadApacheHttpRequestExecutor(requestHttp, tmpDirFile);
case JODD_HTTP:
return new JoddMaterialVoiceAndImageDownloadRequestExecutor(requestHttp, tmpDirFile);
return new MaterialVoiceAndImageDownloadJoddHttpRequestExecutor(requestHttp, tmpDirFile);
case OK_HTTP:
return new OkhttpMaterialVoiceAndImageDownloadRequestExecutor(requestHttp, tmpDirFile);
return new MaterialVoiceAndImageDownloadOkhttpRequestExecutor(requestHttp, tmpDirFile);
default:
return null;
}

View File

@@ -1,11 +1,11 @@
package me.chanjar.weixin.mp.util.http.apache;
package me.chanjar.weixin.mp.util.requestexecuter.media;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
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.apache.Utf8ResponseHandler;
import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult;
import me.chanjar.weixin.mp.util.http.MediaImgUploadRequestExecutor;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
@@ -21,9 +21,11 @@ import java.io.IOException;
/**
* Created by ecoolper on 2017/5/5.
*
* @author ecoolper
*/
public class ApacheMediaImgUploadRequestExecutor extends MediaImgUploadRequestExecutor<CloseableHttpClient, HttpHost> {
public ApacheMediaImgUploadRequestExecutor(RequestHttp requestHttp) {
public class MediaImgUploadApacheHttpRequestExecutor extends MediaImgUploadRequestExecutor<CloseableHttpClient, HttpHost> {
public MediaImgUploadApacheHttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@@ -49,7 +51,7 @@ public class ApacheMediaImgUploadRequestExecutor extends MediaImgUploadRequestEx
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) {
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
WxError error = WxError.fromJson(responseContent);
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}

View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.mp.util.http.jodd;
package me.chanjar.weixin.mp.util.requestexecuter.media;
import jodd.http.HttpConnectionProvider;
import jodd.http.HttpRequest;
@@ -6,20 +6,22 @@ import jodd.http.HttpResponse;
import jodd.http.ProxyInfo;
import jodd.util.StringPool;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
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.mp.bean.material.WxMediaImgUploadResult;
import me.chanjar.weixin.mp.util.http.MediaImgUploadRequestExecutor;
import java.io.File;
import java.io.IOException;
/**
* Created by ecoolper on 2017/5/5.
*
* @author ecoolper
*/
public class JoddMediaImgUploadRequestExecutor extends MediaImgUploadRequestExecutor<HttpConnectionProvider, ProxyInfo> {
public JoddMediaImgUploadRequestExecutor(RequestHttp requestHttp) {
public class MediaImgUploadHttpRequestExecutor extends MediaImgUploadRequestExecutor<HttpConnectionProvider, ProxyInfo> {
public MediaImgUploadHttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@@ -39,7 +41,7 @@ public class JoddMediaImgUploadRequestExecutor extends MediaImgUploadRequestExec
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent);
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}

View File

@@ -1,11 +1,11 @@
package me.chanjar.weixin.mp.util.http.okhttp;
package me.chanjar.weixin.mp.util.requestexecuter.media;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
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.okhttp.OkHttpProxyInfo;
import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult;
import me.chanjar.weixin.mp.util.http.MediaImgUploadRequestExecutor;
import okhttp3.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -15,17 +15,19 @@ import java.io.IOException;
/**
* Created by ecoolper on 2017/5/5.
*
* @author ecoolper
*/
public class OkhttpMediaImgUploadRequestExecutor extends MediaImgUploadRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
public class MediaImgUploadOkhttpRequestExecutor extends MediaImgUploadRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public OkhttpMediaImgUploadRequestExecutor(RequestHttp requestHttp) {
public MediaImgUploadOkhttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@Override
public WxMediaImgUploadResult execute(String uri, File file) throws WxErrorException, IOException {
logger.debug("OkhttpMediaImgUploadRequestExecutor is running");
logger.debug("MediaImgUploadOkhttpRequestExecutor is running");
//得到httpClient
OkHttpClient client = requestHttp.getRequestHttpClient();
@@ -39,7 +41,7 @@ public class OkhttpMediaImgUploadRequestExecutor extends MediaImgUploadRequestEx
Request request = new Request.Builder().url(uri).post(body).build();
Response response = client.newCall(request).execute();
String responseContent = response.body().string();
WxError error = WxError.fromJson(responseContent);
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}

View File

@@ -1,11 +1,8 @@
package me.chanjar.weixin.mp.util.http;
package me.chanjar.weixin.mp.util.requestexecuter.media;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult;
import me.chanjar.weixin.mp.util.http.apache.ApacheMediaImgUploadRequestExecutor;
import me.chanjar.weixin.mp.util.http.jodd.JoddMediaImgUploadRequestExecutor;
import me.chanjar.weixin.mp.util.http.okhttp.OkhttpMediaImgUploadRequestExecutor;
import java.io.File;
@@ -22,11 +19,11 @@ public abstract class MediaImgUploadRequestExecutor<H, P> implements RequestExec
public static RequestExecutor<WxMediaImgUploadResult, File> create(RequestHttp requestHttp) {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheMediaImgUploadRequestExecutor(requestHttp);
return new MediaImgUploadApacheHttpRequestExecutor(requestHttp);
case JODD_HTTP:
return new JoddMediaImgUploadRequestExecutor(requestHttp);
return new MediaImgUploadHttpRequestExecutor(requestHttp);
case OK_HTTP:
return new OkhttpMediaImgUploadRequestExecutor(requestHttp);
return new MediaImgUploadOkhttpRequestExecutor(requestHttp);
default:
return null;
}

View File

@@ -1,13 +1,13 @@
package me.chanjar.weixin.mp.util.http.apache;
package me.chanjar.weixin.mp.util.requestexecuter.qrcode;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
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.Utf8ResponseHandler;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
@@ -25,8 +25,8 @@ import java.util.UUID;
/**
* Created by ecoolper on 2017/5/5.
*/
public class ApacheQrCodeRequestExecutor extends QrCodeRequestExecutor<CloseableHttpClient, HttpHost> {
public ApacheQrCodeRequestExecutor(RequestHttp requestHttp) {
public class QrCodeApacheHttpRequestExecutor extends QrCodeRequestExecutor<CloseableHttpClient, HttpHost> {
public QrCodeApacheHttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@@ -55,7 +55,7 @@ public class ApacheQrCodeRequestExecutor extends QrCodeRequestExecutor<Closeable
if (ContentType.TEXT_PLAIN.getMimeType()
.equals(ContentType.parse(contentTypeHeader[0].getValue()).getMimeType())) {
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
throw new WxErrorException(WxError.fromJson(responseContent));
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
}
}
return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg");

View File

@@ -1,4 +1,4 @@
package me.chanjar.weixin.mp.util.http.jodd;
package me.chanjar.weixin.mp.util.requestexecuter.qrcode;
import jodd.http.HttpConnectionProvider;
import jodd.http.HttpRequest;
@@ -7,12 +7,12 @@ import jodd.http.ProxyInfo;
import jodd.util.MimeTypes;
import jodd.util.StringPool;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -24,8 +24,8 @@ import java.util.UUID;
/**
* Created by ecoolper on 2017/5/5.
*/
public class JoddQrCodeRequestExecutor extends QrCodeRequestExecutor<HttpConnectionProvider, ProxyInfo> {
public JoddQrCodeRequestExecutor(RequestHttp requestHttp) {
public class QrCodeJoddHttpRequestExecutor extends QrCodeRequestExecutor<HttpConnectionProvider, ProxyInfo> {
public QrCodeJoddHttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@@ -51,7 +51,7 @@ public class JoddQrCodeRequestExecutor extends QrCodeRequestExecutor<HttpConnect
String contentTypeHeader = response.header("Content-Type");
if (MimeTypes.MIME_TEXT_PLAIN.equals(contentTypeHeader)) {
String responseContent = response.bodyText();
throw new WxErrorException(WxError.fromJson(responseContent));
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
}
try (InputStream inputStream = new ByteArrayInputStream(response.bodyBytes())) {
return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg");

View File

@@ -1,12 +1,12 @@
package me.chanjar.weixin.mp.util.http.okhttp;
package me.chanjar.weixin.mp.util.requestexecuter.qrcode;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
@@ -24,16 +24,16 @@ import java.util.UUID;
* @author ecoolper
* @date 2017/5/5
*/
public class OkhttpQrCodeRequestExecutor extends QrCodeRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
public class QrCodeOkhttpRequestExecutor extends QrCodeRequestExecutor<OkHttpClient, OkHttpProxyInfo> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public OkhttpQrCodeRequestExecutor(RequestHttp requestHttp) {
public QrCodeOkhttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@Override
public File execute(String uri, WxMpQrCodeTicket ticket) throws WxErrorException, IOException {
logger.debug("OkhttpQrCodeRequestExecutor is running");
logger.debug("QrCodeOkhttpRequestExecutor is running");
if (ticket != null) {
if (uri.indexOf('?') == -1) {
@@ -50,7 +50,7 @@ public class OkhttpQrCodeRequestExecutor extends QrCodeRequestExecutor<OkHttpCli
String contentTypeHeader = response.header("Content-Type");
if ("text/plain".equals(contentTypeHeader)) {
String responseContent = response.body().string();
throw new WxErrorException(WxError.fromJson(responseContent));
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
}
try (InputStream inputStream = response.body().byteStream()) {

View File

@@ -1,13 +1,10 @@
package me.chanjar.weixin.mp.util.http;
package me.chanjar.weixin.mp.util.requestexecuter.qrcode;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.error.WxError;
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.mp.bean.result.WxMpQrCodeTicket;
import me.chanjar.weixin.mp.util.http.apache.ApacheQrCodeRequestExecutor;
import me.chanjar.weixin.mp.util.http.jodd.JoddQrCodeRequestExecutor;
import me.chanjar.weixin.mp.util.http.okhttp.OkhttpQrCodeRequestExecutor;
import java.io.File;
@@ -26,11 +23,11 @@ public abstract class QrCodeRequestExecutor<H, P> implements RequestExecutor<Fil
public static RequestExecutor<File, WxMpQrCodeTicket> create(RequestHttp requestHttp) throws WxErrorException {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new ApacheQrCodeRequestExecutor(requestHttp);
return new QrCodeApacheHttpRequestExecutor(requestHttp);
case JODD_HTTP:
return new JoddQrCodeRequestExecutor(requestHttp);
return new QrCodeJoddHttpRequestExecutor(requestHttp);
case OK_HTTP:
return new OkhttpQrCodeRequestExecutor(requestHttp);
return new QrCodeOkhttpRequestExecutor(requestHttp);
default:
throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("不支持的http框架").build());
}

View File

@@ -0,0 +1,65 @@
package me.chanjar.weixin.mp.util.requestexecuter.voice;
import me.chanjar.weixin.common.WxType;
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.apache.Utf8ResponseHandler;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import java.io.File;
import java.io.IOException;
/**
* <pre>
* Created by BinaryWang on 2018/6/9.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public class VoiceUploadApacheHttpRequestExecutor extends VoiceUploadRequestExecutor<CloseableHttpClient, HttpHost> {
public VoiceUploadApacheHttpRequestExecutor(RequestHttp requestHttp) {
super(requestHttp);
}
@Override
public Boolean execute(String uri, File data) throws WxErrorException, IOException {
if (data == null) {
throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("文件对象为空").build());
}
HttpPost httpPost = new HttpPost(uri);
if (requestHttp.getRequestHttpProxy() != null) {
RequestConfig config = RequestConfig.custom().setProxy(requestHttp.getRequestHttpProxy()).build();
httpPost.setConfig(config);
}
HttpEntity entity = MultipartEntityBuilder
.create()
.addBinaryBody("media", data)
.setMode(HttpMultipartMode.RFC6532)
.build();
httpPost.setEntity(entity);
httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString());
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) {
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return true;
} finally {
httpPost.releaseConnection();
}
}
}

View File

@@ -0,0 +1,33 @@
package me.chanjar.weixin.mp.util.requestexecuter.voice;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.RequestHttp;
import java.io.File;
/**
* <pre>
* Created by BinaryWang on 2018/6/9.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public abstract class VoiceUploadRequestExecutor<H, P> implements RequestExecutor<Boolean, File> {
protected RequestHttp<H, P> requestHttp;
public VoiceUploadRequestExecutor(RequestHttp requestHttp) {
this.requestHttp = requestHttp;
}
public static RequestExecutor<Boolean, File> create(RequestHttp requestHttp) {
switch (requestHttp.getRequestType()) {
case APACHE_HTTP:
return new VoiceUploadApacheHttpRequestExecutor(requestHttp);
case JODD_HTTP:
case OK_HTTP:
default:
return null;
}
}
}

View File

@@ -71,7 +71,6 @@ public class XStreamTransformer {
*/
private static void registerClass(Class<?> clz) {
XStream xstream = XStreamInitializer.getInstance();
xstream.setClassLoader(Thread.currentThread().getContextClassLoader());
xstream.processAnnotations(clz);
xstream.processAnnotations(getInnerClasses(clz));