From 17949abed22b5310f027b5606c577f5eb76fb766 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=83=A1=E9=87=91=E5=AE=87?=
Date: Mon, 14 Aug 2017 13:28:04 +0800
Subject: [PATCH] component
---
.../weixin4j/mp/WeixinComponentProxy.java | 78 +-
.../com/foxinmy/weixin4j/mp/WeixinProxy.java | 4199 +++++++++--------
.../foxinmy/weixin4j/mp/api/ComponentApi.java | 154 +-
.../WeixinTokenComponentCreator.java | 70 +-
4 files changed, 2247 insertions(+), 2254 deletions(-)
diff --git a/weixin4j-mp/src/main/java/com/foxinmy/weixin4j/mp/WeixinComponentProxy.java b/weixin4j-mp/src/main/java/com/foxinmy/weixin4j/mp/WeixinComponentProxy.java
index 576c2b44..0108739a 100644
--- a/weixin4j-mp/src/main/java/com/foxinmy/weixin4j/mp/WeixinComponentProxy.java
+++ b/weixin4j-mp/src/main/java/com/foxinmy/weixin4j/mp/WeixinComponentProxy.java
@@ -57,8 +57,7 @@ public class WeixinComponentProxy {
* token管理
*/
public WeixinComponentProxy(CacheStorager cacheStorager) {
- this(JSON.parseObject(Weixin4jConfigUtil.getValue("account"),
- WeixinMpAccount.class), cacheStorager);
+ this(JSON.parseObject(Weixin4jConfigUtil.getValue("account"), WeixinMpAccount.class), cacheStorager);
}
/**
@@ -69,26 +68,20 @@ public class WeixinComponentProxy {
* @param cacheStorager
* token管理
*/
- public WeixinComponentProxy(WeixinMpAccount weixinMpAccount,
- CacheStorager cacheStorager) {
+ public WeixinComponentProxy(WeixinMpAccount weixinMpAccount, CacheStorager cacheStorager) {
if (weixinMpAccount == null) {
- throw new IllegalArgumentException(
- "weixinMpAccount must not be empty");
+ throw new IllegalArgumentException("weixinMpAccount must not be empty");
}
if (cacheStorager == null) {
- throw new IllegalArgumentException(
- "cacheStorager must not be empty");
+ throw new IllegalArgumentException("cacheStorager must not be empty");
}
this.weixinMpAccount = weixinMpAccount;
- this.componentMap = new HashMap(weixinMpAccount
- .getComponents().size());
+ this.componentMap = new HashMap(weixinMpAccount.getComponents().size());
for (WeixinAccount component : weixinMpAccount.getComponents()) {
- this.componentMap.put(component.getId(), new ComponentApi(
- new TicketManager(component.getId(), component.getSecret(),
- cacheStorager)));
+ this.componentMap.put(component.getId(),
+ new ComponentApi(new TicketManager(component.getId(), component.getSecret(), cacheStorager)));
}
- this.componentMap.put(null, componentMap.get(weixinMpAccount
- .getComponents().get(0).getId()));
+ this.componentMap.put(null, componentMap.get(weixinMpAccount.getComponents().get(0).getId()));
}
/**
@@ -134,8 +127,7 @@ public class WeixinComponentProxy {
* @see com.foxinmy.weixin4j.mp.api.ComponentApi#getPreCodeManager()
* @throws WeixinException
*/
- public String getPreComponentTicket(String componentId)
- throws WeixinException {
+ public String getPreComponentTicket(String componentId) throws WeixinException {
ComponentApi component = component(componentId);
Token token = component.getTicketManager().getTicket();
if (token == null || StringUtil.isBlank(token.getAccessToken())) {
@@ -153,16 +145,14 @@ public class WeixinComponentProxy {
* 组件ticket内容
* @throws WeixinException
*/
- public void cacheComponentTicket(String componentId, String componentTicket)
- throws WeixinException {
- component(componentId).getTicketManager()
- .cachingTicket(componentTicket);
+ public void cacheComponentTicket(String componentId, String componentTicket) throws WeixinException {
+ component(componentId).getTicketManager().cachingTicket(componentTicket);
}
/**
- * 应用组件授权 需先缓存ticket
- * redirectUri默认填写weixin4j.properties#component.oauth.redirect.uri
- * state默认填写state
+ * 应用组件授权 需先缓存ticket
+ * redirectUri默认填写weixin4j.properties#component.oauth.redirect.uri
+ * state默认填写state
*
* @param componentId
* 组件ID
@@ -170,17 +160,14 @@ public class WeixinComponentProxy {
* @return 请求授权的URL
* @throws WeixinException
*/
- public String getComponentAuthorizationURL(String componentId)
- throws WeixinException {
- String redirectUri = Weixin4jConfigUtil
- .getValue("component.oauth.redirect.uri");
+ public String getComponentAuthorizationURL(String componentId) throws WeixinException {
+ String redirectUri = Weixin4jConfigUtil.getValue("component.oauth.redirect.uri");
return getComponentAuthorizationURL(componentId, redirectUri, "state");
}
/**
- * 应用组件授权 需先缓存ticket,在授权完成之后需要调用ComponentApi#exchangeAuthInfo方法
- * ,否则无法缓存token相关导致后续的组件接口调用失败
+ * 应用组件授权 需先缓存ticket,在授权完成之后需要调用ComponentApi#
+ * exchangeAuthorizerToken方法 ,否则无法缓存token相关导致后续的组件接口调用失败
*
* @param componentId
* 组件ID
@@ -192,17 +179,17 @@ public class WeixinComponentProxy {
* @see com.foxinmy.weixin4j.mp.api.ComponentApi
* @see com.foxinmy.weixin4j.mp.api.ComponentApi#getTicketManager()
* @see com.foxinmy.weixin4j.mp.api.ComponentApi#getPreCodeManager()
- * @see com.foxinmy.weixin4j.mp.api.ComponentApi#exchangeAuthInfo(String)
- * @see 应用组件授权
+ * @see com.foxinmy.weixin4j.mp.api.ComponentApi#exchangeAuthorizerToken(String)
+ * @see
+ * 应用组件授权
* @return 请求授权的URL
* @throws WeixinException
*/
- public String getComponentAuthorizationURL(String componentId,
- String redirectUri, String state) throws WeixinException {
+ public String getComponentAuthorizationURL(String componentId, String redirectUri, String state)
+ throws WeixinException {
try {
- return String.format(URLConsts.COMPONENT_OAUTH_URL, componentId,
- getPreComponentTicket(componentId),
+ return String.format(URLConsts.COMPONENT_OAUTH_URL, componentId, getPreComponentTicket(componentId),
URLEncoder.encode(redirectUri, Consts.UTF_8.name()), state);
} catch (UnsupportedEncodingException e) {
;
@@ -210,5 +197,20 @@ public class WeixinComponentProxy {
return "";
}
+ /**
+ * 创建WeixinProxy对象
+ *
+ * @param componentId
+ * 组件ID
+ * @param authAppId
+ * 已授权的appid
+ * @see com.foxinmy.weixin4j.mp.WeixinProxy
+ * @return
+ */
+ public WeixinProxy getWeixinProxy(String componentId, String authAppId) {
+ return new WeixinProxy(component(componentId).getRefreshTokenManager(authAppId),
+ component(componentId).getTokenManager());
+ }
+
public final static String VERSION = "1.7.7";
}
diff --git a/weixin4j-mp/src/main/java/com/foxinmy/weixin4j/mp/WeixinProxy.java b/weixin4j-mp/src/main/java/com/foxinmy/weixin4j/mp/WeixinProxy.java
index 7b937fd1..21d1fc79 100644
--- a/weixin4j-mp/src/main/java/com/foxinmy/weixin4j/mp/WeixinProxy.java
+++ b/weixin4j-mp/src/main/java/com/foxinmy/weixin4j/mp/WeixinProxy.java
@@ -85,2085 +85,2122 @@ import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
* @see api文档
*/
public class WeixinProxy {
- /**
- * 授权API
- */
- private final OauthApi oauthApi;
- /**
- * 媒体素材API
- */
- private final MediaApi mediaApi;
- /**
- * 客服消息API
- */
- private final NotifyApi notifyApi;
- /**
- * 多客服API
- */
- private final CustomApi customApi;
- /**
- * 群发消息API
- */
- private final MassApi massApi;
- /**
- * 用户API
- */
- private final UserApi userApi;
- /**
- * 分组API
- */
- private final GroupApi groupApi;
- /**
- * 菜单API
- */
- private final MenuApi menuApi;
- /**
- * 二维码API
- */
- private final QrApi qrApi;
- /**
- * 模板消息API
- */
- private final TmplApi tmplApi;
- /**
- * 辅助API
- */
- private final HelperApi helperApi;
- /**
- * 数据统计API
- */
- private final DataApi dataApi;
- /**
- * 标签API
- */
- private final TagApi tagApi;
- /**
- * 卡券API
- */
- private final CardApi cardApi;
- /**
- * 文章评论API
- */
- private final CommentApi commentApi;
- /**
- * token管理
- */
- private final TokenManager tokenManager;
- /**
- * 账号信息
- */
- private final WeixinAccount weixinAccount;
- /**
- * token存储
- */
- private final CacheStorager cacheStorager;
-
- /**
- * 微信接口实现(使用weixin4j.properties配置的account账号信息,
- * 使用FileCacheStorager文件方式缓存TOKEN)
- */
- public WeixinProxy() {
- this(new FileCacheStorager());
- }
-
- /**
- * 微信接口实现(使用weixin4j.properties配置的account账号信息)
- *
- * @param cacheStorager
- * token管理
- */
- public WeixinProxy(CacheStorager cacheStorager) {
- this(Weixin4jConfigUtil.getWeixinAccount(), cacheStorager);
- }
-
- /**
- * 微信接口实现
- *
- * @param weixinAccount
- * 账号信息
- * @param cacheStorager
- * token管理
- */
- public WeixinProxy(WeixinAccount weixinAccount, CacheStorager cacheStorager) {
- this(weixinAccount, new WeixinTokenCreator(weixinAccount.getId(), weixinAccount.getSecret()), cacheStorager);
- }
-
- /**
- * 微信接口实现
- *
- * @param weixinAccount
- * 微信账号
- * @param tokenCreator
- * token的创建
- * @param cacheStorager
- * token的存储
- */
- private WeixinProxy(WeixinAccount weixinAccount, TokenCreator tokenCreator, CacheStorager cacheStorager) {
- if (weixinAccount == null) {
- throw new IllegalArgumentException("weixinAccount must not be empty");
- }
- if (tokenCreator == null) {
- throw new IllegalArgumentException("tokenCreator must not be empty");
- }
- if (cacheStorager == null) {
- throw new IllegalArgumentException("cacheStorager must not be empty");
- }
- this.tokenManager = new TokenManager(tokenCreator, cacheStorager);
- this.weixinAccount = weixinAccount;
- this.cacheStorager = cacheStorager;
- this.oauthApi = new OauthApi(weixinAccount);
- this.mediaApi = new MediaApi(tokenManager);
- this.notifyApi = new NotifyApi(tokenManager);
- this.customApi = new CustomApi(tokenManager);
- this.massApi = new MassApi(tokenManager);
- this.userApi = new UserApi(tokenManager);
- this.groupApi = new GroupApi(tokenManager);
- this.menuApi = new MenuApi(tokenManager);
- this.qrApi = new QrApi(tokenManager);
- this.tmplApi = new TmplApi(tokenManager);
- this.helperApi = new HelperApi(tokenManager);
- this.dataApi = new DataApi(tokenManager);
- this.tagApi = new TagApi(tokenManager);
- this.cardApi = new CardApi(tokenManager);
- this.commentApi = new CommentApi(tokenManager);
- }
-
- /**
- * 获取微信账号信息
- *
- * @return
- */
- public WeixinAccount getWeixinAccount() {
- return weixinAccount;
- }
-
- /**
- * token管理
- *
- * @return
- */
- public TokenManager getTokenManager() {
- return this.tokenManager;
- }
-
- /**
- * 获取oauth授权API
- *
- * @see com.foxinmy.weixin4j.mp.api.OauthApi
- * @return
- */
- public OauthApi getOauthApi() {
- return oauthApi;
- }
-
- /**
- * 获取JSSDK Ticket的tokenManager
- *
- * @param ticketType
- * 票据类型
- * @return
- */
- public TokenManager getTicketManager(TicketType ticketType) {
- return new TokenManager(new WeixinTicketCreator(ticketType, this.tokenManager),
- this.cacheStorager);
- }
-
- /**
- * 上传图文消息内的图片获取URL
- * 请注意,本接口所上传的图片不占用公众号的素材库中图片数量的5000个的限制。图片仅支持jpg/png格式,大小必须在1MB以下。
- *
- * @param is
- * 图片数据流
- * @param fileName
- * 文件名 为空时将自动生成
- * @return 图片URL 可用于后续群发中,放置到图文消息中
- * @see com.foxinmy.weixin4j.mp.api.MediaApi
- * @throws WeixinException
- */
- public String uploadImage(InputStream is, String fileName) throws WeixinException {
- return mediaApi.uploadImage(is, fileName);
- }
-
- /**
- * 上传群发中的视频素材
- *
- * @param is
- * 图片数据流
- * @param fileName
- * 文件名 为空时将自动生成
- * @param title
- * 视频标题 非空
- * @param description
- * 视频描述 可为空
- * @return 群发视频消息对象
- * @throws WeixinException
- * @see com.foxinmy.weixin4j.mp.api.MediaApi
- * @see
- * 高级群发
- * @see com.foxinmy.weixin4j.tuple.MpVideo
- */
- public MpVideo uploadVideo(InputStream is, String fileName, String title, String description)
- throws WeixinException {
- return mediaApi.uploadVideo(is, fileName, title, description);
- }
-
- /**
- * 上传媒体文件
- * 此接口只包含图片、语音、缩略图、视频(临时)四种媒体类型的上传
- *
- *
- * @param isMaterial
- * 是否永久上传
- * @param is
- * 媒体数据流
- * @param fileName
- * 文件名 为空时将自动生成
- * @return 上传到微信服务器返回的媒体标识
- * @see
- * 上传临时素材
- * @see
- * 上传永久素材
- * @see com.foxinmy.weixin4j.model.media.MediaUploadResult
- * @see com.foxinmy.weixin4j.type.MediaType
- * @see com.foxinmy.weixin4j.mp.api.MediaApi
- * @throws WeixinException
- */
- public MediaUploadResult uploadMedia(boolean isMaterial, InputStream is, String fileName) throws WeixinException {
- return mediaApi.uploadMedia(isMaterial, is, fileName);
- }
-
- /**
- * 下载媒体文件
- *
- * @param mediaId
- * 媒体ID
- * @param isMaterial
- * 是否永久素材
- * @return 媒体文件下载结果
- * @throws WeixinException
- * @see com.foxinmy.weixin4j.mp.api.MediaApi
- * @see com.foxinmy.weixin4j.model.media.MediaDownloadResult
- * @see
- * 下载临时媒体素材
- * @see
- * 下载永久媒体素材
- */
- public MediaDownloadResult downloadMedia(String mediaId, boolean isMaterial) throws WeixinException {
- return mediaApi.downloadMedia(mediaId, isMaterial);
- }
-
- /**
- * 上传永久图文素材
- *
- * 、新增的永久素材也可以在公众平台官网素材管理模块中看到,永久素材的数量是有上限的,请谨慎新增。图文消息素材和图片素材的上限为5000,
- * 其他类型为1000
- *
- *
- * @param articles
- * 图文列表
- * @return 上传到微信服务器返回的媒体标识
- * @throws WeixinException
- * @see com.foxinmy.weixin4j.mp.api.MediaApi
- * @see com.foxinmy.weixin4j.tuple.MpArticle
- * @see
- * 上传永久媒体素材
- */
- public String uploadMaterialArticle(List articles) throws WeixinException {
- return mediaApi.uploadMaterialArticle(articles);
- }
-
- /**
- * 下载永久图文素材
- *
- * @param mediaId
- * 媒体ID
- * @return 图文列表
- * @throws WeixinException
- * @see {@link #downloadMedia(String, boolean)}
- * @see com.foxinmy.weixin4j.tuple.MpArticle
- * @see com.foxinmy.weixin4j.mp.api.MediaApi
- */
- public List downloadArticle(String mediaId) throws WeixinException {
- return mediaApi.downloadArticle(mediaId);
- }
-
- /**
- * 更新永久图文素材
- *
- * @param mediaId
- * 要修改的图文消息的id
- * @param index
- * 要更新的文章在图文消息中的位置(多图文消息时,此字段才有意义),第一篇为0
- * @param article
- * 图文对象
- * @return 处理结果
- * @throws WeixinException
- * @see com.foxinmy.weixin4j.mp.api.MediaApi
- * @see com.foxinmy.weixin4j.tuple.MpArticle
- * @see
- * 更新永久图文素材
- */
- public ApiResult updateMaterialArticle(String mediaId, int index, MpArticle article) throws WeixinException {
- return mediaApi.updateMaterialArticle(mediaId, index, article);
- }
-
- /**
- * 删除永久媒体素材
- *
- * @param mediaId
- * 媒体素材的media_id
- * @return 处理结果
- * @throws WeixinException
- * @see com.foxinmy.weixin4j.mp.api.MediaApi
- * @see
- * 删除永久媒体素材
- */
- public ApiResult deleteMaterialMedia(String mediaId) throws WeixinException {
- return mediaApi.deleteMaterialMedia(mediaId);
- }
-
- /**
- * 上传永久视频素材
- *
- * @param is
- * 大小不超过1M且格式为MP4的视频文件
- * @param fileName
- * 文件名 为空时将自动生成
- * @param title
- * 视频标题
- * @param introduction
- * 视频描述
- * @return 上传到微信服务器返回的媒体标识
- * @see
- * 上传永久媒体素材
- * @see com.foxinmy.weixin4j.mp.api.MediaApi
- * @throws WeixinException
- */
- public String uploadMaterialVideo(InputStream is, String fileName, String title, String introduction)
- throws WeixinException {
- return mediaApi.uploadMaterialVideo(is, fileName, title, introduction);
- }
-
- /**
- * 获取永久媒体素材的总数
- * .图片和图文消息素材(包括单图文和多图文)的总数上限为5000,其他素材的总数上限为1000
- *
- * @return 总数对象
- * @throws WeixinException
- * @see com.com.foxinmy.weixin4j.model.media.MediaCounter
- * @see
- * 获取素材总数
- * @see com.foxinmy.weixin4j.mp.api.MediaApi
- */
- public MediaCounter countMaterialMedia() throws WeixinException {
- return mediaApi.countMaterialMedia();
- }
-
- /**
- * 获取媒体素材记录列表
- *
- * @param mediaType
- * 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)
- * @param pageable
- * 分页数据
- * @return 媒体素材的记录对象
- * @throws WeixinException
- * @see com.foxinmy.weixin4j.mp.api.MediaApi
- * @see com.foxinmy.weixin4j.model.media.MediaRecord
- * @see com.foxinmy.weixin4j.type.MediaType
- * @see com.foxinmy.weixin4j.model.media.MediaItem
- * @see com.foxinmy.weixin4j.model.paging.Pageable
- * @see com.foxinmy.weixin4j.model.paging.Pagedata
- * @see
- * 获取素材列表
- */
- public MediaRecord listMaterialMedia(MediaType mediaType, Pageable pageable) throws WeixinException {
- return mediaApi.listMaterialMedia(mediaType, pageable);
- }
-
- /**
- * 获取全部的媒体素材
- *
- * @param mediaType
- * 媒体类型
- * @return 素材列表
- * @see com.foxinmy.weixin4j.mp.api.MediaApi
- * @see {@link #listMaterialMedia(MediaType, Pageable)}
- * @throws WeixinException
- */
- public List listAllMaterialMedia(MediaType mediaType) throws WeixinException {
- return mediaApi.listAllMaterialMedia(mediaType);
- }
-
- /**
- * 发送客服消息(在48小时内不限制发送次数)
- *
- * @param notify
- * 客服消息对象
- * @return 处理结果
- * @see {@link #sendNotify(NotifyMessage,String) }
- * @throws WeixinException
- */
- public ApiResult sendNotify(NotifyMessage notify) throws WeixinException {
- return notifyApi.sendNotify(notify);
- }
-
- /**
- * 发送客服消息(在48小时内不限制发送次数)
- *
- * @param notify
- * 客服消息对象
- * @param kfAccount
- * 客服账号 可为空
- * @throws WeixinException
- * @return 处理结果
- * @see
- * 发送客服消息
- * @see com.foxinmy.weixin4j.tuple.Text
- * @see com.foxinmy.weixin4j.tuple.Image
- * @see com.foxinmy.weixin4j.tuple.Voice
- * @see com.foxinmy.weixin4j.tuple.Video
- * @see com.foxinmy.weixin4j.tuple.Music
- * @see com.foxinmy.weixin4j.tuple.News
- * @see com.foxinmy.weixin4j.mp.api.NotifyApi
- */
- public ApiResult sendNotify(NotifyMessage notify, String kfAccount) throws WeixinException {
- return notifyApi.sendNotify(notify, kfAccount);
- }
-
- /**
- * 客服聊天记录
- *
- * @param startTime
- * 查询开始时间
- * @param endTime
- * 查询结束时间 每次查询不能跨日查询
- * @param number
- * 最多10000条
- * @see com.foxinmy.weixin4j.mp.model.CustomRecord
- * @see com.foxinmy.weixin4j.mp.api.CustomApi
- * @see 查询客服聊天记录
- * @see
- * 查询客服聊天记录
- * @throws WeixinException
- */
- public List getKfChatRecord(Date startTime, Date endTime, int number) throws WeixinException {
- return customApi.getKfChatRecord(startTime, endTime, number);
- }
-
- /**
- * 获取公众号中所设置的客服基本信息,包括客服工号、客服昵称、客服登录账号
- *
- * @return 多客服信息列表
- * @see com.foxinmy.weixin4j.mp.model.KfAccount
- * @see com.foxinmy.weixin4j.mp.api.CustomApi
- * @see
- * 获取客服基本信息
- * @throws WeixinException
- */
- public List listKfAccount() throws WeixinException {
- return customApi.listKfAccount();
- }
-
- /**
- * 获取在线客服在线状态(手机在线、PC客户端在线、手机和PC客户端全都在线)、客服自动接入最大值、 客服当前接待客户数
- *
- * @return 多客服在线信息列表
- * @see com.foxinmy.weixin4j.mp.model.KfOnlineAccount
- * @see com.foxinmy.weixin4j.mp.api.CustomApi
- * @see
- * 获取客服在线信息
- * @throws WeixinException
- */
- public List listOnlineKfAccount() throws WeixinException {
- return customApi.listOnlineKfAccount();
- }
-
- /**
- * 新增客服账号
- *
- * @param id
- * 完整客服账号,格式为:账号前缀@公众号微信号,账号前缀最多10个字符,必须是英文或者数字字符。如果没有公众号微信号,
- * 请前往微信公众平台设置。
- * @param name
- * 客服昵称,最长6个汉字或12个英文字符
- * @return 处理结果
- * @throws WeixinException
- * @see com.foxinmy.weixin4j.mp.api.CustomApi 客服管理接口返回码
- * @see
- * 新增客服账号
- */
- public ApiResult createKfAccount(String id, String name) throws WeixinException {
- return customApi.createKfAccount(id, name);
- }
-
- /**
- * 更新客服账号
- *
- * @param id
- * 完整客服账号,格式为:账号前缀@公众号微信号,账号前缀最多10个字符,必须是英文或者数字字符。如果没有公众号微信号,
- * 请前往微信公众平台设置。
- * @param name
- * 客服昵称,最长6个汉字或12个英文字符
- * @return 处理结果
- * @throws WeixinException
- * @see com.foxinmy.weixin4j.mp.api.CustomApi
- * @see
- * 更新客服账号
- */
- public ApiResult updateKfAccount(String id, String name) throws WeixinException {
- return customApi.updateKfAccount(id, name);
- }
-
- /**
- * 邀请绑定客服帐号
- * 新添加的客服帐号是不能直接使用的,只有客服人员用微信号绑定了客服账号后,方可登录Web客服进行操作。此接口发起一个绑定邀请到客服人员微信号
- * ,客服人员需要在微信客户端上用该微信号确认后帐号才可用。尚未绑定微信号的帐号可以进行绑定邀请操作,邀请未失效时不能对该帐号进行再次绑定微信号邀请。
- *
- * @param kfAccount
- * 完整客服帐号,格式为:帐号前缀@公众号微信号
- * @param inviteAccount
- * 接收绑定邀请的客服微信号
- * @return 处理结果
- * @see com.foxinmy.weixin4j.mp.api.CustomApi
- * @see 邀请绑定客服帐号
- * @throws WeixinException
- */
- public ApiResult inviteKfAccount(String kfAccount, String inviteAccount) throws WeixinException {
- return customApi.inviteKfAccount(kfAccount, inviteAccount);
- }
-
- /**
- * 上传客服头像
- *
- * @param accountId
- * 完整客服账号,格式为:账号前缀@公众号微信号
- * @param is
- * 头像图片文件必须是jpg格式,推荐使用640*640大小的图片以达到最佳效果
- * @param fileName
- * 文件名 为空时将自动生成
- * @return 处理结果
- * @see com.foxinmy.weixin4j.mp.api.CustomApi
- * @throws WeixinException
- * @see
- * 上传客服头像
- */
- public ApiResult uploadKfAvatar(String accountId, InputStream is, String fileName) throws WeixinException {
- return customApi.uploadKfAvatar(accountId, is, fileName);
- }
-
- /**
- * 删除客服账号
- *
- * @param id
- * 完整客服账号,格式为:账号前缀@公众号微信号
- * @return 处理结果
- * @see com.foxinmy.weixin4j.mp.api.CustomApi
- * @throws WeixinException
- * @see
- * 删除客服账号
- */
- public ApiResult deleteKfAccount(String id) throws WeixinException {
- return customApi.deleteKfAccount(id);
- }
-
- /**
- * 创建客服会话
- *
- * 开发者可以使用本接口,为多客服的客服工号创建会话,将某个客户直接指定给客服工号接待,需要注意此接口不会受客服自动接入数以及自动接入开关限制。
- * 只能为在线的客服(PC客户端在线,或者已绑定多客服助手)创建会话。
- *
- *
- * @param userOpenId
- * 用户的userOpenId
- * @param kfAccount
- * 完整客服账号,格式为:账号前缀@公众号微信号
- * @param text
- * 附加信息,文本会展示在客服人员的多客服客户端
- * @return 处理结果
- * @throws WeixinException
- * @see com.foxinmy.weixin4j.mp.api.CustomApi
- * @see
- * 创建会话
- */
- public ApiResult createKfSession(String userOpenId, String kfAccount, String text) throws WeixinException {
- return customApi.createKfSession(userOpenId, kfAccount, text);
- }
-
- /**
- * 关闭客服会话
- *
- * @param userOpenId
- * 用户的userOpenId
- * @param kfAccount
- * 完整客服账号,格式为:账号前缀@公众号微信号
- * @param text
- * 附加信息,文本会展示在客服人员的多客服客户端
- * @return 处理结果
- * @throws WeixinException
- * @see com.foxinmy.weixin4j.mp.api.CustomApi
- * @see
- * 关闭会话
- */
- public ApiResult closeKfSession(String userOpenId, String kfAccount, String text) throws WeixinException {
- return customApi.closeKfSession(userOpenId, kfAccount, text);
- }
-
- /**
- * 获取客户的会话状态:获取客户当前的会话状态。
- *
- * @param userOpenId
- * 用户的openid
- * @return 会话对象
- * @throws WeixinException
- * @see com.foxinmy.weixin4j.mp.api.CustomApi
- * @see com.foxinmy.weixin4j.mp.model.KfSession
- * @see
- * 获取会话状态
- */
- public KfSession getKfSession(String userOpenId) throws WeixinException {
- return customApi.getKfSession(userOpenId);
- }
-
- /**
- * 获取客服的会话列表:获取某个客服正在接待的会话列表。
- *
- * @param kfAccount
- * 完整客服账号,格式为:账号前缀@公众号微信号,账号前缀最多10个字符,必须是英文或者数字字符。
- * @return 会话列表
- * @throws WeixinException
- * @see com.foxinmy.weixin4j.mp.api.CustomApi
- * @see com.foxinmy.weixin4j.mp.model.KfSession
- * @see
- * 获取客服的会话列表
- */
- public List listKfSession(String kfAccount) throws WeixinException {
- return customApi.listKfSession(kfAccount);
- }
-
- /**
- * 获取未接入会话列表:获取当前正在等待队列中的会话列表,此接口最多返回最早进入队列的100个未接入会话
- *
- * @return 会话列表
- * @throws WeixinException
- * @see com.foxinmy.weixin4j.mp.api.CustomApi
- * @see com.foxinmy.weixin4j.mp.model.KfSession
- * @see com.foxinmy.weixin4j.mp.model.KfSession.KfSessionCounter
- * @see
- * 获取客服的会话列表
- */
- public KfSessionCounter listKfWaitSession() throws WeixinException {
- return customApi.listKfWaitSession();
- }
-
- /**
- * 上传群发的图文消息,一个图文消息支持1到10条图文
- *
- * @param articles
- * 图片消息
- * @return 媒体ID
- * @throws WeixinException
- * @see
- * 上传图文素材
- * @see com.foxinmy.weixin4j.tuple.MpArticle
- * @see com.foxinmy.weixin4j.mp.api.MassApi
- */
- public String uploadMassArticle(List articles) throws WeixinException {
- return massApi.uploadArticle(articles);
- }
-
- /**
- * 群发消息
- *
- * 在返回成功时,意味着群发任务提交成功,并不意味着此时群发已经结束,所以,仍有可能在后续的发送过程中出现异常情况导致用户未收到消息,
- * 如消息有时会进行审核、服务器不稳定等,此外,群发任务一般需要较长的时间才能全部发送完毕
- *
- *
- * @param MassTuple
- * 消息元件
- * @param isToAll
- * 用于设定是否向全部用户发送,值为true或false,选择true该消息群发给所有用户,
- * 选择false可根据group_id发送给指定群组的用户
- * @param groupId
- * 分组ID
- * @return 第一个元素为消息发送任务的ID,第二个元素为消息的数据ID,该字段只有在群发图文消息时,才会出现,可以用于在图文分析数据接口中
- * @throws WeixinException
- * @see com.foxinmy.weixin4j.mp.model.Group
- * @see com.foxinmy.weixin4j.tuple.Text
- * @see com.foxinmy.weixin4j.tuple.Image
- * @see com.foxinmy.weixin4j.tuple.Voice
- * @see com.foxinmy.weixin4j.tuple.MpVideo
- * @see com.foxinmy.weixin4j.tuple.MpNews
- * @see com.foxinmy.weixin4j.mp.api.MassApi
- * @see com.foxinmy.weixin4j.tuple.MassTuple
- * @see {@link #getGroups()}
- * @see
- * 根据分组群发
- */
- public String[] massByGroupId(MassTuple tuple, boolean isToAll, int groupId) throws WeixinException {
- return massApi.massByGroupId(tuple, isToAll, groupId);
- }
-
- /**
- * 分组ID群发图文消息
- *
- * @param articles
- * 图文列表
- * @param groupId
- * 分组ID
- * @return 第一个元素为消息发送任务的ID,第二个元素为消息的数据ID,该字段只有在群发图文消息时,才会出现,可以用于在图文分析数据接口中
- * @see {@link #massByGroupId(Tuple,int)}
- * @see
- * 根据分组群发
- * @see com.foxinmy.weixin4j.tuple.MpArticle
- * @throws WeixinException
- */
- public String[] massArticleByGroupId(List articles, int groupId) throws WeixinException {
- return massApi.massArticleByGroupId(articles, groupId);
- }
-
- /**
- * 群发消息给所有粉丝
- *
- * @param tuple
- * 消息元件
- * @return 第一个元素为消息发送任务的ID,第二个元素为消息的数据ID,该字段只有在群发图文消息时,才会出现,可以用于在图文分析数据接口中
- * @throws WeixinException
- * @see com.foxinmy.weixin4j.mp.api.MassApi
- * @see 根据标签群发
- */
- public String[] massToAll(MassTuple tuple) throws WeixinException {
- return massApi.massToAll(tuple);
- }
-
- /**
- * 标签群发消息
- *
- * @param tuple
- * 消息元件
- * @param tagId
- * 标签ID
- * @return 第一个元素为消息发送任务的ID,第二个元素为消息的数据ID,该字段只有在群发图文消息时,才会出现,可以用于在图文分析数据接口中
- * @throws WeixinException
- * @see Tag
- * @see {@link TagApi#listTags()}
- * @see com.foxinmy.weixin4j.mp.api.MassApi
- * @see 根据标签群发
- */
- public String[] massByTagId(MassTuple tuple, int tagId) throws WeixinException {
- return massApi.massByTagId(tuple, tagId);
- }
-
- /**
- * 标签群发图文消息
- *
- * @param articles
- * 图文列表
- * @param tagId
- * 标签ID
- * @param ignoreReprint
- * 图文消息被判定为转载时,是否继续群发
- * @return 第一个元素为消息发送任务的ID,第二个元素为消息的数据ID,该字段只有在群发图文消息时,才会出现。
- * @see 根据标签群发
- * @see {@link #massByTagId(Tuple,int)}
- * @see com.foxinmy.weixin4j.tuple.MpArticle
- * @see com.foxinmy.weixin4j.mp.api.MassApi
- * @throws WeixinException
- */
- public String[] massArticleByTagId(List articles, int tagId, boolean ignoreReprint)
- throws WeixinException {
- return massApi.massArticleByTagId(articles, tagId, ignoreReprint);
- }
-
- /**
- * openId群发消息
- *
- * @param tuple
- * 消息元件
- * @param openIds
- * openId列表
- * @return 第一个元素为消息发送任务的ID,第二个元素为消息的数据ID,该字段只有在群发图文消息时,才会出现,可以用于在图文分析数据接口中
- * @throws WeixinException
- * @see 根据openid群发
- * @see {@link UserApi#getUser(String)}
- * @see com.foxinmy.weixin4j.mp.api.MassApi
- */
- public String[] massByOpenIds(MassTuple tuple, String... openIds) throws WeixinException {
- return massApi.massByOpenIds(tuple, openIds);
- }
-
- /**
- * openid群发图文消息
- *
- * @param articles
- * 图文列表
- * @param ignoreReprint
- * 图文消息被判定为转载时,是否继续群发
- * @param openIds
- * openId列表
- * @return 第一个元素为消息发送任务的ID,第二个元素为消息的数据ID,该字段只有在群发图文消息时,才会出现,可以用于在图文分析数据接口中.
- * @see 根据openid群发
- * @see {@link #massByOpenIds(Tuple,String...)}
- * @see com.foxinmy.weixin4j.tuple.MpArticle
- * @see com.foxinmy.weixin4j.mp.api.MassApi
- * @throws WeixinException
- */
- public String[] massArticleByOpenIds(List articles, boolean ignoreReprint, String... openIds)
- throws WeixinException {
- return massApi.massArticleByOpenIds(articles, ignoreReprint, openIds);
- }
-
- /**
- * 删除群发消息
- *
- * @param msgid
- * 发送出去的消息ID
- * @throws WeixinException
- * @see 删除群发
- * @see #deleteMassNews(String, int)
- * @see com.foxinmy.weixin4j.mp.api.MassApi
- */
- public ApiResult deleteMassNews(String msgid) throws WeixinException {
- return massApi.deleteMassNews(msgid);
- }
-
- /**
- * 删除群发消息
- *
- * 请注意,只有已经发送成功的消息才能删除删除消息只是将消息的图文详情页失效,已经收到的用户,还是能在其本地看到消息卡片
- *
- *
- * @param msgid
- * 发送出去的消息ID
- * @param articleIndex
- * 要删除的文章在图文消息中的位置,第一篇编号为1,该字段不填或填0会删除全部文章
- * @throws WeixinException
- * @see 删除群发
- * @see {@link #massByTagId(Tuple, int)}
- * @see {@link #massByOpenIds(Tuple, String...)
- * @see com.foxinmy.weixin4j.mp.api.MassApi
- */
- public ApiResult deleteMassNews(String msgid, int articleIndex) throws WeixinException {
- return massApi.deleteMassNews(msgid, articleIndex);
- }
-
- /**
- * 预览群发消息
- * 开发者可通过该接口发送消息给指定用户,在手机端查看消息的样式和排版
- *
- * @param toUser
- * 接收用户的openID
- * @param toWxName
- * 接收用户的微信号 towxname和touser同时赋值时,以towxname优先
- * @param tuple
- * 消息元件
- * @return 处理结果
- * @throws WeixinException
- * @see com.foxinmy.weixin4j.mp.api.MassApi
- * @see com.foxinmy.weixin4j.tuple.MassTuple
- * @see
- * 预览群发消息
- */
- public ApiResult previewMassNews(String toUser, String toWxName, MassTuple tuple) throws WeixinException {
- return massApi.previewMassNews(toUser, toWxName, tuple);
- }
-
- /**
- * 查询群发发送状态
- *
- * @param msgId
- * 消息ID
- * @return 消息发送状态
- * @throws WeixinException
- * @see com.foxinmy.weixin4j.mp.api.MassApi
- * @see
- * 查询群发状态
- */
- public String getMassNewStatus(String msgId) throws WeixinException {
- return massApi.getMassNewStatus(msgId);
- }
-
- /**
- * 获取用户信息
- *
- * @param openId
- * 用户对应的ID
- * @return 用户对象
- * @throws WeixinException
- * @see
- * 获取用户信息
- * @see com.foxinmy.weixin4j.mp.model.User
- * @see com.foxinmy.weixin4j.mp.api.UserApi
- * @see {@link #getUser(String,Lang)}
- */
- public User getUser(String openId) throws WeixinException {
- return userApi.getUser(openId);
- }
-
- /**
- * 获取用户信息
- *
- * 在关注者与公众号产生消息交互后,公众号可获得关注者的OpenID(加密后的微信号,每个用户对每个公众号的OpenID是唯一的,对于不同公众号,
- * 同一用户的openid不同),公众号可通过本接口来根据OpenID获取用户基本信息,包括昵称、头像、性别、所在城市、语言和关注时间
- *
- *
- * @param openId
- * 用户对应的ID
- * @param lang
- * 国家地区语言版本
- * @return 用户对象
- * @throws WeixinException
- * @see
- * 获取用户信息
- * @see com.foxinmy.weixin4j.mp.type.Lang
- * @see com.foxinmy.weixin4j.mp.model.User
- * @see com.foxinmy.weixin4j.mp.api.UserApi
- */
- public User getUser(String openId, Lang lang) throws WeixinException {
- return userApi.getUser(openId, lang);
- }
-
- /**
- * 批量获取用户信息
- *
- * @param openIds
- * 用户ID
- * @return 用户列表
- * @see
- * 获取用户信息
- * @see com.foxinmy.weixin4j.mp.model.User
- * @see com.foxinmy.weixin4j.mp.api.UserApi
- * @throws WeixinException
- * @see {@link #getUsers(Lang,String[])}
- */
- public List getUsers(String... openIds) throws WeixinException {
- return userApi.getUsers(openIds);
- }
-
- /**
- * 批量获取用户信息
- *
- * @param lang
- * 国家地区语言版本
- * @param openIds
- * 用户ID
- * @return 用户列表
- * @see
- * 获取用户信息
- * @see com.foxinmy.weixin4j.mp.type.Lang
- * @see com.foxinmy.weixin4j.mp.model.User
- * @see com.foxinmy.weixin4j.mp.api.UserApi
- * @throws WeixinException
- */
- public List getUsers(Lang lang, String... openIds) throws WeixinException {
- return userApi.getUsers(lang, openIds);
- }
-
- /**
- * 获取公众号一定数量(10000)的关注者列表 请慎重使用
- *
- * @param nextOpenId
- * 下一次拉取数据的openid 不填写则默认从头开始拉取
- * @return 关注者信息 包含用户的详细信息
- * @throws WeixinException
- * @see
- * 获取关注者列表
- * @see
- * 批量获取用户信息
- * @see com.foxinmy.weixin4j.mp.api.UserApi
- * @see com.foxinmy.weixin4j.mp.model.Following
- * @see com.foxinmy.weixin4j.mp.model.User
- */
- public Following getFollowing(String nextOpenId) throws WeixinException {
- return userApi.getFollowing(nextOpenId);
- }
-
- /**
- * 获取公众号一定数量(10000)的关注者列表
- *
- * @param nextOpenId
- * 下一次拉取数据的openid 不填写则默认从头开始拉取
- * @return 关注者信息 不包含用户的详细信息
- * @throws WeixinException
- * @see
- * 获取关注者列表
- * @see com.foxinmy.weixin4j.mp.api.UserApi
- * @see com.foxinmy.weixin4j.mp.model.Following
- */
- public Following getFollowingOpenIds(String nextOpenId) throws WeixinException {
- return userApi.getFollowingOpenIds(nextOpenId);
- }
-
- /**
- * 获取公众号全部的关注者列表 请慎重使用
- *
- * 当公众号关注者数量超过10000时,可通过填写next_openid的值,从而多次拉取列表的方式来满足需求,
- * 将上一次调用得到的返回中的next_openid值,作为下一次调用中的next_openid值
- *
- *
- * @return 用户对象集合
- * @throws WeixinException
- * @see
- * 获取关注者列表
- * @see
- * 批量获取用户信息
- * @see com.foxinmy.weixin4j.mp.api.UserApi
- * @see com.foxinmy.weixin4j.mp.model.Following
- * @see com.foxinmy.weixin4j.mp.model.User
- * @see #getFollowing(String)
- */
- public List getAllFollowing() throws WeixinException {
- return userApi.getAllFollowing();
- }
-
- /**
- * 获取公众号全部的关注者列表 请慎重使用
- *
- * 当公众号关注者数量超过10000时,可通过填写next_openid的值,从而多次拉取列表的方式来满足需求,
- * 将上一次调用得到的返回中的next_openid值,作为下一次调用中的next_openid值
- *
- *
- * @return 用户openid集合
- * @throws WeixinException
- * @see
- * 获取关注者列表
- * @see com.foxinmy.weixin4j.mp.api.UserApi
- * @see #getFollowingOpenIds(String)
- */
- public List getAllFollowingOpenIds() throws WeixinException {
- return userApi.getAllFollowingOpenIds();
- }
-
- /**
- * 设置用户备注名
- *
- * @param openId
- * 用户ID
- * @param remark
- * 备注名
- * @throws WeixinException
- * @see
- * 设置用户备注名
- * @see com.foxinmy.weixin4j.mp.api.UserApi
- */
- public ApiResult remarkUserName(String openId, String remark) throws WeixinException {
- return userApi.remarkUserName(openId, remark);
- }
-
- /**
- * 创建分组
- *
- * @param name
- * 组名称
- * @return group对象
- * @throws WeixinException
- * @see
- * 创建分组
- * @see com.foxinmy.weixin4j.mp.model.Group
- * @see com.foxinmy.weixin4j.mp.model.Group#toCreateJson()
- * @see com.foxinmy.weixin4j.mp.api.GroupApi
- */
- public Group createGroup(String name) throws WeixinException {
- return groupApi.createGroup(name);
- }
-
- /**
- * 查询所有分组
- *
- * @return 组集合
- * @throws WeixinException
- * @see
- * 查询所有分组
- * @see com.foxinmy.weixin4j.mp.model.Group
- * @see com.foxinmy.weixin4j.mp.api.GroupApi
- */
- public List getGroups() throws WeixinException {
- return groupApi.getGroups();
- }
-
- /**
- * 查询用户所在分组
- *
- * @param openId
- * 用户对应的ID
- * @return 组ID
- * @throws WeixinException
- * @see
- * 查询用户所在分组
- * @see com.foxinmy.weixin4j.mp.model.Group
- * @see com.foxinmy.weixin4j.mp.api.GroupApi
- */
- public int getGroupByOpenId(String openId) throws WeixinException {
- return groupApi.getGroupByOpenId(openId);
- }
-
- /**
- * 修改分组名
- *
- * @param groupId
- * 组ID
- * @param name
- * 组名称
- * @throws WeixinException
- * @see
- * 修改分组名
- * @see com.foxinmy.weixin4j.mp.model.Group
- * @see com.foxinmy.weixin4j.mp.api.GroupApi
- */
- public ApiResult modifyGroup(int groupId, String name) throws WeixinException {
- return groupApi.modifyGroup(groupId, name);
- }
-
- /**
- * 移动用户到分组
- *
- * @param groupId
- * 组ID
- * @param openId
- * 用户对应的ID
- * @throws WeixinException
- * @see
- * 移动分组
- * @see com.foxinmy.weixin4j.mp.model.Group
- * @see com.foxinmy.weixin4j.mp.api.GroupApi
- */
- public ApiResult moveGroup(int groupId, String openId) throws WeixinException {
- return groupApi.moveGroup(groupId, openId);
- }
-
- /**
- * 批量移动分组
- *
- * @param groupId
- * 组ID
- * @param openIds
- * 用户ID列表(不能超过50个)
- * @throws WeixinException
- * @see
- * 批量移动分组
- * @see com.foxinmy.weixin4j.mp.model.Group
- * @see com.foxinmy.weixin4j.mp.api.GroupApi
- */
- public ApiResult moveGroup(int groupId, String... openIds) throws WeixinException {
- return groupApi.moveGroup(groupId, openIds);
- }
-
- /**
- * 删除用户分组,所有该分组内的用户自动进入默认分组.
- *
- * @param groupId
- * 组ID
- * @throws WeixinException
- * @see
- * 删除用户分组
- * @see com.foxinmy.weixin4j.mp.model.Group
- * @see com.foxinmy.weixin4j.mp.api.GroupApi
- */
- public ApiResult deleteGroup(int groupId) throws WeixinException {
- return groupApi.deleteGroup(groupId);
- }
-
- /**
- * 自定义菜单
- *
- * @param buttons
- * 菜单列表
- * @throws WeixinException
- * @see
- * 创建自定义菜单
- * @see com.foxinmy.weixin4j.model.Button
- * @see com.foxinmy.weixin4j.type.ButtonType
- * @see com.foxinmy.weixin4j.mp.api.MenuApi
- */
- public ApiResult createMenu(List