重构Cache实现
This commit is contained in:
@@ -51,7 +51,7 @@ import com.foxinmy.weixin4j.mp.type.DatacubeType;
|
||||
import com.foxinmy.weixin4j.mp.type.IndustryType;
|
||||
import com.foxinmy.weixin4j.mp.type.Lang;
|
||||
import com.foxinmy.weixin4j.setting.Weixin4jSettings;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.tuple.MassTuple;
|
||||
import com.foxinmy.weixin4j.tuple.MpArticle;
|
||||
import com.foxinmy.weixin4j.tuple.MpVideo;
|
||||
@@ -121,7 +121,7 @@ public class WeixinProxy {
|
||||
/**
|
||||
* token实现
|
||||
*/
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
/**
|
||||
* 配置信息
|
||||
*/
|
||||
@@ -141,9 +141,9 @@ public class WeixinProxy {
|
||||
* @see com.foxinmy.weixin4j.setting.Weixin4jSettings
|
||||
*/
|
||||
public WeixinProxy(Weixin4jSettings settings) {
|
||||
this(new TokenHolder(new WeixinTokenCreator(settings.getAccount()
|
||||
this(new TokenManager(new WeixinTokenCreator(settings.getAccount()
|
||||
.getId(), settings.getAccount().getSecret()),
|
||||
settings.getTokenStorager0()));
|
||||
settings.getCacheStorager0()));
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@@ -151,22 +151,22 @@ public class WeixinProxy {
|
||||
* 注意:TokenCreator 需为 <font color="red">WeixinTokenCreator</font>
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.mp.token.WeixinTokenCreator
|
||||
* @param tokenHolder
|
||||
* @param tokenManager
|
||||
*/
|
||||
private WeixinProxy(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
this.mediaApi = new MediaApi(tokenHolder);
|
||||
this.notifyApi = new NotifyApi(tokenHolder);
|
||||
this.customApi = new CustomApi(tokenHolder);
|
||||
this.massApi = new MassApi(tokenHolder);
|
||||
this.userApi = new UserApi(tokenHolder);
|
||||
this.groupApi = new GroupApi(tokenHolder);
|
||||
this.menuApi = new MenuApi(tokenHolder);
|
||||
this.qrApi = new QrApi(tokenHolder);
|
||||
this.tmplApi = new TmplApi(tokenHolder);
|
||||
this.helperApi = new HelperApi(tokenHolder);
|
||||
this.dataApi = new DataApi(tokenHolder);
|
||||
this.tagApi = new TagApi(tokenHolder);
|
||||
private WeixinProxy(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,25 +179,25 @@ public class WeixinProxy {
|
||||
}
|
||||
|
||||
/**
|
||||
* token获取
|
||||
* token管理
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TokenHolder getTokenHolder() {
|
||||
return this.tokenHolder;
|
||||
public TokenManager getTokenManager() {
|
||||
return this.tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取JSSDK Ticket的tokenHolder
|
||||
* 获取JSSDK Ticket的tokenManager
|
||||
*
|
||||
* @param ticketType
|
||||
* 票据类型
|
||||
* @return
|
||||
*/
|
||||
public TokenHolder getTicketHolder(TicketType ticketType) {
|
||||
return new TokenHolder(new WeixinTicketCreator(getWeixinAccount()
|
||||
.getId(), ticketType, this.tokenHolder),
|
||||
this.settings.getTokenStorager0());
|
||||
public TokenManager getTicketManager(TicketType ticketType) {
|
||||
return new TokenManager(new WeixinTicketCreator(getWeixinAccount()
|
||||
.getId(), ticketType, this.tokenManager),
|
||||
this.settings.getCacheStorager0());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -864,7 +864,7 @@ public class WeixinProxy {
|
||||
* 删除群发</a>
|
||||
* @see com.foxinmy.weixin4j.mp.api.MassApi
|
||||
* @see {@link #massByGroupId(Tuple, int)}
|
||||
* @see {@link #massByOpenIds(Tuple, String...)
|
||||
* @see {@link #massByOpenIds(Tuple, String...)
|
||||
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.foxinmy.weixin4j.mp.model.KfAccount;
|
||||
import com.foxinmy.weixin4j.mp.model.KfChatRecord;
|
||||
import com.foxinmy.weixin4j.mp.model.KfSession;
|
||||
import com.foxinmy.weixin4j.mp.model.KfSession.KfSessionCounter;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.util.DigestUtil;
|
||||
import com.foxinmy.weixin4j.util.FileUtil;
|
||||
import com.foxinmy.weixin4j.util.ObjectId;
|
||||
@@ -28,7 +28,7 @@ import com.foxinmy.weixin4j.util.StringUtil;
|
||||
|
||||
/**
|
||||
* 多客服API
|
||||
*
|
||||
*
|
||||
* @className CustomApi
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2014年11月16日
|
||||
@@ -37,15 +37,15 @@ import com.foxinmy.weixin4j.util.StringUtil;
|
||||
*/
|
||||
public class CustomApi extends MpApi {
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public CustomApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public CustomApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 客服聊天记录
|
||||
*
|
||||
*
|
||||
* @param startTime
|
||||
* 查询开始时间
|
||||
* @param endTime
|
||||
@@ -62,7 +62,7 @@ public class CustomApi extends MpApi {
|
||||
public List<KfChatRecord> getKfChatRecord(Date startTime, Date endTime, Pageable pageable) throws WeixinException {
|
||||
List<KfChatRecord> records = new ArrayList<KfChatRecord>();
|
||||
String kf_chatrecord_uri = getRequestUri("kf_chatrecord_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("starttime", startTime.getTime() / 1000);
|
||||
obj.put("endtime", endTime.getTime() / 1000);
|
||||
@@ -86,7 +86,7 @@ public class CustomApi extends MpApi {
|
||||
|
||||
/**
|
||||
* 获取公众号中所设置的客服基本信息,包括客服工号、客服昵称、客服登录账号
|
||||
*
|
||||
*
|
||||
* @param isOnline
|
||||
* 是否在线 为ture时可以可以获取客服在线状态(手机在线、PC客户端在线、手机和PC客户端全都在线)、客服自动接入最大值、
|
||||
* 客服当前接待客户数
|
||||
@@ -100,7 +100,7 @@ public class CustomApi extends MpApi {
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public List<KfAccount> listKfAccount(boolean isOnline) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String text = "";
|
||||
if (isOnline) {
|
||||
String kf_onlinelist_uri = getRequestUri("kf_onlinelist_uri");
|
||||
@@ -116,7 +116,7 @@ public class CustomApi extends MpApi {
|
||||
|
||||
/**
|
||||
* 新增客服账号
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
* 完整客服账号,格式为:账号前缀@公众号微信号,账号前缀最多10个字符,必须是英文或者数字字符。如果没有公众号微信号,
|
||||
* 请前往微信公众平台设置。
|
||||
@@ -136,7 +136,7 @@ public class CustomApi extends MpApi {
|
||||
obj.put("nickname", name);
|
||||
obj.put("password", DigestUtil.MD5(pwd));
|
||||
String kf_create_uri = getRequestUri("kf_create_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(String.format(kf_create_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
return response.getAsJsonResult();
|
||||
@@ -144,7 +144,7 @@ public class CustomApi extends MpApi {
|
||||
|
||||
/**
|
||||
* 更新客服账号
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
* 完整客服账号,格式为:账号前缀@公众号微信号,账号前缀最多10个字符,必须是英文或者数字字符。如果没有公众号微信号,
|
||||
* 请前往微信公众平台设置。
|
||||
@@ -164,7 +164,7 @@ public class CustomApi extends MpApi {
|
||||
obj.put("nickname", name);
|
||||
obj.put("password", DigestUtil.MD5(pwd));
|
||||
String kf_update_uri = getRequestUri("kf_update_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(String.format(kf_update_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
return response.getAsJsonResult();
|
||||
@@ -174,7 +174,7 @@ public class CustomApi extends MpApi {
|
||||
* 邀请绑定客服帐号
|
||||
* 新添加的客服帐号是不能直接使用的,只有客服人员用微信号绑定了客服账号后,方可登录Web客服进行操作。此接口发起一个绑定邀请到客服人员微信号
|
||||
* ,客服人员需要在微信客户端上用该微信号确认后帐号才可用。尚未绑定微信号的帐号可以进行绑定邀请操作,邀请未失效时不能对该帐号进行再次绑定微信号邀请。
|
||||
*
|
||||
*
|
||||
* @param kfAccount
|
||||
* 完整客服帐号,格式为:帐号前缀@公众号微信号
|
||||
* @param inviteAccount
|
||||
@@ -190,7 +190,7 @@ public class CustomApi extends MpApi {
|
||||
obj.put("kf_account", kfAccount);
|
||||
obj.put("invite_wx", inviteAccount);
|
||||
String kf_invite_uri = getRequestUri("kf_invite_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(String.format(kf_invite_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
return response.getAsJsonResult();
|
||||
@@ -198,7 +198,7 @@ public class CustomApi extends MpApi {
|
||||
|
||||
/**
|
||||
* 上传客服头像
|
||||
*
|
||||
*
|
||||
* @param accountId
|
||||
* 完整客服账号,格式为:账号前缀@公众号微信号
|
||||
* @param is
|
||||
@@ -218,7 +218,7 @@ public class CustomApi extends MpApi {
|
||||
if (StringUtil.isBlank(FileUtil.getFileExtension(fileName))) {
|
||||
fileName = String.format("%s.jpg", fileName);
|
||||
}
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String kf_avatar_uri = getRequestUri("kf_avatar_uri");
|
||||
WeixinResponse response = weixinExecutor.post(String.format(kf_avatar_uri, token.getAccessToken(), accountId),
|
||||
new FormBodyPart("media", new InputStreamBody(is, ContentType.IMAGE_JPG.getMimeType(), fileName)));
|
||||
@@ -228,7 +228,7 @@ public class CustomApi extends MpApi {
|
||||
|
||||
/**
|
||||
* 删除客服账号
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
* 完整客服账号,格式为:账号前缀@公众号微信号
|
||||
* @return 处理结果
|
||||
@@ -238,7 +238,7 @@ public class CustomApi extends MpApi {
|
||||
* 删除客服账号</a>
|
||||
*/
|
||||
public JsonResult deleteKfAccount(String id) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String kf_delete_uri = getRequestUri("kf_delete_uri");
|
||||
WeixinResponse response = weixinExecutor.get(String.format(kf_delete_uri, token.getAccessToken(), id));
|
||||
|
||||
@@ -251,7 +251,7 @@ public class CustomApi extends MpApi {
|
||||
* 开发者可以使用本接口,为多客服的客服工号创建会话,将某个客户直接指定给客服工号接待,需要注意此接口不会受客服自动接入数以及自动接入开关限制。
|
||||
* 只能为在线的客服(PC客户端在线,或者已绑定多客服助手)创建会话。
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param userOpenId
|
||||
* 用户的userOpenId
|
||||
* @param kfAccount
|
||||
@@ -265,7 +265,7 @@ public class CustomApi extends MpApi {
|
||||
* 创建会话</a>
|
||||
*/
|
||||
public JsonResult createKfSession(String userOpenId, String kfAccount, String text) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String kfsession_create_uri = getRequestUri("kfsession_create_uri");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("openid", userOpenId);
|
||||
@@ -279,7 +279,7 @@ public class CustomApi extends MpApi {
|
||||
|
||||
/**
|
||||
* 关闭会话
|
||||
*
|
||||
*
|
||||
* @param userOpenId
|
||||
* 用户的userOpenId
|
||||
* @param kfAccount
|
||||
@@ -293,7 +293,7 @@ public class CustomApi extends MpApi {
|
||||
* 关闭会话</a>
|
||||
*/
|
||||
public JsonResult closeKfSession(String userOpenId, String kfAccount, String text) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String kfsession_close_uri = getRequestUri("kfsession_close_uri");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("openid", userOpenId);
|
||||
@@ -307,7 +307,7 @@ public class CustomApi extends MpApi {
|
||||
|
||||
/**
|
||||
* 获取客户的会话状态:获取客户当前的会话状态。
|
||||
*
|
||||
*
|
||||
* @param userOpenId
|
||||
* 用户的openid
|
||||
* @return 会话对象
|
||||
@@ -318,7 +318,7 @@ public class CustomApi extends MpApi {
|
||||
* 获取会话状态</a>
|
||||
*/
|
||||
public KfSession getKfSession(String userOpenId) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String kfsession_get_uri = getRequestUri("kfsession_get_uri");
|
||||
WeixinResponse response = weixinExecutor
|
||||
.get(String.format(kfsession_get_uri, token.getAccessToken(), userOpenId));
|
||||
@@ -331,7 +331,7 @@ public class CustomApi extends MpApi {
|
||||
|
||||
/**
|
||||
* 获取客服的会话列表:获取某个客服正在接待的会话列表。
|
||||
*
|
||||
*
|
||||
* @param kfAccount
|
||||
* 完整客服账号,格式为:账号前缀@公众号微信号,账号前缀最多10个字符,必须是英文或者数字字符。
|
||||
* @return 会话列表
|
||||
@@ -342,7 +342,7 @@ public class CustomApi extends MpApi {
|
||||
* 获取客服的会话列表</a>
|
||||
*/
|
||||
public List<KfSession> listKfSession(String kfAccount) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String kfsession_list_uri = getRequestUri("kfsession_list_uri");
|
||||
WeixinResponse response = weixinExecutor
|
||||
.get(String.format(kfsession_list_uri, token.getAccessToken(), kfAccount));
|
||||
@@ -354,7 +354,7 @@ public class CustomApi extends MpApi {
|
||||
/**
|
||||
* 获取未接入会话列表:获取当前正在等待队列中的会话列表,此接口最多返回最早进入队列的100个未接入会话。</br>
|
||||
* <font color="red">缺陷:没有count字段</font>
|
||||
*
|
||||
*
|
||||
* @return 会话列表
|
||||
* @throws WeixinException
|
||||
* @see com.foxinmy.weixin4j.mp.model.KfSession
|
||||
@@ -364,7 +364,7 @@ public class CustomApi extends MpApi {
|
||||
* 获取客服的会话列表</a>
|
||||
*/
|
||||
public KfSessionCounter listKfWaitSession() throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String kfsession_wait_uri = getRequestUri("kfsession_wait_uri");
|
||||
WeixinResponse response = weixinExecutor.get(String.format(kfsession_wait_uri, token.getAccessToken()));
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.type.DatacubeType;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.util.DateUtil;
|
||||
|
||||
/**
|
||||
@@ -27,10 +27,10 @@ import com.foxinmy.weixin4j.util.DateUtil;
|
||||
* @see
|
||||
*/
|
||||
public class DataApi extends MpApi {
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public DataApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public DataApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +119,7 @@ public class DataApi extends MpApi {
|
||||
public List<?> datacube(DatacubeType datacubeType, Date beginDate,
|
||||
Date endDate) throws WeixinException {
|
||||
String datacube_uri = getRequestUri("datacube_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("begin_date", DateUtil.fortmat2yyyy_MM_dd(beginDate));
|
||||
obj.put("end_date", DateUtil.fortmat2yyyy_MM_dd(endDate));
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.foxinmy.weixin4j.http.weixin.JsonResult;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.model.Group;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
|
||||
/**
|
||||
* 分组相关API
|
||||
@@ -22,10 +22,10 @@ import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
*/
|
||||
public class GroupApi extends MpApi {
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public GroupApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public GroupApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,7 +42,7 @@ public class GroupApi extends MpApi {
|
||||
*/
|
||||
public Group createGroup(String name) throws WeixinException {
|
||||
String group_create_uri = getRequestUri("group_create_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
Group group = new Group(name);
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(group_create_uri, token.getAccessToken()),
|
||||
@@ -62,7 +62,7 @@ public class GroupApi extends MpApi {
|
||||
*/
|
||||
public List<Group> getGroups() throws WeixinException {
|
||||
String group_get_uri = getRequestUri("group_get_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(group_get_uri,
|
||||
token.getAccessToken()));
|
||||
|
||||
@@ -83,7 +83,7 @@ public class GroupApi extends MpApi {
|
||||
*/
|
||||
public int getGroupByOpenId(String openId) throws WeixinException {
|
||||
String group_getid_uri = getRequestUri("group_getid_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(group_getid_uri, token.getAccessToken()),
|
||||
String.format("{\"openid\":\"%s\"}", openId));
|
||||
@@ -107,7 +107,7 @@ public class GroupApi extends MpApi {
|
||||
public JsonResult modifyGroup(int groupId, String name)
|
||||
throws WeixinException {
|
||||
String group_modify_uri = getRequestUri("group_modify_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
Group group = new Group(groupId, name);
|
||||
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
@@ -131,7 +131,7 @@ public class GroupApi extends MpApi {
|
||||
public JsonResult moveGroup(int groupId, String openId)
|
||||
throws WeixinException {
|
||||
String group_move_uri = getRequestUri("group_move_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(String.format(group_move_uri,
|
||||
token.getAccessToken()), String.format(
|
||||
"{\"openid\":\"%s\",\"to_groupid\":%d}", openId, groupId));
|
||||
@@ -154,7 +154,7 @@ public class GroupApi extends MpApi {
|
||||
public JsonResult moveGroup(int groupId, String... openIds)
|
||||
throws WeixinException {
|
||||
String group_batchmove_uri = getRequestUri("group_batchmove_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("to_groupid", groupId);
|
||||
obj.put("openid_list", openIds);
|
||||
@@ -177,7 +177,7 @@ public class GroupApi extends MpApi {
|
||||
*/
|
||||
public JsonResult deleteGroup(int groupId) throws WeixinException {
|
||||
String group_delete_uri = getRequestUri("group_delete_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(group_delete_uri, token.getAccessToken()),
|
||||
String.format("{\"group\":{\"id\":%d}}", groupId));
|
||||
|
||||
@@ -17,9 +17,10 @@ import com.foxinmy.weixin4j.mp.model.AutoReplySetting;
|
||||
import com.foxinmy.weixin4j.mp.model.MenuSetting;
|
||||
import com.foxinmy.weixin4j.mp.model.SemQuery;
|
||||
import com.foxinmy.weixin4j.mp.model.SemResult;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.tuple.MpArticle;
|
||||
import com.foxinmy.weixin4j.type.ButtonType;
|
||||
import com.foxinmy.weixin4j.util.ReflectionUtil;
|
||||
|
||||
/**
|
||||
* 辅助相关API
|
||||
@@ -32,10 +33,10 @@ import com.foxinmy.weixin4j.type.ButtonType;
|
||||
*/
|
||||
public class HelperApi extends MpApi {
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public HelperApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public HelperApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +51,7 @@ public class HelperApi extends MpApi {
|
||||
*/
|
||||
public String getShorturl(String url) throws WeixinException {
|
||||
String shorturl_uri = getRequestUri("shorturl_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("action", "long2short");
|
||||
obj.put("long_url", url);
|
||||
@@ -75,7 +76,7 @@ public class HelperApi extends MpApi {
|
||||
*/
|
||||
public SemResult semantic(SemQuery semQuery) throws WeixinException {
|
||||
String semantic_uri = getRequestUri("semantic_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(semantic_uri, token.getAccessToken()),
|
||||
semQuery.toJson());
|
||||
@@ -93,7 +94,7 @@ public class HelperApi extends MpApi {
|
||||
*/
|
||||
public List<String> getWechatServerIp() throws WeixinException {
|
||||
String getcallbackip_uri = getRequestUri("getcallbackip_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(String.format(
|
||||
getcallbackip_uri, token.getAccessToken()));
|
||||
return JSON.parseArray(response.getAsJson().getString("ip_list"),
|
||||
@@ -115,7 +116,7 @@ public class HelperApi extends MpApi {
|
||||
*/
|
||||
public MenuSetting getMenuSetting() throws WeixinException {
|
||||
String menu_get_selfmenu_uri = getRequestUri("menu_get_selfmenu_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
menu_get_selfmenu_uri, token.getAccessToken()));
|
||||
JSONObject result = response.getAsJson();
|
||||
@@ -151,14 +152,18 @@ public class HelperApi extends MpApi {
|
||||
JSONObject article = null;
|
||||
for (int i = 0; i < news.size(); i++) {
|
||||
article = news.getJSONObject(i);
|
||||
article.put("showCoverPic", article.remove("show_cover"));
|
||||
article.put("coverUrl", article.remove("cover_url"));
|
||||
article.put("contentUrl", article.remove("content_url"));
|
||||
article.put("sourceUrl", article.remove("source_url"));
|
||||
newsList.add(JSON.parseObject(article.toJSONString(),
|
||||
MpArticle.class));
|
||||
article.put("show_cover_pic", article.remove("show_cover"));
|
||||
article.put("thumb_url", article.remove("cover_url"));
|
||||
article.put("url", article.remove("content_url"));
|
||||
article.put("content_source_url",
|
||||
article.remove("source_url"));
|
||||
newsList.add(JSON.toJavaObject(article, MpArticle.class));
|
||||
}
|
||||
if (ReflectionUtil.getAccessibleField(object, "articles") != null) {
|
||||
JSONPath.set(object, "$.articles", newsList);
|
||||
} else {
|
||||
JSONPath.set(object, "$.content", newsList);
|
||||
}
|
||||
JSONPath.set(object, "$.content", newsList);
|
||||
} else {
|
||||
JSONPath.set(object, "$.content", value);
|
||||
}
|
||||
@@ -175,11 +180,12 @@ public class HelperApi extends MpApi {
|
||||
*/
|
||||
public AutoReplySetting getAutoReplySetting() throws WeixinException {
|
||||
String autoreply_setting_get_uri = getRequestUri("autoreply_setting_get_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
autoreply_setting_get_uri, token.getAccessToken()));
|
||||
|
||||
JSONObject result = response.getAsJson();
|
||||
|
||||
AutoReplySetting replySetting = JSON.toJavaObject(result,
|
||||
AutoReplySetting.class);
|
||||
List<AutoReplySetting.Rule> ruleList = null;
|
||||
|
||||
@@ -10,7 +10,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.JsonResult;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.tuple.MassTuple;
|
||||
import com.foxinmy.weixin4j.tuple.MpArticle;
|
||||
import com.foxinmy.weixin4j.tuple.MpNews;
|
||||
@@ -27,10 +27,10 @@ import com.foxinmy.weixin4j.util.StringUtil;
|
||||
*/
|
||||
public class MassApi extends MpApi {
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public MassApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public MassApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,7 +48,7 @@ public class MassApi extends MpApi {
|
||||
public String uploadArticle(List<MpArticle> articles)
|
||||
throws WeixinException {
|
||||
String article_upload_uri = getRequestUri("article_upload_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("articles", articles);
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
@@ -110,7 +110,7 @@ public class MassApi extends MpApi {
|
||||
obj.put(msgtype, JSON.toJSON(tuple));
|
||||
obj.put("msgtype", msgtype);
|
||||
String mass_group_uri = getRequestUri("mass_group_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(mass_group_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
@@ -180,7 +180,7 @@ public class MassApi extends MpApi {
|
||||
obj.put(msgtype, JSON.toJSON(tuple));
|
||||
obj.put("msgtype", msgtype);
|
||||
String mass_openid_uri = getRequestUri("mass_openid_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(mass_openid_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
@@ -228,7 +228,7 @@ public class MassApi extends MpApi {
|
||||
public JsonResult deleteMassNews(String msgid) throws WeixinException {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("msgid", msgid);
|
||||
String mass_delete_uri = getRequestUri("mass_delete_uri");
|
||||
String mass_delete_uri = getRequestUri("mass_delete_uri");
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(mass_delete_uri, token.getAccessToken()),
|
||||
@@ -260,7 +260,7 @@ public class MassApi extends MpApi {
|
||||
obj.put("towxname", toWxName);
|
||||
obj.put(msgtype, JSON.toJSON(tuple));
|
||||
obj.put("msgtype", msgtype);
|
||||
String mass_preview_uri = getRequestUri("mass_preview_uri");
|
||||
String mass_preview_uri = getRequestUri("mass_preview_uri");
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(mass_preview_uri, token.getAccessToken()),
|
||||
@@ -282,7 +282,7 @@ public class MassApi extends MpApi {
|
||||
public String getMassNewStatus(String msgId) throws WeixinException {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("msg_id", msgId);
|
||||
String mass_get_uri = getRequestUri("mass_get_uri");
|
||||
String mass_get_uri = getRequestUri("mass_get_uri");
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(mass_get_uri, token.getAccessToken()),
|
||||
|
||||
@@ -35,7 +35,7 @@ import com.foxinmy.weixin4j.model.MediaRecord;
|
||||
import com.foxinmy.weixin4j.model.MediaUploadResult;
|
||||
import com.foxinmy.weixin4j.model.Pageable;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.tuple.MpArticle;
|
||||
import com.foxinmy.weixin4j.tuple.MpVideo;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
@@ -55,10 +55,10 @@ import com.foxinmy.weixin4j.util.StringUtil;
|
||||
*/
|
||||
public class MediaApi extends MpApi {
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public MediaApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public MediaApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,7 +81,7 @@ public class MediaApi extends MpApi {
|
||||
fileName = String.format("%s.jpg", fileName);
|
||||
}
|
||||
String image_upload_uri = getRequestUri("image_upload_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(String.format(
|
||||
image_upload_uri, token.getAccessToken()),
|
||||
new FormBodyPart("media", new InputStreamBody(is,
|
||||
@@ -114,7 +114,7 @@ public class MediaApi extends MpApi {
|
||||
obj.put("title", title);
|
||||
obj.put("description", description);
|
||||
String video_upload_uri = getRequestUri("video_upload_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(video_upload_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
@@ -180,7 +180,7 @@ public class MediaApi extends MpApi {
|
||||
throw new WeixinException(
|
||||
"please invoke uploadMaterialVideo method");
|
||||
}
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = null;
|
||||
try {
|
||||
if (isMaterial) {
|
||||
@@ -238,7 +238,7 @@ public class MediaApi extends MpApi {
|
||||
*/
|
||||
public MediaDownloadResult downloadMedia(String mediaId, boolean isMaterial)
|
||||
throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
try {
|
||||
HttpRequest request = null;
|
||||
if (isMaterial) {
|
||||
@@ -310,7 +310,7 @@ public class MediaApi extends MpApi {
|
||||
*/
|
||||
public String uploadMaterialArticle(List<MpArticle> articles)
|
||||
throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String material_article_upload_uri = getRequestUri("material_article_upload_uri");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("articles", articles);
|
||||
@@ -357,7 +357,7 @@ public class MediaApi extends MpApi {
|
||||
*/
|
||||
public JsonResult updateMaterialArticle(String mediaId, int index,
|
||||
MpArticle article) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String material_article_update_uri = getRequestUri("material_article_update_uri");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("articles", article);
|
||||
@@ -382,7 +382,7 @@ public class MediaApi extends MpApi {
|
||||
*/
|
||||
public JsonResult deleteMaterialMedia(String mediaId)
|
||||
throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String material_media_del_uri = getRequestUri("material_media_del_uri");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("media_id", mediaId);
|
||||
@@ -418,7 +418,7 @@ public class MediaApi extends MpApi {
|
||||
fileName = String.format("%s.mp4", fileName);
|
||||
}
|
||||
String material_media_upload_uri = getRequestUri("material_media_upload_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
try {
|
||||
JSONObject description = new JSONObject();
|
||||
description.put("title", title);
|
||||
@@ -454,7 +454,7 @@ public class MediaApi extends MpApi {
|
||||
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738733&token=&lang=zh_CN">获取素材总数</a>
|
||||
*/
|
||||
public MediaCounter countMaterialMedia() throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String material_media_count_uri = getRequestUri("material_media_count_uri");
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
material_media_count_uri, token.getAccessToken()));
|
||||
@@ -482,7 +482,7 @@ public class MediaApi extends MpApi {
|
||||
*/
|
||||
public MediaRecord listMaterialMedia(MediaType mediaType, Pageable pageable)
|
||||
throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String material_media_list_uri = getRequestUri("material_media_list_uri");
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("type", mediaType.name());
|
||||
|
||||
@@ -17,7 +17,7 @@ import com.foxinmy.weixin4j.model.Button;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.model.Menu;
|
||||
import com.foxinmy.weixin4j.mp.model.MenuMatchRule;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.type.ButtonType;
|
||||
|
||||
/**
|
||||
@@ -30,10 +30,10 @@ import com.foxinmy.weixin4j.type.ButtonType;
|
||||
*/
|
||||
public class MenuApi extends MpApi {
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public MenuApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public MenuApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,7 +58,7 @@ public class MenuApi extends MpApi {
|
||||
private WeixinResponse createMenu0(String url, JSONObject data)
|
||||
throws WeixinException {
|
||||
return weixinExecutor.post(
|
||||
String.format(url, tokenHolder.getAccessToken()),
|
||||
String.format(url, tokenManager.getAccessToken()),
|
||||
JSON.toJSONString(data, new NameFilter() {
|
||||
@Override
|
||||
public String process(Object object, String name,
|
||||
@@ -98,7 +98,7 @@ public class MenuApi extends MpApi {
|
||||
|
||||
private JSONObject getMenu0() throws WeixinException {
|
||||
String menu_get_uri = getRequestUri("menu_get_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
menu_get_uri, token.getAccessToken()));
|
||||
return response.getAsJson();
|
||||
@@ -150,7 +150,7 @@ public class MenuApi extends MpApi {
|
||||
*/
|
||||
public JsonResult deleteMenu() throws WeixinException {
|
||||
String menu_delete_uri = getRequestUri("menu_delete_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
menu_delete_uri, token.getAccessToken()));
|
||||
|
||||
@@ -192,7 +192,7 @@ public class MenuApi extends MpApi {
|
||||
*/
|
||||
public JsonResult deleteCustomMenu(String menuId) throws WeixinException {
|
||||
String menu_delete_uri = getRequestUri("menu_delete_custom_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("menuid", menuId);
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
@@ -216,7 +216,7 @@ public class MenuApi extends MpApi {
|
||||
*/
|
||||
public List<Button> matchCustomMenu(String userId) throws WeixinException {
|
||||
String menu_trymatch_uri = getRequestUri("menu_trymatch_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("user_id", userId);
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
package com.foxinmy.weixin4j.mp.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.JsonResult;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.message.NotifyMessage;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.tuple.MpArticle;
|
||||
import com.foxinmy.weixin4j.tuple.MpNews;
|
||||
import com.foxinmy.weixin4j.tuple.NotifyTuple;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
|
||||
/**
|
||||
* 客服消息API
|
||||
*
|
||||
*
|
||||
* @className NotifyApi
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2014年9月26日
|
||||
@@ -20,15 +24,17 @@ import com.foxinmy.weixin4j.util.StringUtil;
|
||||
*/
|
||||
public class NotifyApi extends MpApi {
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
private final MassApi massApi;
|
||||
|
||||
public NotifyApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public NotifyApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
this.massApi = new MassApi(tokenManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送客服消息(在48小时内不限制发送次数)
|
||||
*
|
||||
*
|
||||
* @param notify
|
||||
* 客服消息对象
|
||||
* @return 处理结果
|
||||
@@ -41,7 +47,7 @@ public class NotifyApi extends MpApi {
|
||||
|
||||
/**
|
||||
* 发送客服消息(在48小时内不限制发送次数)
|
||||
*
|
||||
*
|
||||
* @param notify
|
||||
* 客服消息对象
|
||||
* @param kfAccount
|
||||
@@ -61,6 +67,17 @@ public class NotifyApi extends MpApi {
|
||||
public JsonResult sendNotify(NotifyMessage notify, String kfAccount)
|
||||
throws WeixinException {
|
||||
NotifyTuple tuple = notify.getTuple();
|
||||
if (tuple instanceof MpNews) {
|
||||
MpNews _news = (MpNews) tuple;
|
||||
List<MpArticle> _articles = _news.getArticles();
|
||||
if (StringUtil.isBlank(_news.getMediaId())) {
|
||||
if (_articles.isEmpty()) {
|
||||
throw new WeixinException(
|
||||
"notify fail:mediaId or articles is required");
|
||||
}
|
||||
tuple = new MpNews(massApi.uploadArticle(_articles));
|
||||
}
|
||||
}
|
||||
String msgtype = tuple.getMessageType();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("touser", notify.getTouser());
|
||||
@@ -72,7 +89,7 @@ public class NotifyApi extends MpApi {
|
||||
obj.put("customservice", kf);
|
||||
}
|
||||
String custom_notify_uri = getRequestUri("custom_notify_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(custom_notify_uri, token.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.foxinmy.weixin4j.mp.api;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
@@ -110,9 +111,14 @@ public class OauthApi extends MpApi {
|
||||
String user_token_uri = getRequestUri("sns_user_token_uri");
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
user_token_uri, account.getId(), account.getSecret(), code));
|
||||
|
||||
return response.getAsObject(new TypeReference<OauthToken>() {
|
||||
});
|
||||
JSONObject result = response.getAsJson();
|
||||
OauthToken token = new OauthToken(result.getString("access_token"),
|
||||
result.getLongValue("expires_in") * 1000l);
|
||||
token.setUnionId(result.getString("unionid"));
|
||||
token.setOpenId(result.getString("openid"));
|
||||
token.setScope(result.getString("scope"));
|
||||
token.setRefreshToken(result.getString("refresh_token"));
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,6 +25,8 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.foxinmy.weixin4j.cache.CacheStorager;
|
||||
import com.foxinmy.weixin4j.cache.FileCacheStorager;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.JsonResult;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinRequestExecutor;
|
||||
@@ -42,9 +44,7 @@ import com.foxinmy.weixin4j.mp.token.WeixinTokenCreator;
|
||||
import com.foxinmy.weixin4j.payment.PayRequest;
|
||||
import com.foxinmy.weixin4j.sign.WeixinPaymentSignature;
|
||||
import com.foxinmy.weixin4j.sign.WeixinSignature;
|
||||
import com.foxinmy.weixin4j.token.FileTokenStorager;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenStorager;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.type.BillType;
|
||||
import com.foxinmy.weixin4j.type.IdQuery;
|
||||
import com.foxinmy.weixin4j.type.RefundType;
|
||||
@@ -69,7 +69,7 @@ import com.foxinmy.weixin4j.xml.ListsuffixResultDeserializer;
|
||||
public class PayOldApi extends MpApi {
|
||||
|
||||
private final WeixinOldPayAccount weixinAccount;
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
private final WeixinSignature weixinMD5Signature;
|
||||
private final WeixinOldPaymentSignature weixinOldSignature;
|
||||
|
||||
@@ -78,28 +78,28 @@ public class PayOldApi extends MpApi {
|
||||
*/
|
||||
public PayOldApi() {
|
||||
this(JSON.parseObject(Weixin4jConfigUtil.getValue("account"),
|
||||
WeixinOldPayAccount.class), new FileTokenStorager(
|
||||
WeixinOldPayAccount.class), new FileCacheStorager<Token>(
|
||||
Weixin4jConfigUtil.getClassPathValue("weixin4j.tmpdir",
|
||||
System.getProperty("java.io.tmpdir"))));
|
||||
}
|
||||
|
||||
public PayOldApi(WeixinOldPayAccount payAccount) {
|
||||
this(payAccount, new FileTokenStorager(
|
||||
this(payAccount, new FileCacheStorager<Token>(
|
||||
Weixin4jConfigUtil.getClassPathValue("weixin4j.tmpdir",
|
||||
System.getProperty("java.io.tmpdir"))));
|
||||
}
|
||||
|
||||
public PayOldApi(TokenStorager tokenStorager) {
|
||||
public PayOldApi(CacheStorager<Token> cacheStorager) {
|
||||
this(JSON.parseObject(Weixin4jConfigUtil.getValue("account"),
|
||||
WeixinOldPayAccount.class), tokenStorager);
|
||||
WeixinOldPayAccount.class), cacheStorager);
|
||||
}
|
||||
|
||||
public PayOldApi(WeixinOldPayAccount weixinAccount,
|
||||
TokenStorager tokenStorager) {
|
||||
CacheStorager<Token> cacheStorager) {
|
||||
this.weixinAccount = weixinAccount;
|
||||
this.tokenHolder = new TokenHolder(new WeixinTokenCreator(
|
||||
this.tokenManager = new TokenManager(new WeixinTokenCreator(
|
||||
weixinAccount.getId(), weixinAccount.getSecret()),
|
||||
tokenStorager);
|
||||
cacheStorager);
|
||||
this.weixinMD5Signature = new WeixinPaymentSignature(
|
||||
weixinAccount.getPartnerKey());
|
||||
this.weixinOldSignature = new WeixinOldPaymentSignature();
|
||||
@@ -109,7 +109,7 @@ public class PayOldApi extends MpApi {
|
||||
return this.weixinAccount;
|
||||
}
|
||||
|
||||
public WeixinOldPaymentSignature getWeixinPaymentSignature(){
|
||||
public WeixinOldPaymentSignature getWeixinPaymentSignature() {
|
||||
return this.weixinOldSignature;
|
||||
}
|
||||
|
||||
@@ -130,9 +130,9 @@ public class PayOldApi extends MpApi {
|
||||
*/
|
||||
public String createPayJsRequestJson(String body, String outTradeNo,
|
||||
double totalFee, String notifyUrl, String createIp) {
|
||||
PayPackageV2 payPackage = new PayPackageV2(weixinAccount
|
||||
.getPartnerId(), body, outTradeNo, totalFee, notifyUrl,
|
||||
createIp);
|
||||
PayPackageV2 payPackage = new PayPackageV2(
|
||||
weixinAccount.getPartnerId(), body, outTradeNo, totalFee,
|
||||
notifyUrl, createIp);
|
||||
return createPayJsRequestJson(payPackage);
|
||||
}
|
||||
|
||||
@@ -145,8 +145,8 @@ public class PayOldApi extends MpApi {
|
||||
*/
|
||||
public String createPayJsRequestJson(PayPackageV2 payPackage) {
|
||||
PayRequest payRequest = new PayRequest(weixinAccount.getId(),
|
||||
weixinOldSignature.sign(payPackage, weixinAccount
|
||||
.getPartnerKey()));
|
||||
weixinOldSignature.sign(payPackage,
|
||||
weixinAccount.getPartnerKey()));
|
||||
payRequest.setPaySign(weixinOldSignature.sign(payRequest,
|
||||
weixinAccount.getPaySignKey()));
|
||||
payRequest.setSignType(SignType.SHA1);
|
||||
@@ -187,7 +187,7 @@ public class PayOldApi extends MpApi {
|
||||
*/
|
||||
public OrderV2 queryOrder(IdQuery idQuery) throws WeixinException {
|
||||
String orderquery_uri = getRequestUri("orderquery_old_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(idQuery.getType().getName()).append("=")
|
||||
.append(idQuery.getId());
|
||||
@@ -286,9 +286,10 @@ public class PayOldApi extends MpApi {
|
||||
SSLContext ctx = null;
|
||||
KeyStore ks = null;
|
||||
String jksPwd = "";
|
||||
File jksFile = new File(String.format("%s/tenpay_cacert.jks",
|
||||
File jksFile = new File(String.format("%s%stenpay_cacert.jks",
|
||||
Weixin4jConfigUtil.getClassPathValue("weixin4j.tmpdir",
|
||||
System.getProperty("java.io.tmpdir"))));
|
||||
System.getProperty("java.io.tmpdir")),
|
||||
File.separator));
|
||||
// create jks ca
|
||||
if (!jksFile.exists()) {
|
||||
CertificateFactory cf = CertificateFactory
|
||||
@@ -450,9 +451,10 @@ public class PayOldApi extends MpApi {
|
||||
}
|
||||
String formatBillDate = DateUtil.fortmat2yyyyMMdd(billDate);
|
||||
String fileName = String.format("weixin4j_bill_%s_%s_%s.txt",
|
||||
formatBillDate, billType.name().toLowerCase(), weixinAccount
|
||||
.getId());
|
||||
File file = new File(String.format("%s/%s", billPath, fileName));
|
||||
formatBillDate, billType.name().toLowerCase(),
|
||||
weixinAccount.getId());
|
||||
File file = new File(String.format("%s%s%s", billPath, File.separator,
|
||||
fileName));
|
||||
if (file.exists()) {
|
||||
return file;
|
||||
}
|
||||
@@ -543,7 +545,7 @@ public class PayOldApi extends MpApi {
|
||||
String outTradeNo, boolean status, String statusMsg)
|
||||
throws WeixinException {
|
||||
String delivernotify_uri = getRequestUri("delivernotify_old_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("appid", weixinAccount.getId());
|
||||
@@ -576,7 +578,7 @@ public class PayOldApi extends MpApi {
|
||||
public JsonResult updateFeedback(String openId, String feedbackId)
|
||||
throws WeixinException {
|
||||
String payfeedback_uri = getRequestUri("payfeedback_old_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
payfeedback_uri, token.getAccessToken(), openId, feedbackId));
|
||||
return response.getAsJsonResult();
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.model.QRParameter;
|
||||
import com.foxinmy.weixin4j.mp.model.QRResult;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.util.IOUtil;
|
||||
|
||||
/**
|
||||
@@ -21,10 +21,10 @@ import com.foxinmy.weixin4j.util.IOUtil;
|
||||
*/
|
||||
public class QrApi extends MpApi {
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public QrApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public QrApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,7 +40,7 @@ public class QrApi extends MpApi {
|
||||
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1443433542&token=&lang=zh_CN">生成二维码</a>
|
||||
*/
|
||||
public QRResult createQR(QRParameter parameter) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String qr_uri = getRequestUri("qr_ticket_uri");
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(qr_uri, token.getAccessToken()),
|
||||
|
||||
@@ -11,7 +11,7 @@ import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.mp.model.Following;
|
||||
import com.foxinmy.weixin4j.mp.model.Tag;
|
||||
import com.foxinmy.weixin4j.mp.model.User;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
|
||||
/**
|
||||
* 标签相关API
|
||||
@@ -23,12 +23,12 @@ import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
* @see com.foxinmy.weixin4j.mp.model.Tag
|
||||
*/
|
||||
public class TagApi extends MpApi {
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
private final UserApi userApi;
|
||||
|
||||
public TagApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
this.userApi = new UserApi(tokenHolder);
|
||||
public TagApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
this.userApi = new UserApi(tokenManager);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,7 +45,7 @@ public class TagApi extends MpApi {
|
||||
public Tag createTag(String name) throws WeixinException {
|
||||
String tag_create_uri = getRequestUri("tag_create_uri");
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(tag_create_uri, tokenHolder.getAccessToken()),
|
||||
String.format(tag_create_uri, tokenManager.getAccessToken()),
|
||||
String.format("{\"tag\":{\"name\":\"%s\"}}", name));
|
||||
|
||||
return JSON.parseObject(response.getAsJson().getString("tag"),
|
||||
@@ -64,7 +64,7 @@ public class TagApi extends MpApi {
|
||||
public List<Tag> listTags() throws WeixinException {
|
||||
String tag_get_uri = getRequestUri("tag_get_uri");
|
||||
WeixinResponse response = weixinExecutor.get(String.format(tag_get_uri,
|
||||
tokenHolder.getAccessToken()));
|
||||
tokenManager.getAccessToken()));
|
||||
|
||||
return JSON.parseArray(response.getAsJson().getString("tags"),
|
||||
Tag.class);
|
||||
@@ -86,7 +86,7 @@ public class TagApi extends MpApi {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("tag", tag);
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(tag_update_uri, tokenHolder.getAccessToken()),
|
||||
String.format(tag_update_uri, tokenManager.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public class TagApi extends MpApi {
|
||||
public JsonResult deleteTag(int tagId) throws WeixinException {
|
||||
String tag_delete_uri = getRequestUri("tag_delete_uri");
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(tag_delete_uri, tokenHolder.getAccessToken()),
|
||||
String.format(tag_delete_uri, tokenManager.getAccessToken()),
|
||||
String.format("{\"tagid\":%d}", tagId));
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
@@ -133,7 +133,7 @@ public class TagApi extends MpApi {
|
||||
obj.put("openid_list", openIds);
|
||||
obj.put("tagid", tagId);
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(tag_batch_uri, tokenHolder.getAccessToken()),
|
||||
String.format(tag_batch_uri, tokenManager.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
@@ -174,7 +174,7 @@ public class TagApi extends MpApi {
|
||||
obj.put("tagid", tagId);
|
||||
obj.put("next_openid", nextOpenId);
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(tag_user_uri, tokenHolder.getAccessToken()),
|
||||
String.format(tag_user_uri, tokenManager.getAccessToken()),
|
||||
obj.toJSONString());
|
||||
|
||||
JSONObject result = response.getAsJson();
|
||||
@@ -283,7 +283,7 @@ public class TagApi extends MpApi {
|
||||
public Integer[] getUserTags(String openId) throws WeixinException {
|
||||
String tag_userids_uri = getRequestUri("tag_userids_uri");
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(tag_userids_uri, tokenHolder.getAccessToken()),
|
||||
String.format(tag_userids_uri, tokenManager.getAccessToken()),
|
||||
String.format("{\"openid\":\"%s\"}", openId));
|
||||
return response.getAsJson().getJSONArray("tagid_list")
|
||||
.toArray(new Integer[] {});
|
||||
|
||||
@@ -12,7 +12,7 @@ import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.message.TemplateMessage;
|
||||
import com.foxinmy.weixin4j.mp.model.TemplateMessageInfo;
|
||||
import com.foxinmy.weixin4j.mp.type.IndustryType;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.util.NameValue;
|
||||
|
||||
/**
|
||||
@@ -26,10 +26,10 @@ import com.foxinmy.weixin4j.util.NameValue;
|
||||
*/
|
||||
public class TmplApi extends MpApi {
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public TmplApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public TmplApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +50,7 @@ public class TmplApi extends MpApi {
|
||||
obj.put(String.format("industry_id%d", i + 1),
|
||||
Integer.toString(industryTypes[i].getTypeId()));
|
||||
}
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String template_set_industry_uri = getRequestUri("template_set_industry_uri");
|
||||
WeixinResponse response = weixinExecutor.post(String.format(
|
||||
template_set_industry_uri, token.getAccessToken()), obj
|
||||
@@ -71,7 +71,7 @@ public class TmplApi extends MpApi {
|
||||
public IndustryType[] getTmplIndustry() throws WeixinException {
|
||||
String template_get_industry_uri = getRequestUri("template_get_industry_uri");
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
template_get_industry_uri, tokenHolder.getAccessToken()));
|
||||
template_get_industry_uri, tokenManager.getAccessToken()));
|
||||
JSONObject primary = response.getAsJson().getJSONObject(
|
||||
"primary_industry");
|
||||
JSONObject secondary = response.getAsJson().getJSONObject(
|
||||
@@ -96,7 +96,7 @@ public class TmplApi extends MpApi {
|
||||
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN">获得模板ID</a>
|
||||
*/
|
||||
public String getTemplateId(String shortId) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String template_getid_uri = getRequestUri("template_getid_uri");
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(template_getid_uri, token.getAccessToken()),
|
||||
@@ -115,7 +115,7 @@ public class TmplApi extends MpApi {
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public List<TemplateMessageInfo> getAllTemplates() throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String template_getall_uri = getRequestUri("template_getall_uri");
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
template_getall_uri, token.getAccessToken()));
|
||||
@@ -134,7 +134,7 @@ public class TmplApi extends MpApi {
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult deleteTemplate(String templateId) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String template_del_uri = getRequestUri("template_del_uri");
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(template_del_uri, token.getAccessToken()),
|
||||
@@ -159,7 +159,7 @@ public class TmplApi extends MpApi {
|
||||
*/
|
||||
public JsonResult sendTmplMessage(TemplateMessage tplMessage)
|
||||
throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
String template_send_uri = getRequestUri("template_send_uri");
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(template_send_uri, token.getAccessToken()),
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.model.Following;
|
||||
import com.foxinmy.weixin4j.mp.model.User;
|
||||
import com.foxinmy.weixin4j.mp.type.Lang;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
|
||||
/**
|
||||
* 用户相关API
|
||||
@@ -26,10 +26,10 @@ import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
*/
|
||||
public class UserApi extends MpApi {
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public UserApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
public UserApi(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +66,7 @@ public class UserApi extends MpApi {
|
||||
*/
|
||||
public User getUser(String openId, Lang lang) throws WeixinException {
|
||||
String user_info_uri = getRequestUri("api_user_info_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
user_info_uri, token.getAccessToken(), openId, lang.name()));
|
||||
|
||||
@@ -118,7 +118,7 @@ public class UserApi extends MpApi {
|
||||
}
|
||||
parameter.delete(parameter.length() - 1, parameter.length());
|
||||
parameter.append("]}");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(api_users_info_uri, token.getAccessToken()),
|
||||
parameter.toString());
|
||||
@@ -174,7 +174,7 @@ public class UserApi extends MpApi {
|
||||
public Following getFollowingOpenIds(String nextOpenId)
|
||||
throws WeixinException {
|
||||
String following_uri = getRequestUri("following_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
following_uri, token.getAccessToken(), nextOpenId == null ? ""
|
||||
: nextOpenId));
|
||||
@@ -267,7 +267,7 @@ public class UserApi extends MpApi {
|
||||
public JsonResult remarkUserName(String openId, String remark)
|
||||
throws WeixinException {
|
||||
String username_remark_uri = getRequestUri("username_remark_uri");
|
||||
Token token = tokenHolder.getToken();
|
||||
Token token = tokenManager.getCache();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("openid", openId);
|
||||
obj.put("remark", remark);
|
||||
|
||||
@@ -10,7 +10,7 @@ import com.foxinmy.weixin4j.util.NameValue;
|
||||
|
||||
/**
|
||||
* 模板消息
|
||||
*
|
||||
*
|
||||
* @className TemplateMessage
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2014年9月29日
|
||||
@@ -56,10 +56,7 @@ public class TemplateMessage implements Serializable {
|
||||
private final static String TAIL_KEY = "remark";
|
||||
private final static String DEFAULT_COLOR = "#173177";
|
||||
|
||||
@JSONCreator
|
||||
public TemplateMessage(@JSONField(name = "toUser") String toUser,
|
||||
@JSONField(name = "templateId") String templateId,
|
||||
@JSONField(name = "url") String url) {
|
||||
public TemplateMessage(String toUser, String templateId, String url) {
|
||||
this.toUser = toUser;
|
||||
this.templateId = templateId;
|
||||
this.url = url;
|
||||
@@ -92,7 +89,7 @@ public class TemplateMessage implements Serializable {
|
||||
|
||||
/**
|
||||
* 新增头部字段(默认颜色为#FF0000)
|
||||
*
|
||||
*
|
||||
* @param text
|
||||
* 字段文本
|
||||
* @return
|
||||
@@ -103,7 +100,7 @@ public class TemplateMessage implements Serializable {
|
||||
|
||||
/**
|
||||
* 新增头部字段
|
||||
*
|
||||
*
|
||||
* @param color
|
||||
* 文字颜色
|
||||
* @param text
|
||||
@@ -118,7 +115,7 @@ public class TemplateMessage implements Serializable {
|
||||
|
||||
/**
|
||||
* 新增尾部字段(默认颜色为#173177)
|
||||
*
|
||||
*
|
||||
* @param text
|
||||
* 字段文本
|
||||
* @return
|
||||
@@ -129,7 +126,7 @@ public class TemplateMessage implements Serializable {
|
||||
|
||||
/**
|
||||
* 新增尾部字段
|
||||
*
|
||||
*
|
||||
* @param color
|
||||
* 文字颜色
|
||||
* @param text
|
||||
@@ -144,7 +141,7 @@ public class TemplateMessage implements Serializable {
|
||||
|
||||
/**
|
||||
* 新增字段项(默认颜色为#173177)
|
||||
*
|
||||
*
|
||||
* @param key
|
||||
* 预留的字段名
|
||||
* @param text
|
||||
@@ -157,7 +154,7 @@ public class TemplateMessage implements Serializable {
|
||||
|
||||
/**
|
||||
* 新增字段项
|
||||
*
|
||||
*
|
||||
* @param key
|
||||
* 预留的字段名
|
||||
* @param color
|
||||
@@ -173,7 +170,7 @@ public class TemplateMessage implements Serializable {
|
||||
|
||||
/**
|
||||
* 设置所有字段项
|
||||
*
|
||||
*
|
||||
* @param items
|
||||
*/
|
||||
public void pushItems(Map<String, NameValue> items) {
|
||||
|
||||
@@ -7,10 +7,11 @@ import java.util.List;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.type.AutomatchMode;
|
||||
import com.foxinmy.weixin4j.mp.type.AutoreplyMode;
|
||||
import com.foxinmy.weixin4j.type.ButtonType;
|
||||
|
||||
/**
|
||||
* 自动回复设置
|
||||
*
|
||||
*
|
||||
* @className AutoReplySetting
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年4月15日
|
||||
@@ -34,7 +35,7 @@ public class AutoReplySetting implements Serializable {
|
||||
|
||||
/**
|
||||
* 关注后自动回复的信息
|
||||
*
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.mp.model.AutoReplySetting.Entry
|
||||
*/
|
||||
@JSONField(name = "add_friend_autoreply_info")
|
||||
@@ -42,7 +43,7 @@ public class AutoReplySetting implements Serializable {
|
||||
|
||||
/**
|
||||
* 默认自动回复的信息
|
||||
*
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.mp.model.AutoReplySetting.Entry
|
||||
*/
|
||||
@JSONField(name = "message_default_autoreply_info")
|
||||
@@ -50,7 +51,7 @@ public class AutoReplySetting implements Serializable {
|
||||
|
||||
/**
|
||||
* 关键词自动回复的信息
|
||||
*
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.mp.model.AutoReplySetting.Rule
|
||||
*/
|
||||
private List<Rule> keywordReplyList;
|
||||
@@ -105,7 +106,7 @@ public class AutoReplySetting implements Serializable {
|
||||
|
||||
/**
|
||||
* 关键字规则
|
||||
*
|
||||
*
|
||||
* @className Rule
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年4月15日
|
||||
@@ -127,21 +128,21 @@ public class AutoReplySetting implements Serializable {
|
||||
private Date createTime;
|
||||
/**
|
||||
* 回复模式
|
||||
*
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.mp.type.AutoreplyMode
|
||||
*/
|
||||
@JSONField(name = "reply_mode")
|
||||
private AutoreplyMode replyMode;
|
||||
/**
|
||||
* 匹配的关键词列表
|
||||
*
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.mp.model.AutoReplySetting.Entry
|
||||
*/
|
||||
@JSONField(name = "keyword_list_info")
|
||||
private List<Entry> keywordList;
|
||||
/**
|
||||
* 回复的信息列表
|
||||
*
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.mp.model.AutoReplySetting.Entry
|
||||
*/
|
||||
@JSONField(name = "reply_list_info")
|
||||
@@ -189,16 +190,15 @@ public class AutoReplySetting implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Rule [ruleName=" + ruleName + ", createTime="
|
||||
+ createTime + ", replyMode=" + replyMode
|
||||
+ ", keywordList=" + keywordList + ", replyList="
|
||||
+ replyList + "]";
|
||||
return "Rule [ruleName=" + ruleName + ", createTime=" + createTime
|
||||
+ ", replyMode=" + replyMode + ", keywordList="
|
||||
+ keywordList + ", replyList=" + replyList + "]";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据项
|
||||
*
|
||||
*
|
||||
* @className Entry
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年4月15日
|
||||
@@ -212,26 +212,26 @@ public class AutoReplySetting implements Serializable {
|
||||
* 自动回复的类型。关注后自动回复和消息自动回复的类型仅支持文本(text)、图片(img)、语音(voice)、视频(video),
|
||||
* 关键词自动回复则还多了图文消息(news)
|
||||
*/
|
||||
private String type;
|
||||
private ButtonType type;
|
||||
/**
|
||||
* 对于文本类型,content是文本内容,对于图片、语音、视频类型,content是mediaID,news是article
|
||||
*
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.tuple.MpArticle
|
||||
*/
|
||||
private Serializable content;
|
||||
/**
|
||||
* 匹配模式(仅但关键字列表)
|
||||
*
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.mp.type.AutomatchMode
|
||||
*/
|
||||
@JSONField(name = "match_mode")
|
||||
private AutomatchMode matchMode;
|
||||
|
||||
public String getType() {
|
||||
public ButtonType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
public void setType(ButtonType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.foxinmy.weixin4j.model.Button;
|
||||
|
||||
/**
|
||||
* 自定义菜单配置
|
||||
*
|
||||
*
|
||||
* @className MenuSetting
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年4月14日
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package com.foxinmy.weixin4j.mp.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONCreator;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
|
||||
/**
|
||||
* 用户授权token 一般通过授权页面获得
|
||||
*
|
||||
*
|
||||
* @className OauthToken
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2014年4月6日
|
||||
* @since JDK 1.6
|
||||
* @see com.foxinmy.weixin4j.mp.model.AuthResult
|
||||
* @see com.foxinmy.weixin4j.mp.model.AuthResult.AuthScope
|
||||
*/
|
||||
public class OauthToken extends Token {
|
||||
|
||||
@@ -36,6 +35,10 @@ public class OauthToken extends Token {
|
||||
|
||||
private String scope;
|
||||
|
||||
public OauthToken(String accessToken, long expires) {
|
||||
super(accessToken, expires);
|
||||
}
|
||||
|
||||
public String getOpenId() {
|
||||
return openId;
|
||||
}
|
||||
@@ -71,9 +74,7 @@ public class OauthToken extends Token {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OauthToken [openId=" + openId + ", unionId=" + unionId
|
||||
+ ", refreshToken=" + refreshToken + ", scope=" + scope
|
||||
+ ", accessToken=" + getAccessToken()
|
||||
+ ", expiresIn=" + getExpiresIn() + ", createTime="
|
||||
+ getCreateTime() + "]";
|
||||
+ ", refreshToken=" + refreshToken + ", scope=" + scope + ", "
|
||||
+ super.toString() + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.type.URLConsts;
|
||||
import com.foxinmy.weixin4j.token.TokenCreator;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.token.TokenManager;
|
||||
import com.foxinmy.weixin4j.type.TicketType;
|
||||
|
||||
/**
|
||||
* 微信公众平台TICKET创建(包括jsticket、其它JSSDK所需的ticket的创建
|
||||
*
|
||||
* @className WeixinJSTicketCreator
|
||||
* @className WeixinTicketCreator
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年1月10日
|
||||
* @since JDK 1.6
|
||||
@@ -24,7 +24,7 @@ public class WeixinTicketCreator extends TokenCreator {
|
||||
|
||||
private final String appid;
|
||||
private final TicketType ticketType;
|
||||
private final TokenHolder weixinTokenHolder;
|
||||
private final TokenManager weixinTokenManager;
|
||||
|
||||
/**
|
||||
* jssdk
|
||||
@@ -33,13 +33,14 @@ public class WeixinTicketCreator extends TokenCreator {
|
||||
* 公众号的appid
|
||||
* @param ticketType
|
||||
* 票据类型
|
||||
* @param weixinTokenHolder
|
||||
* @param weixinTokenManager
|
||||
* <font color="red">公众平台的access_token</font>
|
||||
*/
|
||||
public WeixinTicketCreator(String appid, TicketType ticketType, TokenHolder weixinTokenHolder) {
|
||||
public WeixinTicketCreator(String appid, TicketType ticketType,
|
||||
TokenManager weixinTokenManager) {
|
||||
this.appid = appid;
|
||||
this.ticketType = ticketType;
|
||||
this.weixinTokenHolder = weixinTokenHolder;
|
||||
this.weixinTokenManager = weixinTokenManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,12 +50,11 @@ public class WeixinTicketCreator extends TokenCreator {
|
||||
|
||||
@Override
|
||||
public Token create() throws WeixinException {
|
||||
WeixinResponse response = weixinExecutor.get(
|
||||
String.format(URLConsts.JS_TICKET_URL, weixinTokenHolder.getToken().getAccessToken(), ticketType.name()));
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
URLConsts.JS_TICKET_URL, weixinTokenManager.getAccessToken(),
|
||||
ticketType.name()));
|
||||
JSONObject result = response.getAsJson();
|
||||
Token token = new Token(result.getString("ticket"));
|
||||
token.setExpiresIn(result.getIntValue("expires_in"));
|
||||
token.setOriginalResult(response.getAsString());
|
||||
return token;
|
||||
return new Token(result.getString("ticket"),
|
||||
result.getLongValue("expires_in") * 1000l);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.foxinmy.weixin4j.mp.token;
|
||||
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
@@ -45,10 +45,8 @@ public class WeixinTokenCreator extends TokenCreator {
|
||||
String tokenUrl = String.format(URLConsts.ASSESS_TOKEN_URL, appid,
|
||||
secret);
|
||||
WeixinResponse response = weixinExecutor.get(tokenUrl);
|
||||
Token token = response.getAsObject(new TypeReference<Token>() {
|
||||
});
|
||||
token.setCreateTime(System.currentTimeMillis());
|
||||
token.setOriginalResult(response.getAsString());
|
||||
return token;
|
||||
JSONObject result = response.getAsJson();
|
||||
return new Token(result.getString("access_token"),
|
||||
result.getLongValue("expires_in") * 1000l);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user