code clean up for cp module

This commit is contained in:
BinaryWang
2016-08-02 19:49:27 +08:00
parent f7a64a7cf6
commit d05da579a8
58 changed files with 1069 additions and 1027 deletions

View File

@@ -7,8 +7,8 @@ import java.io.File;
/** /**
* 微信客户端配置存储 * 微信客户端配置存储
* @author Daniel Qian
* *
* @author Daniel Qian
*/ */
public interface WxCpConfigStorage { public interface WxCpConfigStorage {
@@ -36,6 +36,7 @@ public interface WxCpConfigStorage {
/** /**
* 应该是线程安全的 * 应该是线程安全的
*
* @param jsapiTicket * @param jsapiTicket
*/ */
void updateJsapiTicket(String jsapiTicket, int expiresInSeconds); void updateJsapiTicket(String jsapiTicket, int expiresInSeconds);
@@ -66,6 +67,7 @@ public interface WxCpConfigStorage {
/** /**
* http client builder * http client builder
*
* @return ApacheHttpClientBuilder * @return ApacheHttpClientBuilder
*/ */
ApacheHttpClientBuilder getApacheHttpClientBuilder(); ApacheHttpClientBuilder getApacheHttpClientBuilder();

View File

@@ -7,8 +7,8 @@ import java.io.File;
/** /**
* 基于内存的微信配置provider在实际生产环境中应该将这些配置持久化 * 基于内存的微信配置provider在实际生产环境中应该将这些配置持久化
* @author Daniel Qian
* *
* @author Daniel Qian
*/ */
public class WxCpInMemoryConfigStorage implements WxCpConfigStorage { public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
@@ -39,6 +39,10 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
return this.accessToken; return this.accessToken;
} }
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public boolean isAccessTokenExpired() { public boolean isAccessTokenExpired() {
return System.currentTimeMillis() > this.expiresTime; return System.currentTimeMillis() > this.expiresTime;
} }
@@ -91,30 +95,34 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
return this.corpId; return this.corpId;
} }
public String getCorpSecret() {
return this.corpSecret;
}
public String getToken() {
return this.token;
}
public long getExpiresTime() {
return this.expiresTime;
}
public void setCorpId(String corpId) { public void setCorpId(String corpId) {
this.corpId = corpId; this.corpId = corpId;
} }
public String getCorpSecret() {
return this.corpSecret;
}
public void setCorpSecret(String corpSecret) { public void setCorpSecret(String corpSecret) {
this.corpSecret = corpSecret; this.corpSecret = corpSecret;
} }
public String getToken() {
return this.token;
}
public void setToken(String token) { public void setToken(String token) {
this.token = token; this.token = token;
} }
public long getExpiresTime() {
return this.expiresTime;
}
public void setExpiresTime(long expiresTime) {
this.expiresTime = expiresTime;
}
public String getAesKey() { public String getAesKey() {
return aesKey; return aesKey;
} }
@@ -123,14 +131,6 @@ public class WxCpInMemoryConfigStorage implements WxCpConfigStorage {
this.aesKey = aesKey; this.aesKey = aesKey;
} }
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public void setExpiresTime(long expiresTime) {
this.expiresTime = expiresTime;
}
public String getAgentId() { public String getAgentId() {
return agentId; return agentId;
} }

View File

@@ -1,7 +1,6 @@
package me.chanjar.weixin.cp.api; package me.chanjar.weixin.cp.api;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.session.WxSession;
import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage; import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage; import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;

View File

