mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
合并 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:
@@ -0,0 +1,29 @@
|
||||
package me.chanjar.weixin.mp;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* AI开放接口里的语言类型,目前只支持两种:中文和英文
|
||||
* Created by BinaryWang on 2018/6/10.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@Getter
|
||||
public enum AiLangType {
|
||||
/**
|
||||
* 中文 汉语
|
||||
*/
|
||||
zh_CN("zh_CN"),
|
||||
/**
|
||||
* 英文 英语
|
||||
*/
|
||||
en_US("en_US");
|
||||
|
||||
private String code;
|
||||
|
||||
AiLangType(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.AiLangType;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信AI开放接口(语音识别,微信翻译).
|
||||
* https://mp.weixin.qq.com/wiki?t=resource/res_main&id=21516712282KzWVE
|
||||
* Created by BinaryWang on 2018/6/9.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public interface WxMpAiOpenService {
|
||||
String VOICE_UPLOAD_URL = "http://api.weixin.qq.com/cgi-bin/media/voice/addvoicetorecofortext?format=%s&voice_id=%s&lang=%s";
|
||||
String VOICE_QUERY_RESULT_URL = "http://api.weixin.qq.com/cgi-bin/media/voice/queryrecoresultfortext";
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 提交语音.
|
||||
* 接口调用请求说明
|
||||
*
|
||||
* http请求方式: POST
|
||||
* http://api.weixin.qq.com/cgi-bin/media/voice/addvoicetorecofortext?access_token=ACCESS_TOKEN&format=&voice_id=xxxxxx&lang=zh_CN
|
||||
* 参数说明
|
||||
*
|
||||
* 参数 是否必须 说明
|
||||
* access_token 是 接口调用凭证
|
||||
* format 是 文件格式 (只支持mp3,16k,单声道,最大1M)
|
||||
* voice_id 是 语音唯一标识
|
||||
* lang 否 语言,zh_CN 或 en_US,默认中文
|
||||
* 语音内容放body里或者上传文件的形式
|
||||
* </pre>
|
||||
*
|
||||
* @param lang 语言,zh_CN 或 en_US,默认中文
|
||||
* @param voiceFile 语音文件
|
||||
* @param voiceId 语音唯一标识
|
||||
*/
|
||||
void uploadVoice(String voiceId, AiLangType lang, File voiceFile) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取语音识别结果.
|
||||
* 接口调用请求说明
|
||||
*
|
||||
* http请求方式: POST
|
||||
* http://api.weixin.qq.com/cgi-bin/media/voice/queryrecoresultfortext?access_token=ACCESS_TOKEN&voice_id=xxxxxx&lang=zh_CN
|
||||
* 请注意,添加完文件之后10s内调用这个接口
|
||||
*
|
||||
* 参数说明
|
||||
*
|
||||
* 参数 是否必须 说明
|
||||
* access_token 是 接口调用凭证
|
||||
* voice_id 是 语音唯一标识
|
||||
* lang 否 语言,zh_CN 或 en_US,默认中文
|
||||
* </pre>
|
||||
*
|
||||
* @param lang 语言,zh_CN 或 en_US,默认中文
|
||||
* @param voiceId 语音唯一标识
|
||||
*/
|
||||
String queryRecognitionResult(String voiceId, AiLangType lang) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 识别指定语音文件内容.
|
||||
* 此方法揉合了前两两个方法:uploadVoice 和 queryRecognitionResult
|
||||
*
|
||||
* @param lang 语言,zh_CN 或 en_US,默认中文
|
||||
* @param voiceFile 语音文件
|
||||
* @param voiceId 语音唯一标识
|
||||
*/
|
||||
String recogniseVoice(String voiceId, AiLangType lang, File voiceFile) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信翻译.
|
||||
* 接口调用请求说明
|
||||
*
|
||||
* http请求方式: POST
|
||||
* http://api.weixin.qq.com/cgi-bin/media/voice/translatecontent?access_token=ACCESS_TOKEN&lfrom=xxx<o=xxx
|
||||
* 参数说明
|
||||
*
|
||||
* 参数 是否必须 说明
|
||||
* access_token 是 接口调用凭证
|
||||
* lfrom 是 源语言,zh_CN 或 en_US
|
||||
* lto 是 目标语言,zh_CN 或 en_US
|
||||
* 源内容放body里或者上传文件的形式(utf8格式,最大600Byte)
|
||||
* </pre>
|
||||
*
|
||||
* @param langFrom 源语言,zh_CN 或 en_US
|
||||
* @param langTo 目标语言,zh_CN 或 en_US
|
||||
* @param content 要翻译的文本内容
|
||||
*/
|
||||
String translate(AiLangType langFrom, AiLangType langTo, String content) throws WxErrorException;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.bean.WxCardApiSignature;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpCardResult;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.datacube.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.device.*;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
|
||||
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest;
|
||||
import me.chanjar.weixin.mp.bean.kefu.result.*;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.*;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.material.*;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardActivatedMessage;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUpdateMessage;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUpdateResult;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.bean.menu.WxMenu;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
|
||||
import me.chanjar.weixin.mp.bean.menu.WxMpMenu;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
|
||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
|
||||
|
||||
|
||||
@@ -75,6 +75,29 @@ public class WxMpMessageRouter {
|
||||
this.exceptionHandler = new LogExceptionHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 使用自定义的 {@link ExecutorService}
|
||||
* </pre>
|
||||
*/
|
||||
public WxMpMessageRouter(WxMpService wxMpService, ExecutorService executorService) {
|
||||
this.wxMpService = wxMpService;
|
||||
this.executorService = executorService;
|
||||
this.messageDuplicateChecker = new WxMessageInMemoryDuplicateChecker();
|
||||
this.sessionManager = new StandardSessionManager();
|
||||
this.exceptionHandler = new LogExceptionHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 如果使用默认的 {@link ExecutorService},则系统退出前,应该调用该方法。
|
||||
* </pre>
|
||||
*/
|
||||
public void shutDownExecutorService() {
|
||||
this.executorService.shutdown();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 设置自定义的 {@link ExecutorService}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
|
||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.RequestHttp;
|
||||
@@ -58,7 +58,7 @@ public interface WxMpService {
|
||||
/**
|
||||
* oauth2授权的url连接
|
||||
*/
|
||||
String CONNECT_OAUTH2_AUTHORIZE_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s#wechat_redirect";
|
||||
String CONNECT_OAUTH2_AUTHORIZE_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=%s&state=%s&connect_redirect=1#wechat_redirect";
|
||||
|
||||
/**
|
||||
* 获取公众号的自动回复规则
|
||||
@@ -408,6 +408,20 @@ public interface WxMpService {
|
||||
*/
|
||||
WxMpMassMessageService getMassMessageService();
|
||||
|
||||
/**
|
||||
* 返回AI开放接口方法的实现类对象,以方便调用其各个接口
|
||||
*
|
||||
* @return WxMpAiOpenService
|
||||
*/
|
||||
WxMpAiOpenService getAiOpenService();
|
||||
|
||||
/**
|
||||
* 返回WIFI接口方法的实现类对象,以方便调用其各个接口
|
||||
*
|
||||
* @return WxMpWifiService
|
||||
*/
|
||||
WxMpWifiService getWifiService();
|
||||
|
||||
void setKefuService(WxMpKefuService kefuService);
|
||||
|
||||
void setMaterialService(WxMpMaterialService materialService);
|
||||
@@ -437,4 +451,6 @@ public interface WxMpService {
|
||||
void setMemberCardService(WxMpMemberCardService memberCardService);
|
||||
|
||||
void setMassMessageService(WxMpMassMessageService massMessageService);
|
||||
|
||||
void setAiOpenService(WxMpAiOpenService aiOpenService);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
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.mp.bean.WxMpShakeInfoResult;
|
||||
import me.chanjar.weixin.mp.bean.WxMpShakeQuery;
|
||||
import me.chanjar.weixin.mp.bean.shake.*;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo;
|
||||
import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo;
|
||||
import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.subscribe.WxMpSubscribeMessage;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
|
||||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry;
|
||||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.WxMpUserQuery;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.tag.WxTagListUser;
|
||||
import me.chanjar.weixin.mp.bean.tag.WxUserTag;
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopListResult;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信连接WI-FI接口.
|
||||
* Created by BinaryWang on 2018/6/10.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public interface WxMpWifiService {
|
||||
/**
|
||||
* <pre>
|
||||
* 获取Wi-Fi门店列表.
|
||||
* 通过此接口获取WiFi的门店列表,该列表包括公众平台的门店信息、以及添加设备后的WiFi相关信息。创建门店方法请参考“微信门店接口”。
|
||||
* 注:微信连Wi-Fi下的所有接口中的shop_id,必需先通过此接口获取。
|
||||
*
|
||||
* http请求方式: POST
|
||||
* 请求URL:https://api.weixin.qq.com/bizwifi/shop/list?access_token=ACCESS_TOKEN
|
||||
* </pre>
|
||||
* @param pageIndex 分页下标,默认从1开始
|
||||
* @param pageSize 每页的个数,默认10个,最大20个
|
||||
*/
|
||||
WxMpWifiShopListResult listShop(int pageIndex, int pageSize) throws WxErrorException;
|
||||
}
|
||||
@@ -5,10 +5,11 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
||||
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.session.StandardSessionManager;
|
||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.common.util.DataUtils;
|
||||
import me.chanjar.weixin.common.util.RandomUtils;
|
||||
import me.chanjar.weixin.common.util.crypto.SHA1;
|
||||
import me.chanjar.weixin.common.util.http.*;
|
||||
@@ -25,11 +26,14 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
public abstract class WxMpServiceBaseImpl<H, P> implements WxMpService, RequestHttp<H, P> {
|
||||
|
||||
/**
|
||||
* @author someone
|
||||
*/
|
||||
public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestHttp<H, P> {
|
||||
private static final JsonParser JSON_PARSER = new JsonParser();
|
||||
|
||||
protected final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
protected WxSessionManager sessionManager = new StandardSessionManager();
|
||||
protected WxMpConfigStorage wxMpConfigStorage;
|
||||
private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this);
|
||||
@@ -48,6 +52,8 @@ public abstract class WxMpServiceBaseImpl<H, P> implements WxMpService, RequestH
|
||||
private WxMpShakeService shakeService = new WxMpShakeServiceImpl(this);
|
||||
private WxMpMemberCardService memberCardService = new WxMpMemberCardServiceImpl(this);
|
||||
private WxMpMassMessageService massMessageService = new WxMpMassMessageServiceImpl(this);
|
||||
private WxMpAiOpenService aiOpenService = new WxMpAiOpenServiceImpl(this);
|
||||
private WxMpWifiService wifiService = new WxMpWifiServiceImpl(this);
|
||||
|
||||
private int retrySleepMillis = 1000;
|
||||
private int maxRetryTimes = 5;
|
||||
@@ -265,6 +271,8 @@ public abstract class WxMpServiceBaseImpl<H, P> implements WxMpService, RequestH
|
||||
}
|
||||
|
||||
public <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {
|
||||
E dataForLog = DataUtils.handleDataWithSecret(data);
|
||||
|
||||
if (uri.contains("access_token=")) {
|
||||
throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri);
|
||||
}
|
||||
@@ -275,7 +283,7 @@ public abstract class WxMpServiceBaseImpl<H, P> implements WxMpService, RequestH
|
||||
|
||||
try {
|
||||
T result = executor.execute(uriWithAccessToken, data);
|
||||
this.log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, data, result);
|
||||
this.log.debug("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", uriWithAccessToken, dataForLog, result);
|
||||
return result;
|
||||
} catch (WxErrorException e) {
|
||||
WxError error = e.getError();
|
||||
@@ -294,12 +302,12 @@ public abstract class WxMpServiceBaseImpl<H, P> implements WxMpService, RequestH
|
||||
}
|
||||
|
||||
if (error.getErrorCode() != 0) {
|
||||
this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, data, error);
|
||||
this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【错误信息】:{}", uriWithAccessToken, dataForLog, error);
|
||||
throw new WxErrorException(error, e);
|
||||
}
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, data, e.getMessage());
|
||||
this.log.error("\n【请求地址】: {}\n【请求参数】:{}\n【异常信息】:{}", uriWithAccessToken, dataForLog, e.getMessage());
|
||||
throw new WxErrorException(WxError.builder().errorMsg(e.getMessage()).build(), e);
|
||||
}
|
||||
}
|
||||
@@ -484,4 +492,19 @@ public abstract class WxMpServiceBaseImpl<H, P> implements WxMpService, RequestH
|
||||
public void setMassMessageService(WxMpMassMessageService massMessageService) {
|
||||
this.massMessageService = massMessageService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpAiOpenService getAiOpenService() {
|
||||
return this.aiOpenService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAiOpenService(WxMpAiOpenService aiOpenService) {
|
||||
this.aiOpenService = aiOpenService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpWifiService getWifiService() {
|
||||
return this.wifiService;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import me.chanjar.weixin.common.WxType;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.AiLangType;
|
||||
import me.chanjar.weixin.mp.api.WxMpAiOpenService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.util.requestexecuter.voice.VoiceUploadRequestExecutor;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by BinaryWang on 2018/6/9.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public class WxMpAiOpenServiceImpl implements WxMpAiOpenService {
|
||||
|
||||
private static final JsonParser JSON_PARSER = new JsonParser();
|
||||
public static final String TRANSLATE_URL = "http://api.weixin.qq.com/cgi-bin/media/voice/translatecontent?lfrom=%s<o=%s";
|
||||
private WxMpService wxMpService;
|
||||
|
||||
public WxMpAiOpenServiceImpl(WxMpService wxMpService) {
|
||||
this.wxMpService = wxMpService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadVoice(String voiceId, AiLangType lang, File voiceFile) throws WxErrorException {
|
||||
if (lang == null) {
|
||||
lang = AiLangType.zh_CN;
|
||||
}
|
||||
|
||||
this.wxMpService.execute(VoiceUploadRequestExecutor.create(this.wxMpService.getRequestHttp()),
|
||||
String.format(VOICE_UPLOAD_URL, "mp3", voiceId, lang.getCode()),
|
||||
voiceFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String recogniseVoice(String voiceId, AiLangType lang, File voiceFile) throws WxErrorException {
|
||||
this.uploadVoice(voiceId, lang, voiceFile);
|
||||
return this.queryRecognitionResult(voiceId, lang);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translate(AiLangType langFrom, AiLangType langTo, String content) throws WxErrorException {
|
||||
final String responseContent = this.wxMpService.post(String.format(TRANSLATE_URL, langFrom.getCode(), langTo.getCode()),
|
||||
content);
|
||||
final JsonObject jsonObject = new JsonParser().parse(responseContent).getAsJsonObject();
|
||||
if (jsonObject.get("errcode") == null || jsonObject.get("errcode").getAsInt() == 0) {
|
||||
return jsonObject.get("to_content").getAsString();
|
||||
}
|
||||
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String queryRecognitionResult(String voiceId, AiLangType lang) throws WxErrorException {
|
||||
if (lang == null) {
|
||||
lang = AiLangType.zh_CN;
|
||||
}
|
||||
|
||||
final String responseContent = this.wxMpService.get(VOICE_QUERY_RESULT_URL,
|
||||
String.format("voice_id=%s&lang=%s", voiceId, lang.getCode()));
|
||||
final JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
|
||||
if (jsonObject.get("errcode") == null || jsonObject.get("errcode").getAsInt() == 0) {
|
||||
return jsonObject.get("result").getAsString();
|
||||
}
|
||||
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,8 @@ import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import me.chanjar.weixin.common.bean.WxCardApiSignature;
|
||||
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.RandomUtils;
|
||||
import me.chanjar.weixin.common.util.crypto.SHA1;
|
||||
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpDataCubeService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.datacube.*;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpDeviceService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.device.*;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
|
||||
import me.chanjar.weixin.mp.api.WxMpKefuService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpMassMessageService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.*;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import me.chanjar.weixin.common.WxType;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.fs.FileUtils;
|
||||
import me.chanjar.weixin.common.util.http.BaseMediaDownloadRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
|
||||
@@ -11,7 +12,8 @@ import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||
import me.chanjar.weixin.mp.api.WxMpMaterialService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.material.*;
|
||||
import me.chanjar.weixin.mp.util.http.*;
|
||||
import me.chanjar.weixin.mp.util.requestexecuter.material.*;
|
||||
import me.chanjar.weixin.mp.util.requestexecuter.media.MediaImgUploadRequestExecutor;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.File;
|
||||
@@ -100,7 +102,7 @@ public class WxMpMaterialServiceImpl implements WxMpMaterialService {
|
||||
@Override
|
||||
public boolean materialNewsUpdate(WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate) throws WxErrorException {
|
||||
String responseText = this.wxMpService.post(NEWS_UPDATE_URL, wxMpMaterialArticleUpdate.toJson());
|
||||
WxError wxError = WxError.fromJson(responseText);
|
||||
WxError wxError = WxError.fromJson(responseText, WxType.MP);
|
||||
if (wxError.getErrorCode() == 0) {
|
||||
return true;
|
||||
} else {
|
||||
@@ -116,7 +118,7 @@ public class WxMpMaterialServiceImpl implements WxMpMaterialService {
|
||||
@Override
|
||||
public WxMpMaterialCountResult materialCount() throws WxErrorException {
|
||||
String responseText = this.wxMpService.get(MATERIAL_GET_COUNT_URL, null);
|
||||
WxError wxError = WxError.fromJson(responseText);
|
||||
WxError wxError = WxError.fromJson(responseText, WxType.MP);
|
||||
if (wxError.getErrorCode() == 0) {
|
||||
return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialCountResult.class);
|
||||
} else {
|
||||
@@ -131,7 +133,7 @@ public class WxMpMaterialServiceImpl implements WxMpMaterialService {
|
||||
params.put("offset", offset);
|
||||
params.put("count", count);
|
||||
String responseText = this.wxMpService.post(MATERIAL_BATCHGET_URL, WxGsonBuilder.create().toJson(params));
|
||||
WxError wxError = WxError.fromJson(responseText);
|
||||
WxError wxError = WxError.fromJson(responseText, WxType.MP);
|
||||
if (wxError.getErrorCode() == 0) {
|
||||
return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialNewsBatchGetResult.class);
|
||||
} else {
|
||||
@@ -146,7 +148,7 @@ public class WxMpMaterialServiceImpl implements WxMpMaterialService {
|
||||
params.put("offset", offset);
|
||||
params.put("count", count);
|
||||
String responseText = this.wxMpService.post(MATERIAL_BATCHGET_URL, WxGsonBuilder.create().toJson(params));
|
||||
WxError wxError = WxError.fromJson(responseText);
|
||||
WxError wxError = WxError.fromJson(responseText, WxType.MP);
|
||||
if (wxError.getErrorCode() == 0) {
|
||||
return WxMpGsonBuilder.create().fromJson(responseText, WxMpMaterialFileBatchGetResult.class);
|
||||
} else {
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpMemberCardService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardActivatedMessage;
|
||||
|
||||
@@ -3,7 +3,7 @@ package me.chanjar.weixin.mp.api.impl;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import me.chanjar.weixin.common.bean.menu.WxMenu;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpMenuService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
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.mp.api.WxMpQrcodeService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
|
||||
import me.chanjar.weixin.mp.util.http.QrCodeRequestExecutor;
|
||||
import me.chanjar.weixin.mp.util.requestexecuter.qrcode.QrCodeRequestExecutor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import me.chanjar.weixin.common.WxType;
|
||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||
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.HttpType;
|
||||
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
|
||||
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
|
||||
@@ -21,7 +22,7 @@ import java.util.concurrent.locks.Lock;
|
||||
/**
|
||||
* apache http client方式实现.
|
||||
*/
|
||||
public class WxMpServiceHttpClientImpl extends WxMpServiceBaseImpl<CloseableHttpClient, HttpHost> {
|
||||
public class WxMpServiceHttpClientImpl extends BaseWxMpServiceImpl<CloseableHttpClient, HttpHost> {
|
||||
private CloseableHttpClient httpClient;
|
||||
private HttpHost httpProxy;
|
||||
|
||||
@@ -76,7 +77,7 @@ public class WxMpServiceHttpClientImpl extends WxMpServiceBaseImpl<CloseableHttp
|
||||
}
|
||||
try (CloseableHttpResponse response = getRequestHttpClient().execute(httpGet)) {
|
||||
String resultContent = new BasicResponseHandler().handleResponse(response);
|
||||
WxError error = WxError.fromJson(resultContent);
|
||||
WxError error = WxError.fromJson(resultContent, WxType.MP);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@ package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import jodd.http.*;
|
||||
import jodd.http.net.SocketHttpConnectionProvider;
|
||||
import me.chanjar.weixin.common.WxType;
|
||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||
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.HttpType;
|
||||
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
@@ -14,7 +15,7 @@ import java.util.concurrent.locks.Lock;
|
||||
/**
|
||||
* jodd-http方式实现
|
||||
*/
|
||||
public class WxMpServiceJoddHttpImpl extends WxMpServiceBaseImpl<HttpConnectionProvider, ProxyInfo> {
|
||||
public class WxMpServiceJoddHttpImpl extends BaseWxMpServiceImpl<HttpConnectionProvider, ProxyInfo> {
|
||||
private HttpConnectionProvider httpClient;
|
||||
private ProxyInfo httpProxy;
|
||||
|
||||
@@ -65,7 +66,7 @@ public class WxMpServiceJoddHttpImpl extends WxMpServiceBaseImpl<HttpConnectionP
|
||||
}
|
||||
HttpResponse response = request.send();
|
||||
String resultContent = response.bodyText();
|
||||
WxError error = WxError.fromJson(resultContent);
|
||||
WxError error = WxError.fromJson(resultContent, WxType.MP);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import me.chanjar.weixin.common.WxType;
|
||||
import me.chanjar.weixin.common.bean.WxAccessToken;
|
||||
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.HttpType;
|
||||
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
@@ -14,7 +15,7 @@ import java.util.concurrent.locks.Lock;
|
||||
/**
|
||||
* okhttp实现
|
||||
*/
|
||||
public class WxMpServiceOkHttpImpl extends WxMpServiceBaseImpl<OkHttpClient, OkHttpProxyInfo> {
|
||||
public class WxMpServiceOkHttpImpl extends BaseWxMpServiceImpl<OkHttpClient, OkHttpProxyInfo> {
|
||||
private OkHttpClient httpClient;
|
||||
private OkHttpProxyInfo httpProxy;
|
||||
|
||||
@@ -47,7 +48,7 @@ public class WxMpServiceOkHttpImpl extends WxMpServiceBaseImpl<OkHttpClient, OkH
|
||||
Request request = new Request.Builder().url(url).get().build();
|
||||
Response response = getRequestHttpClient().newCall(request).execute();
|
||||
String resultContent = response.body().string();
|
||||
WxError error = WxError.fromJson(resultContent);
|
||||
WxError error = WxError.fromJson(resultContent, WxType.MP);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
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.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.WxMpShakeService;
|
||||
import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult;
|
||||
@@ -53,7 +54,7 @@ public class WxMpShakeServiceImpl implements WxMpShakeService {
|
||||
String url = "https://api.weixin.qq.com/shakearound/device/bindpage";
|
||||
String postData = shakeAroundDeviceBindPageQuery.toJsonString();
|
||||
String responseContent = this.wxMpService.post(url, postData);
|
||||
return WxError.fromJson(responseContent);
|
||||
return WxError.fromJson(responseContent, WxType.MP);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,8 +3,9 @@ package me.chanjar.weixin.mp.api.impl;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
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.BeanUtils;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.WxMpStoreService;
|
||||
@@ -32,7 +33,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService {
|
||||
BeanUtils.checkRequiredFields(request);
|
||||
|
||||
String response = this.wxMpService.post(POI_ADD_URL, request.toJson());
|
||||
WxError wxError = WxError.fromJson(response);
|
||||
WxError wxError = WxError.fromJson(response, WxType.MP);
|
||||
if (wxError.getErrorCode() != 0) {
|
||||
throw new WxErrorException(wxError);
|
||||
}
|
||||
@@ -43,7 +44,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService {
|
||||
JsonObject paramObject = new JsonObject();
|
||||
paramObject.addProperty("poi_id", poiId);
|
||||
String response = this.wxMpService.post(POI_GET_URL, paramObject.toString());
|
||||
WxError wxError = WxError.fromJson(response);
|
||||
WxError wxError = WxError.fromJson(response, WxType.MP);
|
||||
if (wxError.getErrorCode() != 0) {
|
||||
throw new WxErrorException(wxError);
|
||||
}
|
||||
@@ -56,7 +57,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService {
|
||||
JsonObject paramObject = new JsonObject();
|
||||
paramObject.addProperty("poi_id", poiId);
|
||||
String response = this.wxMpService.post(POI_DEL_URL, paramObject.toString());
|
||||
WxError wxError = WxError.fromJson(response);
|
||||
WxError wxError = WxError.fromJson(response, WxType.MP);
|
||||
if (wxError.getErrorCode() != 0) {
|
||||
throw new WxErrorException(wxError);
|
||||
}
|
||||
@@ -70,7 +71,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService {
|
||||
params.addProperty("limit", limit);
|
||||
String response = this.wxMpService.post(POI_LIST_URL, params.toString());
|
||||
|
||||
WxError wxError = WxError.fromJson(response);
|
||||
WxError wxError = WxError.fromJson(response, WxType.MP);
|
||||
if (wxError.getErrorCode() != 0) {
|
||||
throw new WxErrorException(wxError);
|
||||
}
|
||||
@@ -102,7 +103,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService {
|
||||
@Override
|
||||
public void update(WxMpStoreBaseInfo request) throws WxErrorException {
|
||||
String response = this.wxMpService.post(POI_UPDATE_URL, request.toJson());
|
||||
WxError wxError = WxError.fromJson(response);
|
||||
WxError wxError = WxError.fromJson(response, WxType.MP);
|
||||
if (wxError.getErrorCode() != 0) {
|
||||
throw new WxErrorException(wxError);
|
||||
}
|
||||
@@ -111,7 +112,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService {
|
||||
@Override
|
||||
public List<String> listCategories() throws WxErrorException {
|
||||
String response = this.wxMpService.get(POI_GET_WX_CATEGORY_URL, null);
|
||||
WxError wxError = WxError.fromJson(response);
|
||||
WxError wxError = WxError.fromJson(response, WxType.MP);
|
||||
if (wxError.getErrorCode() != 0) {
|
||||
throw new WxErrorException(wxError);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.URIUtil;
|
||||
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
|
||||
@@ -2,8 +2,9 @@ package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
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.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.WxMpTemplateMsgService;
|
||||
import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
|
||||
@@ -37,7 +38,7 @@ public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService {
|
||||
if (jsonObject.get("errcode").getAsInt() == 0) {
|
||||
return jsonObject.get("msgid").getAsString();
|
||||
}
|
||||
throw new WxErrorException(WxError.fromJson(responseContent));
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,7 +71,7 @@ public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService {
|
||||
return result.get("template_id").getAsString();
|
||||
}
|
||||
|
||||
throw new WxErrorException(WxError.fromJson(responseContent));
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,7 +86,7 @@ public class WxMpTemplateMsgServiceImpl implements WxMpTemplateMsgService {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("template_id", templateId);
|
||||
String responseContent = this.wxMpService.post(url, jsonObject.toString());
|
||||
WxError error = WxError.fromJson(responseContent);
|
||||
WxError error = WxError.fromJson(responseContent, WxType.MP);
|
||||
if (error.getErrorCode() == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.WxMpUserBlacklistService;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.WxMpUserService;
|
||||
import me.chanjar.weixin.mp.bean.WxMpUserQuery;
|
||||
|
||||
@@ -4,8 +4,9 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
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.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.WxMpUserTagService;
|
||||
import me.chanjar.weixin.mp.bean.tag.WxTagListUser;
|
||||
@@ -60,7 +61,7 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService {
|
||||
json.add("tag", tagJson);
|
||||
|
||||
String responseContent = this.wxMpService.post(url, json.toString());
|
||||
WxError wxError = WxError.fromJson(responseContent);
|
||||
WxError wxError = WxError.fromJson(responseContent, WxType.MP);
|
||||
if (wxError.getErrorCode() == 0) {
|
||||
return true;
|
||||
}
|
||||
@@ -78,7 +79,7 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService {
|
||||
json.add("tag", tagJson);
|
||||
|
||||
String responseContent = this.wxMpService.post(url, json.toString());
|
||||
WxError wxError = WxError.fromJson(responseContent);
|
||||
WxError wxError = WxError.fromJson(responseContent, WxType.MP);
|
||||
if (wxError.getErrorCode() == 0) {
|
||||
return true;
|
||||
}
|
||||
@@ -113,7 +114,7 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService {
|
||||
json.add("openid_list", openidArrayJson);
|
||||
|
||||
String responseContent = this.wxMpService.post(url, json.toString());
|
||||
WxError wxError = WxError.fromJson(responseContent);
|
||||
WxError wxError = WxError.fromJson(responseContent, WxType.MP);
|
||||
if (wxError.getErrorCode() == 0) {
|
||||
return true;
|
||||
}
|
||||
@@ -135,7 +136,7 @@ public class WxMpUserTagServiceImpl implements WxMpUserTagService {
|
||||
json.add("openid_list", openidArrayJson);
|
||||
|
||||
String responseContent = this.wxMpService.post(url, json.toString());
|
||||
WxError wxError = WxError.fromJson(responseContent);
|
||||
WxError wxError = WxError.fromJson(responseContent, WxType.MP);
|
||||
if (wxError.getErrorCode() == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.WxMpWifiService;
|
||||
import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopListResult;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by BinaryWang on 2018/6/10.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public class WxMpWifiServiceImpl implements WxMpWifiService {
|
||||
private WxMpService wxMpService;
|
||||
|
||||
public WxMpWifiServiceImpl(WxMpService wxMpService) {
|
||||
this.wxMpService = wxMpService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpWifiShopListResult listShop(int pageIndex, int pageSize) throws WxErrorException {
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("pageindex", pageIndex);
|
||||
json.addProperty("pagesize", pageSize);
|
||||
final String result = this.wxMpService.post("https://api.weixin.qq.com/bizwifi/shop/list", json.toString());
|
||||
return WxMpWifiShopListResult.fromJson(result);
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,11 @@ public class WxMpMassOpenIdsMessage implements Serializable {
|
||||
*/
|
||||
private boolean sendIgnoreReprint = false;
|
||||
|
||||
/**
|
||||
* 开发者侧群发msgid,长度限制64字节,如不填,则后台默认以群发范围和群发内容的摘要值做为clientmsgid
|
||||
*/
|
||||
private String clientMsgId;
|
||||
|
||||
public WxMpMassOpenIdsMessage() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -38,11 +38,17 @@ public class WxMpMassTagMessage implements Serializable {
|
||||
* 是否群发给所有用户
|
||||
*/
|
||||
private boolean isSendAll = false;
|
||||
|
||||
/**
|
||||
* 文章被判定为转载时,是否继续进行群发操作。
|
||||
*/
|
||||
private boolean sendIgnoreReprint = false;
|
||||
|
||||
/**
|
||||
* 开发者侧群发msgid,长度限制64字节,如不填,则后台默认以群发范围和群发内容的摘要值做为clientmsgid
|
||||
*/
|
||||
private String clientMsgId;
|
||||
|
||||
public WxMpMassTagMessage() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ public class WxMpKefuMessage implements Serializable {
|
||||
private String kfAccount;
|
||||
private String cardId;
|
||||
private String mpNewsMediaId;
|
||||
private String miniProgramAppId;
|
||||
private String miniProgramPagePath;
|
||||
private List<WxArticle> articles = new ArrayList<>();
|
||||
|
||||
/**
|
||||
@@ -88,6 +90,13 @@ public class WxMpKefuMessage implements Serializable {
|
||||
return new WxCardBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序卡片
|
||||
*/
|
||||
public static MiniProgramPageBuilder MINIPROGRAMPAGE() {
|
||||
return new MiniProgramPageBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 请使用
|
||||
@@ -99,6 +108,7 @@ public class WxMpKefuMessage implements Serializable {
|
||||
* {@link WxConsts.KefuMsgType#NEWS}
|
||||
* {@link WxConsts.KefuMsgType#MPNEWS}
|
||||
* {@link WxConsts.KefuMsgType#WXCARD}
|
||||
* {@link WxConsts.KefuMsgType#MINIPROGRAMPAGE}
|
||||
* </pre>
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package me.chanjar.weixin.mp.bean.result;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
@@ -7,10 +11,6 @@ import lombok.Data;
|
||||
import me.chanjar.weixin.common.util.ToStringUtils;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 微信用户信息.
|
||||
*
|
||||
@@ -56,6 +56,23 @@ public class WxMpUser implements Serializable {
|
||||
*/
|
||||
private String[] privileges;
|
||||
|
||||
/**
|
||||
* subscribe_scene 返回用户关注的渠道来源.
|
||||
* ADD_SCENE_SEARCH 公众号搜索,ADD_SCENE_ACCOUNT_MIGRATION 公众号迁移,ADD_SCENE_PROFILE_CARD 名片分享,ADD_SCENE_QR_CODE 扫描二维码,ADD_SCENEPROFILE LINK 图文页内名称点击,ADD_SCENE_PROFILE_ITEM 图文页右上角菜单,ADD_SCENE_PAID 支付后关注,ADD_SCENE_OTHERS 其他
|
||||
*/
|
||||
private String subscribeScene;
|
||||
|
||||
/**
|
||||
* qr_scene 二维码扫码场景(开发者自定义).
|
||||
*/
|
||||
private String qrScene;
|
||||
|
||||
/**
|
||||
* qr_scene_str 二维码扫码场景描述(开发者自定义).
|
||||
*/
|
||||
private String qrSceneStr;
|
||||
|
||||
|
||||
public static WxMpUser fromJson(String json) {
|
||||
return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpUser.class);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class WxMpTemplateMessage implements Serializable {
|
||||
/**
|
||||
* 模板数据.
|
||||
*/
|
||||
private List<WxMpTemplateData> data;
|
||||
private List<WxMpTemplateData> data = new ArrayList<>();
|
||||
|
||||
public WxMpTemplateMessage addData(WxMpTemplateData datum) {
|
||||
if (this.data == null) {
|
||||
@@ -76,7 +76,7 @@ public class WxMpTemplateMessage implements Serializable {
|
||||
private static final long serialVersionUID = -7945254706501974849L;
|
||||
|
||||
private String appid;
|
||||
private String path;
|
||||
private String pagePath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
package me.chanjar.weixin.mp.bean.wifi;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by BinaryWang on 2018/6/10.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@Data
|
||||
public class WxMpWifiShopListResult {
|
||||
public static WxMpWifiShopListResult fromJson(String json) {
|
||||
return WxMpGsonBuilder.create().fromJson(
|
||||
new JsonParser().parse(json).getAsJsonObject().get("data"),
|
||||
WxMpWifiShopListResult.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 总数
|
||||
*/
|
||||
@SerializedName("totalcount")
|
||||
private int totalCount;
|
||||
|
||||
/**
|
||||
* 分页下标
|
||||
*/
|
||||
@SerializedName("pageindex")
|
||||
private int pageIndex;
|
||||
|
||||
/**
|
||||
* 分页页数
|
||||
*/
|
||||
@SerializedName("pagecount")
|
||||
private int pageCount;
|
||||
|
||||
private List<Record> records;
|
||||
|
||||
@Data
|
||||
public static class Record {
|
||||
|
||||
/**
|
||||
* 门店ID(适用于微信连Wi-Fi业务)
|
||||
*/
|
||||
@SerializedName("shop_id")
|
||||
private Integer shopId;
|
||||
|
||||
/**
|
||||
* 门店名称
|
||||
*/
|
||||
@SerializedName("shop_name")
|
||||
private String shopName;
|
||||
|
||||
/**
|
||||
* 无线网络设备的ssid,未添加设备为空,多个ssid时显示第一个
|
||||
*/
|
||||
@SerializedName("ssid")
|
||||
private String ssid;
|
||||
|
||||
/**
|
||||
* 无线网络设备的ssid列表,返回数组格式
|
||||
*/
|
||||
@SerializedName("ssid_list")
|
||||
private List<String> ssidList;
|
||||
|
||||
/**
|
||||
* 门店内设备的设备类型,0-未添加设备,1-专业型设备,4-密码型设备,5-portal自助型设备,31-portal改造型设备
|
||||
*/
|
||||
@SerializedName("protocol_type")
|
||||
private Integer protocolType;
|
||||
|
||||
/**
|
||||
* 商户自己的id,与门店poi_id对应关系,建议在添加门店时候建立关联关系,具体请参考“微信门店接口”
|
||||
*/
|
||||
@SerializedName("sid")
|
||||
private String sid;
|
||||
|
||||
/**
|
||||
* 门店ID(适用于微信卡券、微信门店业务),具体定义参考微信门店,与shop_id一一对应
|
||||
*/
|
||||
@SerializedName("poi_id")
|
||||
private String poiId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package me.chanjar.weixin.mp.builder.kefu;
|
||||
|
||||
import me.chanjar.weixin.common.api.WxConsts.KefuMsgType;
|
||||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
|
||||
|
||||
/**
|
||||
* 小程序卡片 builder
|
||||
* <pre>
|
||||
* 用法:
|
||||
* WxMpKefuMessage m = WxMpKefuMessage.MINIPROGRAMPAGE().title("xxxx").thumbMediaId("xxxxx").appId("xxxx").pagePath("****").toUser(...).build();
|
||||
* </pre>
|
||||
*
|
||||
* @author boris.bao
|
||||
*/
|
||||
public final class MiniProgramPageBuilder extends BaseBuilder<MiniProgramPageBuilder> {
|
||||
|
||||
private String title;
|
||||
private String appId;
|
||||
private String pagePath;
|
||||
private String thumbMediaId;
|
||||
|
||||
public MiniProgramPageBuilder() {
|
||||
this.msgType = KefuMsgType.MINIPROGRAMPAGE;
|
||||
}
|
||||
|
||||
|
||||
public MiniProgramPageBuilder title(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MiniProgramPageBuilder appId(String appId) {
|
||||
this.appId = appId;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public MiniProgramPageBuilder pagePath(String pagePath) {
|
||||
this.pagePath = pagePath;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public MiniProgramPageBuilder thumbMediaId(String thumbMediaId) {
|
||||
this.thumbMediaId = thumbMediaId;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public WxMpKefuMessage build() {
|
||||
WxMpKefuMessage m = super.build();
|
||||
m.setTitle(this.title);
|
||||
m.setMiniProgramAppId(this.appId);
|
||||
m.setMiniProgramPagePath(this.pagePath);
|
||||
m.setThumbMediaId(this.thumbMediaId);
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
@@ -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;
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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");
|
||||
@@ -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");
|
||||
@@ -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()) {
|
||||
@@ -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());
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.test.ApiTestModule;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.testng.*;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
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.mp.api.impl.WxMpServiceHttpClientImpl;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.crypto.SHA1;
|
||||
import me.chanjar.weixin.mp.api.test.ApiTestModule;
|
||||
import org.testng.*;
|
||||
|
||||
@@ -8,6 +8,8 @@ import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -67,9 +69,23 @@ public class WxMpMessageRouterTest {
|
||||
prepare(true, sb, router);
|
||||
router.route(message);
|
||||
Thread.sleep(500);
|
||||
router.shutDownExecutorService();
|
||||
Assert.assertEquals(sb.toString(), expected);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "messages-1")
|
||||
public void testExternalExcutorService(WxMpXmlMessage message, String expected) throws InterruptedException {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(100);
|
||||
WxMpMessageRouter router = new WxMpMessageRouter(null, executorService);
|
||||
prepare(true, sb, router);
|
||||
router.route(message);
|
||||
Thread.sleep(500);
|
||||
executorService.shutdown();
|
||||
Assert.assertEquals(sb.toString(), expected);
|
||||
}
|
||||
|
||||
|
||||
public void testConcurrency() throws InterruptedException {
|
||||
final WxMpMessageRouter router = new WxMpMessageRouter(null);
|
||||
router.rule().handler(new WxMpMessageHandler() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.test.ApiTestModule;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.test.ApiTestModule;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.AiLangType;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.test.ApiTestModule;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by BinaryWang on 2018/6/10.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@Test
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMpAiOpenServiceImplTest {
|
||||
@Inject
|
||||
protected WxMpService wxService;
|
||||
|
||||
@Test
|
||||
public void testUploadVoice() throws WxErrorException {
|
||||
String voiceId = System.currentTimeMillis() + "a";
|
||||
AiLangType lang = AiLangType.zh_CN;
|
||||
this.wxService.getAiOpenService().uploadVoice(voiceId, lang, new File("d:\\t.mp3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecogniseVoice() throws WxErrorException {
|
||||
String voiceId = System.currentTimeMillis() + "a";
|
||||
AiLangType lang = AiLangType.zh_CN;
|
||||
final String result = this.wxService.getAiOpenService().recogniseVoice(voiceId, lang, new File("d:\\t.mp3"));
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTranslate() throws WxErrorException {
|
||||
final String responseContent = this.wxService.getAiOpenService()
|
||||
.translate(AiLangType.zh_CN, AiLangType.en_US, "微信文档很坑爹");
|
||||
System.out.println(responseContent);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.test.ApiTestModule;
|
||||
import me.chanjar.weixin.mp.bean.datacube.*;
|
||||
|
||||
@@ -2,7 +2,7 @@ package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.test.ApiTestModule;
|
||||
import me.chanjar.weixin.mp.bean.device.WxDeviceQrCodeResult;
|
||||
|
||||
@@ -2,7 +2,7 @@ package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.test.ApiTestModule;
|
||||
import me.chanjar.weixin.mp.api.test.TestConfigStorage;
|
||||
|
||||
@@ -3,7 +3,7 @@ package me.chanjar.weixin.mp.api.impl;
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.test.ApiTestModule;
|
||||
import me.chanjar.weixin.mp.api.test.TestConfigStorage;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user