@@ -1,13 +1,13 @@
package me.chanjar.weixin.cp.api; package me.chanjar.weixin.cp.api;
import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
import me.chanjar.weixin.common.api.WxMessageDuplicateChecker;
import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker;
import me.chanjar.weixin.common.session.InternalSession; import me.chanjar.weixin.common.session.InternalSession;
import me.chanjar.weixin.common.session.InternalSessionManager; import me.chanjar.weixin.common.session.InternalSessionManager;
import me.chanjar.weixin.common.session.StandardSessionManager; import me.chanjar.weixin.common.session.StandardSessionManager;
import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.common.util.LogExceptionHandler; import me.chanjar.weixin.common.util.LogExceptionHandler;
import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
import me.chanjar.weixin.common.api.WxMessageDuplicateChecker;
import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage; import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage; import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -45,15 +45,13 @@ import java.util.concurrent.Future;
* router.route(message); * router.route(message);
* *
* </pre> * </pre>
* @author Daniel Qian
* *
* @author Daniel Qian
*/ */
public class WxCpMessageRouter { public class WxCpMessageRouter {
protected final Logger log = LoggerFactory.getLogger(WxCpMessageRouter.class);
private static final int DEFAULT_THREAD_POOL_SIZE = 100; private static final int DEFAULT_THREAD_POOL_SIZE = 100;
protected final Logger log = LoggerFactory.getLogger(WxCpMessageRouter.class);
private final List<WxCpMessageRouterRule> rules = new ArrayList<WxCpMessageRouterRule>(); private final List<WxCpMessageRouterRule> rules = new ArrayList<WxCpMessageRouterRule>();
private final WxCpService wxCpService; private final WxCpService wxCpService;
@@ -79,6 +77,7 @@ public class WxCpMessageRouter {
* 设置自定义的 {@link ExecutorService} * 设置自定义的 {@link ExecutorService}
* 如果不调用该方法,默认使用 Executors.newFixedThreadPool(100) * 如果不调用该方法,默认使用 Executors.newFixedThreadPool(100)
* </pre> * </pre>
*
* @param executorService * @param executorService
*/ */
public void setExecutorService(ExecutorService executorService) { public void setExecutorService(ExecutorService executorService) {
@@ -90,6 +89,7 @@ public class WxCpMessageRouter {
* 设置自定义的 {@link me.chanjar.weixin.common.api.WxMessageDuplicateChecker} * 设置自定义的 {@link me.chanjar.weixin.common.api.WxMessageDuplicateChecker}
* 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker} * 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker}
* </pre> * </pre>
*
* @param messageDuplicateChecker * @param messageDuplicateChecker
*/ */
public void setMessageDuplicateChecker(WxMessageDuplicateChecker messageDuplicateChecker) { public void setMessageDuplicateChecker(WxMessageDuplicateChecker messageDuplicateChecker) {
@@ -101,6 +101,7 @@ public class WxCpMessageRouter {
* 设置自定义的{@link me.chanjar.weixin.common.session.WxSessionManager} * 设置自定义的{@link me.chanjar.weixin.common.session.WxSessionManager}
* 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.session.StandardSessionManager} * 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.session.StandardSessionManager}
* </pre> * </pre>
*
* @param sessionManager * @param sessionManager
*/ */
public void setSessionManager(WxSessionManager sessionManager) { public void setSessionManager(WxSessionManager sessionManager) {
@@ -112,6 +113,7 @@ public class WxCpMessageRouter {
* 设置自定义的{@link me.chanjar.weixin.common.api.WxErrorExceptionHandler} * 设置自定义的{@link me.chanjar.weixin.common.api.WxErrorExceptionHandler}
* 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.util.LogExceptionHandler} * 如果不调用该方法,默认使用 {@link me.chanjar.weixin.common.util.LogExceptionHandler}
* </pre> * </pre>
*
* @param exceptionHandler * @param exceptionHandler
*/ */
public void setExceptionHandler(WxErrorExceptionHandler exceptionHandler) { public void setExceptionHandler(WxErrorExceptionHandler exceptionHandler) {
@@ -131,6 +133,7 @@ public class WxCpMessageRouter {
/** /**
* 处理微信消息 * 处理微信消息
*
* @param wxMessage * @param wxMessage
*/ */
public WxCpXmlOutMessage route(final WxCpXmlMessage wxMessage) { public WxCpXmlOutMessage route(final WxCpXmlMessage wxMessage) {
@@ -144,7 +147,7 @@ public class WxCpMessageRouter {
for (final WxCpMessageRouterRule rule : rules) { for (final WxCpMessageRouterRule rule : rules) {
if (rule.test(wxMessage)) { if (rule.test(wxMessage)) {
matchRules.add(rule); matchRules.add(rule);
if(!rule.isReEnter()) { if (!rule.isReEnter()) {
break; break;
} }
} }
@@ -158,7 +161,7 @@ public class WxCpMessageRouter {
final List<Future> futures = new ArrayList<Future>(); final List<Future> futures = new ArrayList<Future>();
for (final WxCpMessageRouterRule rule : matchRules) { for (final WxCpMessageRouterRule rule : matchRules) {
// 返回最后一个非异步的rule的执行结果 // 返回最后一个非异步的rule的执行结果
if(rule.isAsync()) { if (rule.isAsync()) {
futures.add( futures.add(
executorService.submit(new Runnable() { executorService.submit(new Runnable() {
public void run() { public void run() {
@@ -201,7 +204,7 @@ public class WxCpMessageRouter {
String messageId = ""; String messageId = "";
if (wxMessage.getMsgId() == null) { if (wxMessage.getMsgId() == null) {
messageId = String.valueOf(wxMessage.getCreateTime()) messageId = String.valueOf(wxMessage.getCreateTime())
+ "-" +String.valueOf(wxMessage.getAgentId() == null ? "" : wxMessage.getAgentId()) + "-" + String.valueOf(wxMessage.getAgentId() == null ? "" : wxMessage.getAgentId())
+ "-" + wxMessage.getFromUserName() + "-" + wxMessage.getFromUserName()
+ "-" + String.valueOf(wxMessage.getEventKey() == null ? "" : wxMessage.getEventKey()) + "-" + String.valueOf(wxMessage.getEventKey() == null ? "" : wxMessage.getEventKey())
+ "-" + String.valueOf(wxMessage.getEvent() == null ? "" : wxMessage.getEvent()) + "-" + String.valueOf(wxMessage.getEvent() == null ? "" : wxMessage.getEvent())
@@ -216,11 +219,12 @@ public class WxCpMessageRouter {
/** /**
* 对session的访问结束 * 对session的访问结束
*
* @param wxMessage * @param wxMessage
*/ */
protected void sessionEndAccess(WxCpXmlMessage wxMessage) { protected void sessionEndAccess(WxCpXmlMessage wxMessage) {
InternalSession session = ((InternalSessionManager)sessionManager).findSession(wxMessage.getFromUserName()); InternalSession session = ((InternalSessionManager) sessionManager).findSession(wxMessage.getFromUserName());
if (session != null) { if (session != null) {
session.endAccess(); session.endAccess();
} }

View File

@@ -1,8 +1,8 @@
package me.chanjar.weixin.cp.api; package me.chanjar.weixin.cp.api;
import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage; import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage; import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
@@ -186,7 +186,6 @@ public class WxCpMessageRouterRule {
/** /**
* 规则结束,代表如果一个消息匹配该规则,那么它将不再会进入其他规则 * 规则结束,代表如果一个消息匹配该规则,那么它将不再会进入其他规则
*
*/ */
public WxCpMessageRouter end() { public WxCpMessageRouter end() {
this.routerBuilder.getRules().add(this); this.routerBuilder.getRules().add(this);
@@ -195,7 +194,6 @@ public class WxCpMessageRouterRule {
/** /**
* 规则结束,但是消息还会进入其他规则 * 规则结束,但是消息还会进入其他规则
*
*/ */
public WxCpMessageRouter next() { public WxCpMessageRouter next() {
this.reEnter = true; this.reEnter = true;

View File

@@ -1,10 +1,5 @@
package me.chanjar.weixin.cp.api; package me.chanjar.weixin.cp.api;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import me.chanjar.weixin.common.bean.WxJsapiSignature; import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.bean.menu.WxMenu; import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
@@ -17,6 +12,11 @@ import me.chanjar.weixin.cp.bean.WxCpMessage;
import me.chanjar.weixin.cp.bean.WxCpTag; import me.chanjar.weixin.cp.bean.WxCpTag;
import me.chanjar.weixin.cp.bean.WxCpUser; import me.chanjar.weixin.cp.bean.WxCpUser;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/** /**
* 微信API的Service * 微信API的Service
*/ */
@@ -47,8 +47,9 @@ public interface WxCpService {
/** /**
* 获取access_token, 不强制刷新access_token * 获取access_token, 不强制刷新access_token
* @see #getAccessToken(boolean) *
* @throws WxErrorException * @throws WxErrorException
* @see #getAccessToken(boolean)
*/ */
String getAccessToken() throws WxErrorException; String getAccessToken() throws WxErrorException;
@@ -60,6 +61,7 @@ public interface WxCpService {
* 程序员在非必要情况下尽量不要主动调用此方法 * 程序员在非必要情况下尽量不要主动调用此方法
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取access_token * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取access_token
* </pre> * </pre>
*
* @param forceRefresh 强制刷新 * @param forceRefresh 强制刷新
* @throws me.chanjar.weixin.common.exception.WxErrorException * @throws me.chanjar.weixin.common.exception.WxErrorException
*/ */
@@ -67,8 +69,9 @@ public interface WxCpService {
/** /**
* 获得jsapi_ticket,不强制刷新jsapi_ticket * 获得jsapi_ticket,不强制刷新jsapi_ticket
* @see #getJsapiTicket(boolean) *
* @throws WxErrorException * @throws WxErrorException
* @see #getJsapiTicket(boolean)
*/ */
String getJsapiTicket() throws WxErrorException; String getJsapiTicket() throws WxErrorException;
@@ -79,6 +82,7 @@ public interface WxCpService {
* *
* 详情请见http://qydev.weixin.qq.com/wiki/index.php?title=微信JS接口#.E9.99.84.E5.BD.951-JS-SDK.E4.BD.BF.E7.94.A8.E6.9D.83.E9.99.90.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95 * 详情请见http://qydev.weixin.qq.com/wiki/index.php?title=微信JS接口#.E9.99.84.E5.BD.951-JS-SDK.E4.BD.BF.E7.94.A8.E6.9D.83.E9.99.90.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95
* </pre> * </pre>
*
* @param forceRefresh 强制刷新 * @param forceRefresh 强制刷新
* @throws WxErrorException * @throws WxErrorException
*/ */
@@ -90,6 +94,7 @@ public interface WxCpService {
* *
* 详情请见http://qydev.weixin.qq.com/wiki/index.php?title=微信JS接口#.E9.99.84.E5.BD.951-JS-SDK.E4.BD.BF.E7.94.A8.E6.9D.83.E9.99.90.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95 * 详情请见http://qydev.weixin.qq.com/wiki/index.php?title=微信JS接口#.E9.99.84.E5.BD.951-JS-SDK.E4.BD.BF.E7.94.A8.E6.9D.83.E9.99.90.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95
* </pre> * </pre>
*
* @param url url * @param url url
*/ */
WxJsapiSignature createJsapiSignature(String url) throws WxErrorException; WxJsapiSignature createJsapiSignature(String url) throws WxErrorException;
@@ -128,9 +133,9 @@ public interface WxCpService {
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件 * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件
* </pre> * </pre>
* *
* @param media_id
* @return 保存到本地的临时文件 * @return 保存到本地的临时文件
* @throws WxErrorException * @throws WxErrorException
* @param media_id
*/ */
File mediaDownload(String media_id) throws WxErrorException; File mediaDownload(String media_id) throws WxErrorException;
@@ -152,10 +157,10 @@ public interface WxCpService {
* *
* 注意: 这个方法使用WxCpConfigStorage里的agentId * 注意: 这个方法使用WxCpConfigStorage里的agentId
* </pre> * </pre>
* @see #menuCreate(String, me.chanjar.weixin.common.bean.WxMenu)
* *
* @param menu * @param menu
* @throws WxErrorException * @throws WxErrorException
* @see #menuCreate(String, me.chanjar.weixin.common.bean.WxMenu)
*/ */
void menuCreate(WxMenu menu) throws WxErrorException; void menuCreate(WxMenu menu) throws WxErrorException;
@@ -166,11 +171,11 @@ public interface WxCpService {
* *
* 注意: 这个方法不使用WxCpConfigStorage里的agentId需要开发人员自己给出 * 注意: 这个方法不使用WxCpConfigStorage里的agentId需要开发人员自己给出
* </pre> * </pre>
* @see #menuCreate(me.chanjar.weixin.common.bean.WxMenu)
* *
* @param agentId 企业号应用的id * @param agentId 企业号应用的id
* @param menu * @param menu
* @throws WxErrorException * @throws WxErrorException
* @see #menuCreate(me.chanjar.weixin.common.bean.WxMenu)
*/ */
void menuCreate(String agentId, WxMenu menu) throws WxErrorException; void menuCreate(String agentId, WxMenu menu) throws WxErrorException;
@@ -181,9 +186,9 @@ public interface WxCpService {
* *
* 注意: 这个方法使用WxCpConfigStorage里的agentId * 注意: 这个方法使用WxCpConfigStorage里的agentId
* </pre> * </pre>
* @see #menuDelete(String)
* *
* @throws WxErrorException * @throws WxErrorException
* @see #menuDelete(String)
*/ */
void menuDelete() throws WxErrorException; void menuDelete() throws WxErrorException;
@@ -194,10 +199,10 @@ public interface WxCpService {
* *
* 注意: 这个方法不使用WxCpConfigStorage里的agentId需要开发人员自己给出 * 注意: 这个方法不使用WxCpConfigStorage里的agentId需要开发人员自己给出
* </pre> * </pre>
* @see #menuDelete()
* *
* @param agentId 企业号应用的id * @param agentId 企业号应用的id
* @throws WxErrorException * @throws WxErrorException
* @see #menuDelete()
*/ */
void menuDelete(String agentId) throws WxErrorException; void menuDelete(String agentId) throws WxErrorException;
@@ -208,9 +213,9 @@ public interface WxCpService {
* *
* 注意: 这个方法使用WxCpConfigStorage里的agentId * 注意: 这个方法使用WxCpConfigStorage里的agentId
* </pre> * </pre>
* @see #menuGet(String)
* *
* @throws WxErrorException * @throws WxErrorException
* @see #menuGet(String)
*/ */
WxMenu menuGet() throws WxErrorException; WxMenu menuGet() throws WxErrorException;
@@ -221,10 +226,10 @@ public interface WxCpService {
* *
* 注意: 这个方法不使用WxCpConfigStorage里的agentId需要开发人员自己给出 * 注意: 这个方法不使用WxCpConfigStorage里的agentId需要开发人员自己给出
* </pre> * </pre>
* @see #menuGet()
* *
* @param agentId 企业号应用的id * @param agentId 企业号应用的id
* @throws WxErrorException * @throws WxErrorException
* @see #menuGet()
*/ */
WxMenu menuGet(String agentId) throws WxErrorException; WxMenu menuGet(String agentId) throws WxErrorException;
@@ -279,6 +284,7 @@ public interface WxCpService {
* *
* http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98.28.E8.AF.A6.E6.83.85.29 * http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98.28.E8.AF.A6.E6.83.85.29
* </pre> * </pre>
*
* @param departId 必填。部门id * @param departId 必填。部门id
* @param fetchChild 非必填。1/0是否递归获取子部门下面的成员 * @param fetchChild 非必填。1/0是否递归获取子部门下面的成员
* @param status 非必填。0获取全部员工1获取已关注成员列表2获取禁用成员列表4获取未关注成员列表。status可叠加 * @param status 非必填。0获取全部员工1获取已关注成员列表2获取禁用成员列表4获取未关注成员列表。status可叠加
@@ -330,6 +336,7 @@ public interface WxCpService {
* *
* http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E6.89.B9.E9.87.8F.E5.88.A0.E9.99.A4.E6.88.90.E5.91.98 * http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E6.89.B9.E9.87.8F.E5.88.A0.E9.99.A4.E6.88.90.E5.91.98
* </pre> * </pre>
*
* @param userids 员工UserID列表。对应管理端的帐号 * @param userids 员工UserID列表。对应管理端的帐号
* @throws WxErrorException * @throws WxErrorException
*/ */
@@ -367,7 +374,6 @@ public interface WxCpService {
/** /**
* 获得标签列表 * 获得标签列表
*
*/ */
List<WxCpTag> tagGet() throws WxErrorException; List<WxCpTag> tagGet() throws WxErrorException;
@@ -391,6 +397,7 @@ public interface WxCpService {
* 构造oauth2授权的url连接 * 构造oauth2授权的url连接
* 详情请见: http://qydev.weixin.qq.com/wiki/index.php?title=企业获取code * 详情请见: http://qydev.weixin.qq.com/wiki/index.php?title=企业获取code
* </pre> * </pre>
*
* @param redirectUri * @param redirectUri
* @param state * @param state
* @return url * @return url
@@ -405,10 +412,10 @@ public interface WxCpService {
* *
* 注意: 这个方法使用WxCpConfigStorage里的agentId * 注意: 这个方法使用WxCpConfigStorage里的agentId
* </pre> * </pre>
* @see #oauth2getUserInfo(String, String)
* *
* @param code * @param code
* @return [userid, deviceid] * @return [userid, deviceid]
* @see #oauth2getUserInfo(String, String)
*/ */
String[] oauth2getUserInfo(String code) throws WxErrorException; String[] oauth2getUserInfo(String code) throws WxErrorException;
@@ -420,11 +427,11 @@ public interface WxCpService {
* *
* 注意: 这个方法不使用WxCpConfigStorage里的agentId需要开发人员自己给出 * 注意: 这个方法不使用WxCpConfigStorage里的agentId需要开发人员自己给出
* </pre> * </pre>
* @see #oauth2getUserInfo(String)
* *
* @param agentId 企业号应用的id * @param agentId 企业号应用的id
* @param code * @param code
* @return [userid, deviceid] * @return [userid, deviceid]
* @see #oauth2getUserInfo(String)
*/ */
String[] oauth2getUserInfo(String agentId, String code) throws WxErrorException; String[] oauth2getUserInfo(String agentId, String code) throws WxErrorException;
@@ -442,6 +449,7 @@ public interface WxCpService {
* 邀请成员关注 * 邀请成员关注
* http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E9.82.80.E8.AF.B7.E6.88.90.E5.91.98.E5.85.B3.E6.B3.A8 * http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E9.82.80.E8.AF.B7.E6.88.90.E5.91.98.E5.85.B3.E6.B3.A8
* </pre> * </pre>
*
* @param userId 用户的userid * @param userId 用户的userid
* @param inviteTips 推送到微信上的提示语只有认证号可以使用。当使用微信推送时该字段默认为“请关注XXX企业号”邮件邀请时该字段无效。 * @param inviteTips 推送到微信上的提示语只有认证号可以使用。当使用微信推送时该字段默认为“请关注XXX企业号”邮件邀请时该字段无效。
* @return 1:微信邀请 2.邮件邀请 * @return 1:微信邀请 2.邮件邀请
@@ -454,6 +462,7 @@ public interface WxCpService {
* 获取微信服务器的ip段 * 获取微信服务器的ip段
* http://qydev.weixin.qq.com/wiki/index.php?title=回调模式#.E8.8E.B7.E5.8F.96.E5.BE.AE.E4.BF.A1.E6.9C.8D.E5.8A.A1.E5.99.A8.E7.9A.84ip.E6.AE.B5 * http://qydev.weixin.qq.com/wiki/index.php?title=回调模式#.E8.8E.B7.E5.8F.96.E5.BE.AE.E4.BF.A1.E6.9C.8D.E5.8A.A1.E5.99.A8.E7.9A.84ip.E6.AE.B5
* </pre> * </pre>
*
* @return { "ip_list": ["101.226.103.*", "101.226.62.*"] } * @return { "ip_list": ["101.226.103.*", "101.226.62.*"] }
* @throws WxErrorException * @throws WxErrorException
*/ */
@@ -461,6 +470,7 @@ public interface WxCpService {
/** /**
* 当本Service没有实现某个API的时候可以用这个针对所有微信API中的GET请求 * 当本Service没有实现某个API的时候可以用这个针对所有微信API中的GET请求
*
* @param url * @param url
* @param queryParam * @param queryParam
* @throws WxErrorException * @throws WxErrorException
@@ -469,6 +479,7 @@ public interface WxCpService {
/** /**
* 当本Service没有实现某个API的时候可以用这个针对所有微信API中的POST请求 * 当本Service没有实现某个API的时候可以用这个针对所有微信API中的POST请求
*
* @param url * @param url
* @param postData * @param postData
* @throws WxErrorException * @throws WxErrorException
@@ -481,6 +492,7 @@ public interface WxCpService {
* 比{@link #get}和{@link #post}方法更灵活可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。 * 比{@link #get}和{@link #post}方法更灵活可以自己构造RequestExecutor用来处理不同的参数和不同的返回类型。
* 可以参考,{@link me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor}的实现方法 * 可以参考,{@link me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor}的实现方法
* </pre> * </pre>
*
* @param executor * @param executor
* @param uri * @param uri
* @param data * @param data
@@ -502,6 +514,7 @@ public interface WxCpService {
* 设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试 * 设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试
* 默认1000ms * 默认1000ms
* </pre> * </pre>
*
* @param retrySleepMillis * @param retrySleepMillis
*/ */
void setRetrySleepMillis(int retrySleepMillis); void setRetrySleepMillis(int retrySleepMillis);
@@ -511,18 +524,21 @@ public interface WxCpService {
* 设置当微信系统响应系统繁忙时,最大重试次数 * 设置当微信系统响应系统繁忙时,最大重试次数
* 默认5次 * 默认5次
* </pre> * </pre>
*
* @param maxRetryTimes * @param maxRetryTimes
*/ */
void setMaxRetryTimes(int maxRetryTimes); void setMaxRetryTimes(int maxRetryTimes);
/** /**
* 获取某个sessionId对应的session,如果sessionId没有对应的session则新建一个并返回。 * 获取某个sessionId对应的session,如果sessionId没有对应的session则新建一个并返回。
*
* @param id id可以为任意字符串建议使用FromUserName作为id * @param id id可以为任意字符串建议使用FromUserName作为id
*/ */
WxSession getSession(String id); WxSession getSession(String id);
/** /**
* 获取某个sessionId对应的session,如果sessionId没有对应的session若create为true则新建一个否则返回null。 * 获取某个sessionId对应的session,如果sessionId没有对应的session若create为true则新建一个否则返回null。
*
* @param id id可以为任意字符串建议使用FromUserName作为id * @param id id可以为任意字符串建议使用FromUserName作为id
* @param create * @param create
*/ */
@@ -533,12 +549,14 @@ public interface WxCpService {
* 设置WxSessionManager只有当需要使用个性化的WxSessionManager的时候才需要调用此方法 * 设置WxSessionManager只有当需要使用个性化的WxSessionManager的时候才需要调用此方法
* WxCpService默认使用的是{@link me.chanjar.weixin.common.session.StandardSessionManager} * WxCpService默认使用的是{@link me.chanjar.weixin.common.session.StandardSessionManager}
* </pre> * </pre>
*
* @param sessionManager * @param sessionManager
*/ */
void setSessionManager(WxSessionManager sessionManager); void setSessionManager(WxSessionManager sessionManager);
/** /**
* 上传部门列表覆盖企业号上的部门信息 * 上传部门列表覆盖企业号上的部门信息
*
* @param mediaId * @param mediaId
* @throws WxErrorException * @throws WxErrorException
*/ */
@@ -546,6 +564,7 @@ public interface WxCpService {
/** /**
* 上传用户列表覆盖企业号上的用户信息 * 上传用户列表覆盖企业号上的用户信息
*
* @param mediaId * @param mediaId
* @throws WxErrorException * @throws WxErrorException
*/ */
@@ -553,6 +572,7 @@ public interface WxCpService {
/** /**
* 获取异步任务结果 * 获取异步任务结果
*
* @param joinId * @param joinId
* @throws WxErrorException * @throws WxErrorException
*/ */

View File

@@ -1,23 +1,5 @@
package me.chanjar.weixin.cp.api; package me.chanjar.weixin.cp.api;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.UUID;
import org.apache.http.HttpHost;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.CloseableHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
@@ -25,7 +7,6 @@ import com.google.gson.JsonPrimitive;
import com.google.gson.internal.Streams; import com.google.gson.internal.Streams;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonReader;
import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.bean.WxJsapiSignature; import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.bean.menu.WxMenu; import me.chanjar.weixin.common.bean.menu.WxMenu;
@@ -39,20 +20,30 @@ import me.chanjar.weixin.common.util.RandomUtils;
import me.chanjar.weixin.common.util.StringUtils; import me.chanjar.weixin.common.util.StringUtils;
import me.chanjar.weixin.common.util.crypto.SHA1; import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.common.util.fs.FileUtils; import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder; import me.chanjar.weixin.common.util.http.*;
import me.chanjar.weixin.common.util.http.DefaultApacheHttpHttpClientBuilder;
import me.chanjar.weixin.common.util.http.MediaDownloadRequestExecutor;
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
import me.chanjar.weixin.common.util.http.URIUtil;
import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.cp.bean.WxCpDepart; import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.bean.WxCpMessage; import me.chanjar.weixin.cp.bean.WxCpMessage;
import me.chanjar.weixin.cp.bean.WxCpTag; import me.chanjar.weixin.cp.bean.WxCpTag;
import me.chanjar.weixin.cp.bean.WxCpUser; import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import org.apache.http.HttpHost;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.CloseableHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.UUID;
public class WxCpServiceImpl implements WxCpService { public class WxCpServiceImpl implements WxCpService {
@@ -73,17 +64,13 @@ public class WxCpServiceImpl implements WxCpService {
protected CloseableHttpClient httpClient; protected CloseableHttpClient httpClient;
protected HttpHost httpProxy; protected HttpHost httpProxy;
private int retrySleepMillis = 1000;
private int maxRetryTimes = 5;
protected WxSessionManager sessionManager = new StandardSessionManager(); protected WxSessionManager sessionManager = new StandardSessionManager();
/** /**
* 临时文件目录 * 临时文件目录
*/ */
protected File tmpDirFile; protected File tmpDirFile;
private int retrySleepMillis = 1000;
private int maxRetryTimes = 5;
public boolean checkSignature(String msgSignature, String timestamp, String nonce, String data) { public boolean checkSignature(String msgSignature, String timestamp, String nonce, String data) {
try { try {
@@ -122,7 +109,7 @@ public class WxCpServiceImpl implements WxCpService {
String resultContent = null; String resultContent = null;
try (CloseableHttpResponse response = httpclient.execute(httpGet)) { try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
resultContent = new BasicResponseHandler().handleResponse(response); resultContent = new BasicResponseHandler().handleResponse(response);
}finally { } finally {
httpGet.releaseConnection(); httpGet.releaseConnection();
} }
WxError error = WxError.fromJson(resultContent); WxError error = WxError.fromJson(resultContent);
@@ -342,7 +329,8 @@ public class WxCpServiceImpl implements WxCpService {
return WxCpGsonBuilder.INSTANCE.create() return WxCpGsonBuilder.INSTANCE.create()
.fromJson( .fromJson(
tmpJsonElement.getAsJsonObject().get("userlist"), tmpJsonElement.getAsJsonObject().get("userlist"),
new TypeToken<List<WxCpUser>>() { }.getType() new TypeToken<List<WxCpUser>>() {
}.getType()
); );
} }
@@ -364,7 +352,8 @@ public class WxCpServiceImpl implements WxCpService {
return WxCpGsonBuilder.INSTANCE.create() return WxCpGsonBuilder.INSTANCE.create()
.fromJson( .fromJson(
tmpJsonElement.getAsJsonObject().get("userlist"), tmpJsonElement.getAsJsonObject().get("userlist"),
new TypeToken<List<WxCpUser>>() { }.getType() new TypeToken<List<WxCpUser>>() {
}.getType()
); );
} }
@@ -414,7 +403,8 @@ public class WxCpServiceImpl implements WxCpService {
return WxCpGsonBuilder.INSTANCE.create() return WxCpGsonBuilder.INSTANCE.create()
.fromJson( .fromJson(
tmpJsonElement.getAsJsonObject().get("userlist"), tmpJsonElement.getAsJsonObject().get("userlist"),
new TypeToken<List<WxCpUser>>() { }.getType() new TypeToken<List<WxCpUser>>() {
}.getType()
); );
} }
@@ -455,7 +445,7 @@ public class WxCpServiceImpl implements WxCpService {
@Override @Override
public String oauth2buildAuthorizationUrl(String redirectUri, String state) { public String oauth2buildAuthorizationUrl(String redirectUri, String state) {
String url = "https://open.weixin.qq.com/connect/oauth2/authorize?" ; String url = "https://open.weixin.qq.com/connect/oauth2/authorize?";
url += "appid=" + wxCpConfigStorage.getCorpId(); url += "appid=" + wxCpConfigStorage.getCorpId();
url += "&redirect_uri=" + URIUtil.encodeURIComponent(redirectUri); url += "&redirect_uri=" + URIUtil.encodeURIComponent(redirectUri);
url += "&response_type=code"; url += "&response_type=code";
@@ -480,7 +470,7 @@ public class WxCpServiceImpl implements WxCpService {
String responseText = get(url, null); String responseText = get(url, null);
JsonElement je = Streams.parse(new JsonReader(new StringReader(responseText))); JsonElement je = Streams.parse(new JsonReader(new StringReader(responseText)));
JsonObject jo = je.getAsJsonObject(); JsonObject jo = je.getAsJsonObject();
return new String[] {GsonHelper.getString(jo, "UserId"), GsonHelper.getString(jo, "DeviceId")}; return new String[]{GsonHelper.getString(jo, "UserId"), GsonHelper.getString(jo, "DeviceId")};
} }
@Override @Override
@@ -503,7 +493,7 @@ public class WxCpServiceImpl implements WxCpService {
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
JsonArray jsonArray = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray(); JsonArray jsonArray = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray();
String[] ips = new String[jsonArray.size()]; String[] ips = new String[jsonArray.size()];
for(int i = 0; i < jsonArray.size(); i++) { for (int i = 0; i < jsonArray.size(); i++) {
ips[i] = jsonArray.get(i).getAsString(); ips[i] = jsonArray.get(i).getAsString();
} }
return ips; return ips;
@@ -542,7 +532,7 @@ public class WxCpServiceImpl implements WxCpService {
throw e; throw e;
} }
} }
} while(++retryTimes < maxRetryTimes); } while (++retryTimes < maxRetryTimes);
throw new RuntimeException("微信服务端异常,超出重试次数"); throw new RuntimeException("微信服务端异常,超出重试次数");
} }
@@ -580,6 +570,7 @@ public class WxCpServiceImpl implements WxCpService {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
protected CloseableHttpClient getHttpclient() { protected CloseableHttpClient getHttpclient() {
return httpClient; return httpClient;
} }
@@ -649,7 +640,7 @@ public class WxCpServiceImpl implements WxCpService {
@Override @Override
public String getTaskResult(String joinId) throws WxErrorException { public String getTaskResult(String joinId) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/getresult?jobid="+joinId; String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/getresult?jobid=" + joinId;
return get(url, null); return get(url, null);
} }

View File

@@ -16,6 +16,10 @@ public class WxCpDepart implements Serializable {
private Integer parentId; private Integer parentId;
private Integer order; private Integer order;
public static WxCpDepart fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpDepart.class);
}
public Integer getId() { public Integer getId() {
return id; return id;
} }
@@ -48,10 +52,6 @@ public class WxCpDepart implements Serializable {
this.order = order; this.order = order;
} }
public static WxCpDepart fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpDepart.class);
}
public String toJson() { public String toJson() {
return WxCpGsonBuilder.create().toJson(this); return WxCpGsonBuilder.create().toJson(this);
} }

View File

@@ -9,8 +9,8 @@ import java.util.List;
/** /**
* 消息 * 消息
* @author Daniel Qian
* *
* @author Daniel Qian
*/ */
public class WxCpMessage implements Serializable { public class WxCpMessage implements Serializable {
@@ -29,151 +29,6 @@ public class WxCpMessage implements Serializable {
private String safe; private String safe;
private List<WxArticle> articles = new ArrayList<WxArticle>(); private List<WxArticle> articles = new ArrayList<WxArticle>();
public String getToUser() {
return toUser;
}
public void setToUser(String toUser) {
this.toUser = toUser;
}
public String getToParty() {
return toParty;
}
public void setToParty(String toParty) {
this.toParty = toParty;
}
public String getToTag() {
return toTag;
}
public void setToTag(String toTag) {
this.toTag = toTag;
}
public String getAgentId() {
return agentId;
}
public void setAgentId(String agentId) {
this.agentId = agentId;
}
public String getMsgType() {
return msgType;
}
public String getSafe() {
return safe;
}
public void setSafe(String safe) {
this.safe = safe;
}
/**
* <pre>
* 请使用
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_TEXT}
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_IMAGE}
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_VOICE}
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_MUSIC}
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_VIDEO}
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_NEWS}
* </pre>
* @param msgType
*/
public void setMsgType(String msgType) {
this.msgType = msgType;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getMediaId() {
return mediaId;
}
public void setMediaId(String mediaId) {
this.mediaId = mediaId;
}
public String getThumbMediaId() {
return thumbMediaId;
}
public void setThumbMediaId(String thumbMediaId) {
this.thumbMediaId = thumbMediaId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getMusicUrl() {
return musicUrl;
}
public void setMusicUrl(String musicUrl) {
this.musicUrl = musicUrl;
}
public String getHqMusicUrl() {
return hqMusicUrl;
}
public void setHqMusicUrl(String hqMusicUrl) {
this.hqMusicUrl = hqMusicUrl;
}
public List<WxArticle> getArticles() {
return articles;
}
public void setArticles(List<WxArticle> articles) {
this.articles = articles;
}
public String toJson() {
return WxCpGsonBuilder.INSTANCE.create().toJson(this);
}
public static class WxArticle {
private String title;
private String description;
private String url;
private String picUrl;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getPicUrl() {
return picUrl;
}
public void setPicUrl(String picUrl) {
this.picUrl = picUrl;
}
}
/** /**
* 获得文本消息builder * 获得文本消息builder
*/ */
@@ -216,4 +71,174 @@ public class WxCpMessage implements Serializable {
return new FileBuilder(); return new FileBuilder();
} }
public String getToUser() {
return toUser;
}
public void setToUser(String toUser) {
this.toUser = toUser;
}
public String getToParty() {
return toParty;
}
public void setToParty(String toParty) {
this.toParty = toParty;
}
public String getToTag() {
return toTag;
}
public void setToTag(String toTag) {
this.toTag = toTag;
}
public String getAgentId() {
return agentId;
}
public void setAgentId(String agentId) {
this.agentId = agentId;
}
public String getMsgType() {
return msgType;
}
/**
* <pre>
* 请使用
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_TEXT}
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_IMAGE}
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_VOICE}
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_MUSIC}
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_VIDEO}
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_NEWS}
* </pre>
*
* @param msgType
*/
public void setMsgType(String msgType) {
this.msgType = msgType;
}
public String getSafe() {
return safe;
}
public void setSafe(String safe) {
this.safe = safe;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getMediaId() {
return mediaId;
}
public void setMediaId(String mediaId) {
this.mediaId = mediaId;
}
public String getThumbMediaId() {
return thumbMediaId;
}
public void setThumbMediaId(String thumbMediaId) {
this.thumbMediaId = thumbMediaId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getMusicUrl() {
return musicUrl;
}
public void setMusicUrl(String musicUrl) {
this.musicUrl = musicUrl;
}
public String getHqMusicUrl() {
return hqMusicUrl;
}
public void setHqMusicUrl(String hqMusicUrl) {
this.hqMusicUrl = hqMusicUrl;
}
public List<WxArticle> getArticles() {
return articles;
}
public void setArticles(List<WxArticle> articles) {
this.articles = articles;
}
public String toJson() {
return WxCpGsonBuilder.INSTANCE.create().toJson(this);
}
public static class WxArticle {
private String title;
private String description;
private String url;
private String picUrl;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getPicUrl() {
return picUrl;
}
public void setPicUrl(String picUrl) {
this.picUrl = picUrl;
}
}
} }

View File

@@ -23,6 +23,10 @@ public class WxCpTag implements Serializable {
this.name = name; this.name = name;
} }
public static WxCpTag fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpTag.class);
}
public String getName() { public String getName() {
return name; return name;
} }
@@ -39,10 +43,6 @@ public class WxCpTag implements Serializable {
this.id = id; this.id = id;
} }
public static WxCpTag fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpTag.class);
}
public String toJson() { public String toJson() {
return WxCpGsonBuilder.create().toJson(this); return WxCpGsonBuilder.create().toJson(this);
} }

View File

@@ -13,6 +13,7 @@ import java.util.List;
*/ */
public class WxCpUser implements Serializable { public class WxCpUser implements Serializable {
private final List<Attr> extAttrs = new ArrayList<Attr>();
private String userId; private String userId;
private String name; private String name;
private Integer[] departIds; private Integer[] departIds;
@@ -25,7 +26,10 @@ public class WxCpUser implements Serializable {
private String avatar; private String avatar;
private Integer status; private Integer status;
private Integer enable; private Integer enable;
private final List<Attr> extAttrs = new ArrayList<Attr>();
public static WxCpUser fromJson(String json) {
return WxCpGsonBuilder.INSTANCE.create().fromJson(json, WxCpUser.class);
}
public String getUserId() { public String getUserId() {
return userId; return userId;
@@ -135,10 +139,6 @@ public class WxCpUser implements Serializable {
return WxCpGsonBuilder.INSTANCE.create().toJson(this); return WxCpGsonBuilder.INSTANCE.create().toJson(this);
} }
public static WxCpUser fromJson(String json) {
return WxCpGsonBuilder.INSTANCE.create().fromJson(json, WxCpUser.class);
}
public static class Attr { public static class Attr {
private String name; private String name;

View File

@@ -36,41 +36,41 @@ public class WxCpXmlMessage implements Serializable {
private Integer agentId; private Integer agentId;
@XStreamAlias("ToUserName") @XStreamAlias("ToUserName")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String toUserName; private String toUserName;
@XStreamAlias("FromUserName") @XStreamAlias("FromUserName")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String fromUserName; private String fromUserName;
@XStreamAlias("CreateTime") @XStreamAlias("CreateTime")
private Long createTime; private Long createTime;
@XStreamAlias("MsgType") @XStreamAlias("MsgType")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String msgType; private String msgType;
@XStreamAlias("Content") @XStreamAlias("Content")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String content; private String content;
@XStreamAlias("MsgId") @XStreamAlias("MsgId")
private Long msgId; private Long msgId;
@XStreamAlias("PicUrl") @XStreamAlias("PicUrl")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String picUrl; private String picUrl;
@XStreamAlias("MediaId") @XStreamAlias("MediaId")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String mediaId; private String mediaId;
@XStreamAlias("Format") @XStreamAlias("Format")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String format; private String format;
@XStreamAlias("ThumbMediaId") @XStreamAlias("ThumbMediaId")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String thumbMediaId; private String thumbMediaId;
@XStreamAlias("Location_X") @XStreamAlias("Location_X")
@@ -83,31 +83,31 @@ public class WxCpXmlMessage implements Serializable {
private Double scale; private Double scale;
@XStreamAlias("Label") @XStreamAlias("Label")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String label; private String label;
@XStreamAlias("Title") @XStreamAlias("Title")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String title; private String title;
@XStreamAlias("Description") @XStreamAlias("Description")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String description; private String description;
@XStreamAlias("Url") @XStreamAlias("Url")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String url; private String url;
@XStreamAlias("Event") @XStreamAlias("Event")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String event; private String event;
@XStreamAlias("EventKey") @XStreamAlias("EventKey")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String eventKey; private String eventKey;
@XStreamAlias("Ticket") @XStreamAlias("Ticket")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String ticket; private String ticket;
@XStreamAlias("Latitude") @XStreamAlias("Latitude")
@@ -120,7 +120,7 @@ public class WxCpXmlMessage implements Serializable {
private Double precision; private Double precision;
@XStreamAlias("Recognition") @XStreamAlias("Recognition")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String recognition; private String recognition;
/////////////////////////////////////// ///////////////////////////////////////
@@ -130,7 +130,7 @@ public class WxCpXmlMessage implements Serializable {
* 群发的结果 * 群发的结果
*/ */
@XStreamAlias("Status") @XStreamAlias("Status")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String status; private String status;
/** /**
* group_id下粉丝数或者openid_list中的粉丝数 * group_id下粉丝数或者openid_list中的粉丝数
@@ -162,6 +162,43 @@ public class WxCpXmlMessage implements Serializable {
@XStreamAlias("SendLocationInfo") @XStreamAlias("SendLocationInfo")
private SendLocationInfo sendLocationInfo = new SendLocationInfo(); private SendLocationInfo sendLocationInfo = new SendLocationInfo();
protected static WxCpXmlMessage fromXml(String xml) {
return XStreamTransformer.fromXml(WxCpXmlMessage.class, xml);
}
protected static WxCpXmlMessage fromXml(InputStream is) {
return XStreamTransformer.fromXml(WxCpXmlMessage.class, is);
}
/**
* 从加密字符串转换
*
* @param encryptedXml
* @param wxCpConfigStorage
* @param timestamp
* @param nonce
* @param msgSignature
*/
public static WxCpXmlMessage fromEncryptedXml(
String encryptedXml,
WxCpConfigStorage wxCpConfigStorage,
String timestamp, String nonce, String msgSignature) {
WxCpCryptUtil cryptUtil = new WxCpCryptUtil(wxCpConfigStorage);
String plainText = cryptUtil.decrypt(msgSignature, timestamp, nonce, encryptedXml);
return fromXml(plainText);
}
public static WxCpXmlMessage fromEncryptedXml(
InputStream is,
WxCpConfigStorage wxCpConfigStorage,
String timestamp, String nonce, String msgSignature) {
try {
return fromEncryptedXml(IOUtils.toString(is, "UTF-8"), wxCpConfigStorage, timestamp, nonce, msgSignature);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public Integer getAgentId() { public Integer getAgentId() {
return agentId; return agentId;
} }
@@ -197,7 +234,6 @@ public class WxCpXmlMessage implements Serializable {
* {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_LINK} * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_LINK}
* {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_EVENT} * {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_EVENT}
* </pre> * </pre>
*
*/ */
public String getMsgType() { public String getMsgType() {
return msgType; return msgType;
@@ -387,43 +423,6 @@ public class WxCpXmlMessage implements Serializable {
this.fromUserName = fromUserName; this.fromUserName = fromUserName;
} }
protected static WxCpXmlMessage fromXml(String xml) {
return XStreamTransformer.fromXml(WxCpXmlMessage.class, xml);
}
protected static WxCpXmlMessage fromXml(InputStream is) {
return XStreamTransformer.fromXml(WxCpXmlMessage.class, is);
}
/**
* 从加密字符串转换
*
* @param encryptedXml
* @param wxCpConfigStorage
* @param timestamp
* @param nonce
* @param msgSignature
*/
public static WxCpXmlMessage fromEncryptedXml(
String encryptedXml,
WxCpConfigStorage wxCpConfigStorage,
String timestamp, String nonce, String msgSignature) {
WxCpCryptUtil cryptUtil = new WxCpCryptUtil(wxCpConfigStorage);
String plainText = cryptUtil.decrypt(msgSignature, timestamp, nonce, encryptedXml);
return fromXml(plainText);
}
public static WxCpXmlMessage fromEncryptedXml(
InputStream is,
WxCpConfigStorage wxCpConfigStorage,
String timestamp, String nonce, String msgSignature) {
try {
return fromEncryptedXml(IOUtils.toString(is, "UTF-8"), wxCpConfigStorage, timestamp, nonce, msgSignature);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public String getStatus() { public String getStatus() {
return status; return status;
} }
@@ -531,11 +530,11 @@ public class WxCpXmlMessage implements Serializable {
public static class ScanCodeInfo { public static class ScanCodeInfo {
@XStreamAlias("ScanType") @XStreamAlias("ScanType")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String scanType; private String scanType;
@XStreamAlias("ScanResult") @XStreamAlias("ScanResult")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String scanResult; private String scanResult;
/** /**
@@ -566,11 +565,10 @@ public class WxCpXmlMessage implements Serializable {
@XStreamAlias("SendPicsInfo") @XStreamAlias("SendPicsInfo")
public static class SendPicsInfo { public static class SendPicsInfo {
@XStreamAlias("Count")
private Long count;
@XStreamAlias("PicList") @XStreamAlias("PicList")
protected final List<Item> picList = new ArrayList<Item>(); protected final List<Item> picList = new ArrayList<Item>();
@XStreamAlias("Count")
private Long count;
public Long getCount() { public Long getCount() {
return count; return count;
@@ -588,7 +586,7 @@ public class WxCpXmlMessage implements Serializable {
public static class Item { public static class Item {
@XStreamAlias("PicMd5Sum") @XStreamAlias("PicMd5Sum")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String PicMd5Sum; private String PicMd5Sum;
public String getPicMd5Sum() { public String getPicMd5Sum() {
@@ -605,23 +603,23 @@ public class WxCpXmlMessage implements Serializable {
public static class SendLocationInfo { public static class SendLocationInfo {
@XStreamAlias("Location_X") @XStreamAlias("Location_X")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String locationX; private String locationX;
@XStreamAlias("Location_Y") @XStreamAlias("Location_Y")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String locationY; private String locationY;
@XStreamAlias("Scale") @XStreamAlias("Scale")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String scale; private String scale;
@XStreamAlias("Label") @XStreamAlias("Label")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String label; private String label;
@XStreamAlias("Poiname") @XStreamAlias("Poiname")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String poiname; private String poiname;
public String getLocationX() { public String getLocationX() {

View File

@@ -9,7 +9,7 @@ import me.chanjar.weixin.common.util.xml.XStreamMediaIdConverter;
public class WxCpXmlOutImageMessage extends WxCpXmlOutMessage { public class WxCpXmlOutImageMessage extends WxCpXmlOutMessage {
@XStreamAlias("Image") @XStreamAlias("Image")
@XStreamConverter(value=XStreamMediaIdConverter.class) @XStreamConverter(value = XStreamMediaIdConverter.class)
private String mediaId; private String mediaId;
public WxCpXmlOutImageMessage() { public WxCpXmlOutImageMessage() {

View File

@@ -12,65 +12,20 @@ import me.chanjar.weixin.cp.util.xml.XStreamTransformer;
public abstract class WxCpXmlOutMessage { public abstract class WxCpXmlOutMessage {
@XStreamAlias("ToUserName") @XStreamAlias("ToUserName")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
protected String toUserName; protected String toUserName;
@XStreamAlias("FromUserName") @XStreamAlias("FromUserName")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
protected String fromUserName; protected String fromUserName;
@XStreamAlias("CreateTime") @XStreamAlias("CreateTime")
protected Long createTime; protected Long createTime;
@XStreamAlias("MsgType") @XStreamAlias("MsgType")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
protected String msgType; protected String msgType;
public String getToUserName() {
return toUserName;
}
public void setToUserName(String toUserName) {
this.toUserName = toUserName;
}
public String getFromUserName() {
return fromUserName;
}
public void setFromUserName(String fromUserName) {
this.fromUserName = fromUserName;
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public String getMsgType() {
return msgType;
}
public void setMsgType(String msgType) {
this.msgType = msgType;
}
protected String toXml() {
return XStreamTransformer.toXml((Class)this.getClass(), this);
}
/**
* 转换成加密的xml格式
*/
public String toEncryptedXml(WxCpConfigStorage wxCpConfigStorage) {
String plainXml = toXml();
WxCpCryptUtil pc = new WxCpCryptUtil(wxCpConfigStorage);
return pc.encrypt(plainXml);
}
/** /**
* 获得文本消息builder * 获得文本消息builder
*/ */
@@ -105,4 +60,49 @@ public abstract class WxCpXmlOutMessage {
public static NewsBuilder NEWS() { public static NewsBuilder NEWS() {
return new NewsBuilder(); return new NewsBuilder();
} }
public String getToUserName() {
return toUserName;
}
public void setToUserName(String toUserName) {
this.toUserName = toUserName;
}
public String getFromUserName() {
return fromUserName;
}
public void setFromUserName(String fromUserName) {
this.fromUserName = fromUserName;
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public String getMsgType() {
return msgType;
}
public void setMsgType(String msgType) {
this.msgType = msgType;
}
protected String toXml() {
return XStreamTransformer.toXml((Class) this.getClass(), this);
}
/**
* 转换成加密的xml格式
*/
public String toEncryptedXml(WxCpConfigStorage wxCpConfigStorage) {
String plainXml = toXml();
WxCpCryptUtil pc = new WxCpCryptUtil(wxCpConfigStorage);
return pc.encrypt(plainXml);
}
} }

View File

@@ -11,11 +11,10 @@ import java.util.List;
@XStreamAlias("xml") @XStreamAlias("xml")
public class WxCpXmlOutNewsMessage extends WxCpXmlOutMessage { public class WxCpXmlOutNewsMessage extends WxCpXmlOutMessage {
@XStreamAlias("ArticleCount")
protected int articleCount;
@XStreamAlias("Articles") @XStreamAlias("Articles")
protected final List<Item> articles = new ArrayList<Item>(); protected final List<Item> articles = new ArrayList<Item>();
@XStreamAlias("ArticleCount")
protected int articleCount;
public WxCpXmlOutNewsMessage() { public WxCpXmlOutNewsMessage() {
this.msgType = WxConsts.XML_MSG_NEWS; this.msgType = WxConsts.XML_MSG_NEWS;
@@ -39,19 +38,19 @@ public class WxCpXmlOutNewsMessage extends WxCpXmlOutMessage {
public static class Item { public static class Item {
@XStreamAlias("Title") @XStreamAlias("Title")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String Title; private String Title;
@XStreamAlias("Description") @XStreamAlias("Description")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String Description; private String Description;
@XStreamAlias("PicUrl") @XStreamAlias("PicUrl")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String PicUrl; private String PicUrl;
@XStreamAlias("Url") @XStreamAlias("Url")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String Url; private String Url;
public String getTitle() { public String getTitle() {

View File

@@ -9,7 +9,7 @@ import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
public class WxCpXmlOutTextMessage extends WxCpXmlOutMessage { public class WxCpXmlOutTextMessage extends WxCpXmlOutMessage {
@XStreamAlias("Content") @XStreamAlias("Content")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String content; private String content;
public WxCpXmlOutTextMessage() { public WxCpXmlOutTextMessage() {

View File

@@ -44,15 +44,15 @@ public class WxCpXmlOutVideoMessage extends WxCpXmlOutMessage {
public static class Video { public static class Video {
@XStreamAlias("MediaId") @XStreamAlias("MediaId")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String mediaId; private String mediaId;
@XStreamAlias("Title") @XStreamAlias("Title")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String title; private String title;
@XStreamAlias("Description") @XStreamAlias("Description")
@XStreamConverter(value=XStreamCDataConverter.class) @XStreamConverter(value = XStreamCDataConverter.class)
private String description; private String description;
public String getMediaId() { public String getMediaId() {

View File

@@ -9,7 +9,7 @@ import me.chanjar.weixin.common.util.xml.XStreamMediaIdConverter;
public class WxCpXmlOutVoiceMessage extends WxCpXmlOutMessage { public class WxCpXmlOutVoiceMessage extends WxCpXmlOutMessage {
@XStreamAlias("Voice") @XStreamAlias("Voice")
@XStreamConverter(value=XStreamMediaIdConverter.class) @XStreamConverter(value = XStreamMediaIdConverter.class)
private String mediaId; private String mediaId;
public WxCpXmlOutVoiceMessage() { public WxCpXmlOutVoiceMessage() {

View File

@@ -44,7 +44,7 @@ public class BaseBuilder<T> {
m.setToParty(this.toParty); m.setToParty(this.toParty);
m.setToTag(this.toTag); m.setToTag(this.toTag);
m.setSafe( m.setSafe(
(this.safe == null || "".equals(this.safe))? WxConsts.CUSTOM_MSG_SAFE_NO: this.safe); (this.safe == null || "".equals(this.safe)) ? WxConsts.CUSTOM_MSG_SAFE_NO : this.safe);
return m; return m;
} }

View File

@@ -8,8 +8,8 @@ import me.chanjar.weixin.cp.bean.WxCpMessage;
* <pre> * <pre>
* 用法: WxCustomMessage m = WxCustomMessage.FILE().mediaId(...).toUser(...).build(); * 用法: WxCustomMessage m = WxCustomMessage.FILE().mediaId(...).toUser(...).build();
* </pre> * </pre>
* @author Daniel Qian
* *
* @author Daniel Qian
*/ */
public final class FileBuilder extends BaseBuilder<FileBuilder> { public final class FileBuilder extends BaseBuilder<FileBuilder> {
private String mediaId; private String mediaId;

View File

@@ -8,8 +8,8 @@ import me.chanjar.weixin.cp.bean.WxCpMessage;
* <pre> * <pre>
* 用法: WxCustomMessage m = WxCustomMessage.IMAGE().mediaId(...).toUser(...).build(); * 用法: WxCustomMessage m = WxCustomMessage.IMAGE().mediaId(...).toUser(...).build();
* </pre> * </pre>
* @author Daniel Qian
* *
* @author Daniel Qian
*/ */
public final class ImageBuilder extends BaseBuilder<ImageBuilder> { public final class ImageBuilder extends BaseBuilder<ImageBuilder> {
private String mediaId; private String mediaId;

View File

@@ -12,8 +12,8 @@ import java.util.List;
* 用法: * 用法:
* WxCustomMessage m = WxCustomMessage.NEWS().addArticle(article).toUser(...).build(); * WxCustomMessage m = WxCustomMessage.NEWS().addArticle(article).toUser(...).build();
* </pre> * </pre>
* @author Daniel Qian
* *
* @author Daniel Qian
*/ */
public final class NewsBuilder extends BaseBuilder<NewsBuilder> { public final class NewsBuilder extends BaseBuilder<NewsBuilder> {

View File

@@ -8,8 +8,8 @@ import me.chanjar.weixin.cp.bean.WxCpMessage;
* <pre> * <pre>
* 用法: WxCustomMessage m = WxCustomMessage.TEXT().content(...).toUser(...).build(); * 用法: WxCustomMessage m = WxCustomMessage.TEXT().content(...).toUser(...).build();
* </pre> * </pre>
* @author Daniel Qian
* *
* @author Daniel Qian
*/ */
public final class TextBuilder extends BaseBuilder<TextBuilder> { public final class TextBuilder extends BaseBuilder<TextBuilder> {
private String content; private String content;

View File

@@ -14,8 +14,8 @@ import me.chanjar.weixin.cp.bean.WxCpMessage;
* .toUser(...) * .toUser(...)
* .build(); * .build();
* </pre> * </pre>
* @author Daniel Qian
* *
* @author Daniel Qian
*/ */
public final class VideoBuilder extends BaseBuilder<VideoBuilder> { public final class VideoBuilder extends BaseBuilder<VideoBuilder> {
private String mediaId; private String mediaId;

View File

@@ -8,8 +8,8 @@ import me.chanjar.weixin.cp.bean.WxCpMessage;
* <pre> * <pre>
* 用法: WxCustomMessage m = WxCustomMessage.VOICE().mediaId(...).toUser(...).build(); * 用法: WxCustomMessage m = WxCustomMessage.VOICE().mediaId(...).toUser(...).build();
* </pre> * </pre>
* @author Daniel Qian
* *
* @author Daniel Qian
*/ */
public final class VoiceBuilder extends BaseBuilder<VoiceBuilder> { public final class VoiceBuilder extends BaseBuilder<VoiceBuilder> {
private String mediaId; private String mediaId;

View File

@@ -4,6 +4,7 @@ import me.chanjar.weixin.cp.bean.WxCpXmlOutImageMessage;
/** /**
* 图片消息builder * 图片消息builder
*
* @author Daniel Qian * @author Daniel Qian
*/ */
public final class ImageBuilder extends BaseBuilder<ImageBuilder, WxCpXmlOutImageMessage> { public final class ImageBuilder extends BaseBuilder<ImageBuilder, WxCpXmlOutImageMessage> {

View File

@@ -8,6 +8,7 @@ import java.util.List;
/** /**
* 图文消息builder * 图文消息builder
*
* @author Daniel Qian * @author Daniel Qian
*/ */
public final class NewsBuilder extends BaseBuilder<NewsBuilder, WxCpXmlOutNewsMessage> { public final class NewsBuilder extends BaseBuilder<NewsBuilder, WxCpXmlOutNewsMessage> {
@@ -21,7 +22,7 @@ public final class NewsBuilder extends BaseBuilder<NewsBuilder, WxCpXmlOutNewsMe
public WxCpXmlOutNewsMessage build() { public WxCpXmlOutNewsMessage build() {
WxCpXmlOutNewsMessage m = new WxCpXmlOutNewsMessage(); WxCpXmlOutNewsMessage m = new WxCpXmlOutNewsMessage();
for(Item item : articles) { for (Item item : articles) {
m.addArticle(item); m.addArticle(item);
} }
setCommon(m); setCommon(m);

View File

@@ -4,8 +4,8 @@ import me.chanjar.weixin.cp.bean.WxCpXmlOutTextMessage;
/** /**
* 文本消息builder * 文本消息builder
* @author Daniel Qian
* *
* @author Daniel Qian
*/ */
public final class TextBuilder extends BaseBuilder<TextBuilder, WxCpXmlOutTextMessage> { public final class TextBuilder extends BaseBuilder<TextBuilder, WxCpXmlOutTextMessage> {
private String content; private String content;

View File

@@ -4,8 +4,8 @@ import me.chanjar.weixin.cp.bean.WxCpXmlOutVideoMessage;
/** /**
* 视频消息builder * 视频消息builder
* @author Daniel Qian
* *
* @author Daniel Qian
*/ */
public final class VideoBuilder extends BaseBuilder<VideoBuilder, WxCpXmlOutVideoMessage> { public final class VideoBuilder extends BaseBuilder<VideoBuilder, WxCpXmlOutVideoMessage> {
@@ -17,10 +17,12 @@ public final class VideoBuilder extends BaseBuilder<VideoBuilder, WxCpXmlOutVide
this.title = title; this.title = title;
return this; return this;
} }
public VideoBuilder description(String description) { public VideoBuilder description(String description) {
this.description = description; this.description = description;
return this; return this;
} }
public VideoBuilder mediaId(String mediaId) { public VideoBuilder mediaId(String mediaId) {
this.mediaId = mediaId; this.mediaId = mediaId;
return this; return this;

View File

@@ -4,6 +4,7 @@ import me.chanjar.weixin.cp.bean.WxCpXmlOutVoiceMessage;
/** /**
* 语音消息builder * 语音消息builder
*
* @author Daniel Qian * @author Daniel Qian
*/ */
public final class VoiceBuilder extends BaseBuilder<VoiceBuilder, WxCpXmlOutVoiceMessage> { public final class VoiceBuilder extends BaseBuilder<VoiceBuilder, WxCpXmlOutVoiceMessage> {

View File

@@ -2,6 +2,10 @@
* 对公众平台发送给公众账号的消息加解密示例代码. * 对公众平台发送给公众账号的消息加解密示例代码.
* *
* @copyright Copyright (c) 1998-2014 Tencent Inc. * @copyright Copyright (c) 1998-2014 Tencent Inc.
* <p>
* 针对org.apache.commons.codec.binary.Base64
* 需要导入架包commons-codec-1.9或commons-codec-1.8等其他版本)
* 官方下载地址http://commons.apache.org/proper/commons-codec/download_codec.cgi
*/ */
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------

View File

@@ -16,9 +16,7 @@ import me.chanjar.weixin.cp.bean.WxCpMessage;
import java.lang.reflect.Type; import java.lang.reflect.Type;
/** /**
*
* @author Daniel Qian * @author Daniel Qian
*
*/ */
public class WxCpMessageGsonAdapter implements JsonSerializer<WxCpMessage> { public class WxCpMessageGsonAdapter implements JsonSerializer<WxCpMessage> {

View File

@@ -26,7 +26,7 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
user.setUserId(GsonHelper.getString(o, "userid")); user.setUserId(GsonHelper.getString(o, "userid"));
user.setName(GsonHelper.getString(o, "name")); user.setName(GsonHelper.getString(o, "name"));
if(o.get("department") != null) { if (o.get("department") != null) {
JsonArray departJsonArray = o.get("department").getAsJsonArray(); JsonArray departJsonArray = o.get("department").getAsJsonArray();
Integer[] departIds = new Integer[departJsonArray.size()]; Integer[] departIds = new Integer[departJsonArray.size()];
int i = 0; int i = 0;

View File

@@ -29,16 +29,16 @@ public class XStreamTransformer {
/** /**
* 注册扩展消息的解析器 * 注册扩展消息的解析器
*
* @param clz 类型 * @param clz 类型
* @param xStream xml解析器 * @param xStream xml解析器
*/ */
public static void register(Class clz,XStream xStream){ public static void register(Class clz, XStream xStream) {
CLASS_2_XSTREAM_INSTANCE.put(clz,xStream); CLASS_2_XSTREAM_INSTANCE.put(clz, xStream);
} }
/** /**
* pojo -> xml * pojo -> xml
*
*/ */
public static <T> String toXml(Class<T> clazz, T object) { public static <T> String toXml(Class<T> clazz, T object) {
return CLASS_2_XSTREAM_INSTANCE.get(clazz).toXML(object); return CLASS_2_XSTREAM_INSTANCE.get(clazz).toXML(object);

View File

@@ -10,6 +10,13 @@ import java.io.InputStream;
public class ApiTestModule implements Module { public class ApiTestModule implements Module {
public static <T> T fromXml(Class<T> clazz, InputStream is) {
XStream xstream = XStreamInitializer.getInstance();
xstream.alias("xml", clazz);
xstream.processAnnotations(clazz);
return (T) xstream.fromXML(is);
}
@Override @Override
public void configure(Binder binder) { public void configure(Binder binder) {
InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml"); InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml");
@@ -21,13 +28,6 @@ public class ApiTestModule implements Module {
binder.bind(WxCpConfigStorage.class).toInstance(config); binder.bind(WxCpConfigStorage.class).toInstance(config);
} }
public static <T> T fromXml(Class<T> clazz, InputStream is) {
XStream xstream = XStreamInitializer.getInstance();
xstream.alias("xml", clazz);
xstream.processAnnotations(clazz);
return (T) xstream.fromXML(is);
}
@XStreamAlias("xml") @XStreamAlias("xml")
public static class WxXmlCpInMemoryConfigStorage extends WxCpInMemoryConfigStorage { public static class WxXmlCpInMemoryConfigStorage extends WxCpInMemoryConfigStorage {
@@ -40,6 +40,7 @@ public class ApiTestModule implements Module {
public String getUserId() { public String getUserId() {
return userId; return userId;
} }
public void setUserId(String userId) { public void setUserId(String userId) {
this.userId = userId; this.userId = userId;
} }

View File

@@ -9,8 +9,8 @@ import org.testng.annotations.Test;
/** /**
* 基础API测试 * 基础API测试
* @author Daniel Qian
* *
* @author Daniel Qian
*/ */
@Test(groups = "baseAPI") @Test(groups = "baseAPI")
@Guice(modules = ApiTestModule.class) @Guice(modules = ApiTestModule.class)

View File

@@ -14,7 +14,7 @@ import java.util.concurrent.Future;
@Test @Test
public class WxCpBusyRetryTest { public class WxCpBusyRetryTest {
@DataProvider(name="getService") @DataProvider(name = "getService")
public Object[][] getService() { public Object[][] getService() {
WxCpService service = new WxCpServiceImpl() { WxCpService service = new WxCpServiceImpl() {
@@ -28,8 +28,8 @@ public class WxCpBusyRetryTest {
service.setMaxRetryTimes(3); service.setMaxRetryTimes(3);
service.setRetrySleepMillis(500); service.setRetrySleepMillis(500);
return new Object[][] { return new Object[][]{
new Object[] { service } new Object[]{service}
}; };
} }

View File

@@ -44,7 +44,7 @@ public class WxCpDepartAPITest {
} }
} }
@Test(dependsOnMethods = { "testDepartGet", "testDepartCreate" }) @Test(dependsOnMethods = {"testDepartGet", "testDepartCreate"})
public void testDepartUpdate() throws WxErrorException { public void testDepartUpdate() throws WxErrorException {
System.out.println("=================更新部门"); System.out.println("=================更新部门");
depart.setName("子部门改名" + System.currentTimeMillis()); depart.setName("子部门改名" + System.currentTimeMillis());

View File

@@ -16,8 +16,8 @@ import java.util.List;
/** /**
* 测试多媒体文件上传下载 * 测试多媒体文件上传下载
* @author Daniel Qian
* *
* @author Daniel Qian
*/ */
//@Test(groups="mediaAPI", dependsOnGroups="baseAPI") //@Test(groups="mediaAPI", dependsOnGroups="baseAPI")
@Test @Test
@@ -29,7 +29,7 @@ public class WxCpMediaAPITest {
private List<String> media_ids = new ArrayList<String>(); private List<String> media_ids = new ArrayList<String>();
@Test(dataProvider="uploadMedia") @Test(dataProvider = "uploadMedia")
public void testUploadMedia(String mediaType, String fileType, String fileName) throws WxErrorException, IOException { public void testUploadMedia(String mediaType, String fileType, String fileName) throws WxErrorException, IOException {
InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName); InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName);
WxMediaUploadResult res = wxService.mediaUpload(mediaType, fileType, inputStream); WxMediaUploadResult res = wxService.mediaUpload(mediaType, fileType, inputStream);
@@ -47,15 +47,15 @@ public class WxCpMediaAPITest {
@DataProvider @DataProvider
public Object[][] uploadMedia() { public Object[][] uploadMedia() {
return new Object[][] { return new Object[][]{
new Object[] { WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, "mm.jpeg" }, new Object[]{WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, "mm.jpeg"},
new Object[] { WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, "mm.mp3" }, new Object[]{WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, "mm.mp3"},
new Object[] { WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, "mm.mp4" }, new Object[]{WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, "mm.mp4"},
new Object[] { WxConsts.MEDIA_FILE, WxConsts.FILE_JPG, "mm.jpeg" } new Object[]{WxConsts.MEDIA_FILE, WxConsts.FILE_JPG, "mm.jpeg"}
}; };
} }
@Test(dependsOnMethods = { "testUploadMedia" }, dataProvider="downloadMedia") @Test(dependsOnMethods = {"testUploadMedia"}, dataProvider = "downloadMedia")
public void testDownloadMedia(String media_id) throws WxErrorException { public void testDownloadMedia(String media_id) throws WxErrorException {
wxService.mediaDownload(media_id); wxService.mediaDownload(media_id);
} }
@@ -64,7 +64,7 @@ public class WxCpMediaAPITest {
public Object[][] downloadMedia() { public Object[][] downloadMedia() {
Object[][] params = new Object[this.media_ids.size()][]; Object[][] params = new Object[this.media_ids.size()][];
for (int i = 0; i < this.media_ids.size(); i++) { for (int i = 0; i < this.media_ids.size(); i++) {
params[i] = new Object[] { this.media_ids.get(i) }; params[i] = new Object[]{this.media_ids.get(i)};
} }
return params; return params;
} }

View File

@@ -12,7 +12,7 @@ import org.testng.annotations.Test;
* @author Daniel Qian * @author Daniel Qian
* *
*/ */
@Test(groups="customMessageAPI", dependsOnGroups = "baseAPI") @Test(groups = "customMessageAPI", dependsOnGroups = "baseAPI")
@Guice(modules = ApiTestModule.class) @Guice(modules = ApiTestModule.class)
public class WxCpMessageAPITest { public class WxCpMessageAPITest {

View File

@@ -13,8 +13,8 @@ import java.util.Map;
/** /**
* 测试消息路由器 * 测试消息路由器
* @author Daniel Qian
* *
* @author Daniel Qian
*/ */
@Test @Test
public class WxCpMessageRouterTest { public class WxCpMessageRouterTest {
@@ -51,7 +51,7 @@ public class WxCpMessageRouterTest {
.rule().async(async).handler(new WxEchoCpMessageHandler(sb, "ALL")).end(); .rule().async(async).handler(new WxEchoCpMessageHandler(sb, "ALL")).end();
} }
@Test(dataProvider="messages-1") @Test(dataProvider = "messages-1")
public void testSync(WxCpXmlMessage message, String expected) { public void testSync(WxCpXmlMessage message, String expected) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
WxCpMessageRouter router = new WxCpMessageRouter(null); WxCpMessageRouter router = new WxCpMessageRouter(null);
@@ -60,7 +60,7 @@ public class WxCpMessageRouterTest {
Assert.assertEquals(sb.toString(), expected); Assert.assertEquals(sb.toString(), expected);
} }
@Test(dataProvider="messages-1") @Test(dataProvider = "messages-1")
public void testAsync(WxCpXmlMessage message, String expected) throws InterruptedException { public void testAsync(WxCpXmlMessage message, String expected) throws InterruptedException {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
WxCpMessageRouter router = new WxCpMessageRouter(null); WxCpMessageRouter router = new WxCpMessageRouter(null);
@@ -98,7 +98,7 @@ public class WxCpMessageRouterTest {
Thread.sleep(1000l * 2); Thread.sleep(1000l * 2);
} }
@DataProvider(name="messages-1") @DataProvider(name = "messages-1")
public Object[][] messages2() { public Object[][] messages2() {
WxCpXmlMessage message1 = new WxCpXmlMessage(); WxCpXmlMessage message1 = new WxCpXmlMessage();
message1.setMsgType(WxConsts.XML_MSG_TEXT); message1.setMsgType(WxConsts.XML_MSG_TEXT);
@@ -137,40 +137,21 @@ public class WxCpMessageRouterTest {
c4.setContent("CONTENT_1"); c4.setContent("CONTENT_1");
return new Object[][] { return new Object[][]{
new Object[] { message1, WxConsts.XML_MSG_TEXT + "," }, new Object[]{message1, WxConsts.XML_MSG_TEXT + ","},
new Object[] { message2, WxConsts.EVT_CLICK + "," }, new Object[]{message2, WxConsts.EVT_CLICK + ","},
new Object[] { message3, "KEY_1," }, new Object[]{message3, "KEY_1,"},
new Object[] { message4, "CONTENT_1," }, new Object[]{message4, "CONTENT_1,"},
new Object[] { message5, "ALL," }, new Object[]{message5, "ALL,"},
new Object[] { message6, "abcd," }, new Object[]{message6, "abcd,"},
new Object[] { message7, "matcher," }, new Object[]{message7, "matcher,"},
new Object[] { c2, "COMBINE_2," }, new Object[]{c2, "COMBINE_2,"},
new Object[] { c3, "COMBINE_3," }, new Object[]{c3, "COMBINE_3,"},
new Object[] { c4, "COMBINE_4," } new Object[]{c4, "COMBINE_4,"}
}; };
} }
public static class WxEchoCpMessageHandler implements WxCpMessageHandler {
private StringBuffer sb;
private String echoStr;
public WxEchoCpMessageHandler(StringBuffer sb, String echoStr) {
this.sb = sb;
this.echoStr = echoStr;
}
@Override
public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map<String, Object> context, WxCpService wxCpService,
WxSessionManager sessionManager) {
sb.append(this.echoStr).append(',');
return null;
}
}
@DataProvider @DataProvider
public Object[][] standardSessionManager() { public Object[][] standardSessionManager() {
@@ -180,8 +161,8 @@ public class WxCpMessageRouterTest {
ism.setProcessExpiresFrequency(1); ism.setProcessExpiresFrequency(1);
ism.setBackgroundProcessorDelay(1); ism.setBackgroundProcessorDelay(1);
return new Object[][] { return new Object[][]{
new Object[] { ism } new Object[]{ism}
}; };
} }
@@ -292,6 +273,25 @@ public class WxCpMessageRouterTest {
} }
} }
public static class WxEchoCpMessageHandler implements WxCpMessageHandler {
private StringBuffer sb;
private String echoStr;
public WxEchoCpMessageHandler(StringBuffer sb, String echoStr) {
this.sb = sb;
this.echoStr = echoStr;
}
@Override
public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map<String, Object> context, WxCpService wxCpService,
WxSessionManager sessionManager) {
sb.append(this.echoStr).append(',');
return null;
}
}
public static class WxSessionMessageHandler implements WxCpMessageHandler { public static class WxSessionMessageHandler implements WxCpMessageHandler {
@Override @Override

View File

@@ -41,7 +41,7 @@ public class WxCpTagAPITest {
@Test(dependsOnMethods = "testTagGet") @Test(dependsOnMethods = "testTagGet")
public void testTagAddUsers() throws Exception { public void testTagAddUsers() throws Exception {
List<String> userIds = new ArrayList<String>(); List<String> userIds = new ArrayList<String>();
userIds.add(((ApiTestModule.WxXmlCpInMemoryConfigStorage)configStorage).getUserId()); userIds.add(((ApiTestModule.WxXmlCpInMemoryConfigStorage) configStorage).getUserId());
wxService.tagAddUsers(tagId, userIds, null); wxService.tagAddUsers(tagId, userIds, null);
} }
@@ -54,7 +54,7 @@ public class WxCpTagAPITest {
@Test(dependsOnMethods = "testTagGetUsers") @Test(dependsOnMethods = "testTagGetUsers")
public void testTagRemoveUsers() throws Exception { public void testTagRemoveUsers() throws Exception {
List<String> userIds = new ArrayList<String>(); List<String> userIds = new ArrayList<String>();
userIds.add(((ApiTestModule.WxXmlCpInMemoryConfigStorage)configStorage).getUserId()); userIds.add(((ApiTestModule.WxXmlCpInMemoryConfigStorage) configStorage).getUserId());
wxService.tagRemoveUsers(tagId, userIds); wxService.tagRemoveUsers(tagId, userIds);
} }

View File

@@ -28,7 +28,7 @@ public class WxCpUserAPITest {
WxCpUser user = new WxCpUser(); WxCpUser user = new WxCpUser();
user.setUserId("some.woman"); user.setUserId("some.woman");
user.setName("Some Woman"); user.setName("Some Woman");
user.setDepartIds(new Integer[] { 9, 8 }); user.setDepartIds(new Integer[]{9, 8});
user.setEmail("none@none.com"); user.setEmail("none@none.com");
user.setGender(""); user.setGender("");
user.setMobile("13560084979"); user.setMobile("13560084979");

View File

@@ -1,23 +1,21 @@
package me.chanjar.weixin.cp.api; package me.chanjar.weixin.cp.api;
import com.google.inject.Inject;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.bean.menu.WxMenuButton;
import me.chanjar.weixin.common.exception.WxErrorException;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.inject.Inject;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.bean.menu.WxMenuButton;
import me.chanjar.weixin.common.exception.WxErrorException;
/** /**
* 测试菜单 * 测试菜单
* @author Daniel Qian
* *
* @author Daniel Qian
*/ */
@Test(groups="menuAPI", dependsOnGroups="baseAPI") @Test(groups = "menuAPI", dependsOnGroups = "baseAPI")
@Guice(modules = ApiTestModule.class) @Guice(modules = ApiTestModule.class)
public class WxMenuAPITest { public class WxMenuAPITest {
@@ -29,17 +27,17 @@ public class WxMenuAPITest {
wxService.menuCreate(wxMenu); wxService.menuCreate(wxMenu);
} }
@Test(dependsOnMethods = { "testCreateMenu"}) @Test(dependsOnMethods = {"testCreateMenu"})
public void testGetMenu() throws WxErrorException { public void testGetMenu() throws WxErrorException {
Assert.assertNotNull(wxService.menuGet()); Assert.assertNotNull(wxService.menuGet());
} }
@Test(dependsOnMethods = { "testGetMenu"}) @Test(dependsOnMethods = {"testGetMenu"})
public void testDeleteMenu() throws WxErrorException { public void testDeleteMenu() throws WxErrorException {
wxService.menuDelete(); wxService.menuDelete();
} }
@DataProvider(name="menu") @DataProvider(name = "menu")
public Object[][] getMenu() { public Object[][] getMenu() {
WxMenu menu = new WxMenu(); WxMenu menu = new WxMenu();
WxMenuButton button1 = new WxMenuButton(); WxMenuButton button1 = new WxMenuButton();
@@ -78,8 +76,8 @@ public class WxMenuAPITest {
button3.getSubButtons().add(button32); button3.getSubButtons().add(button32);
button3.getSubButtons().add(button33); button3.getSubButtons().add(button33);
return new Object[][] { return new Object[][]{
new Object[] { new Object[]{
menu menu
} }
}; };

View File

@@ -13,17 +13,16 @@ import java.io.InputStream;
@XStreamAlias("xml") @XStreamAlias("xml")
class WxCpDemoInMemoryConfigStorage extends WxCpInMemoryConfigStorage { class WxCpDemoInMemoryConfigStorage extends WxCpInMemoryConfigStorage {
@Override
public String toString() {
return "SimpleWxConfigProvider [appidOrCorpid=" + corpId + ", corpSecret=" + corpSecret + ", accessToken=" + accessToken
+ ", expiresTime=" + expiresTime + ", token=" + token + ", aesKey=" + aesKey + "]";
}
public static WxCpDemoInMemoryConfigStorage fromXml(InputStream is) { public static WxCpDemoInMemoryConfigStorage fromXml(InputStream is) {
XStream xstream = XStreamInitializer.getInstance(); XStream xstream = XStreamInitializer.getInstance();
xstream.processAnnotations(WxCpDemoInMemoryConfigStorage.class); xstream.processAnnotations(WxCpDemoInMemoryConfigStorage.class);
return (WxCpDemoInMemoryConfigStorage) xstream.fromXML(is); return (WxCpDemoInMemoryConfigStorage) xstream.fromXML(is);
} }
@Override
public String toString() {
return "SimpleWxConfigProvider [appidOrCorpid=" + corpId + ", corpSecret=" + corpSecret + ", accessToken=" + accessToken
+ ", expiresTime=" + expiresTime + ", token=" + token + ", aesKey=" + aesKey + "]";
}
} }

View File

@@ -18,7 +18,8 @@ public class WxCpOAuth2Servlet extends HttpServlet {
this.wxCpService = wxCpService; this.wxCpService = wxCpService;
} }
@Override protected void service(HttpServletRequest request, HttpServletResponse response) @Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8"); response.setContentType("text/html;charset=utf-8");