🎨 精简代码,移除无用过期接口代码

This commit is contained in:
Binary Wang 2020-08-23 17:22:35 +08:00
parent 6d996f20b9
commit b5956fb298
28 changed files with 113 additions and 827 deletions

View File

@ -55,130 +55,4 @@ public class WxMpServiceAutoConfiguration {
return new WxMpServiceJoddHttpImpl();
}
@Bean
@Deprecated
public WxMpKefuService wxMpKefuService(WxMpService wxMpService) {
return wxMpService.getKefuService();
}
@Bean
@Deprecated
public WxMpMaterialService wxMpMaterialService(WxMpService wxMpService) {
return wxMpService.getMaterialService();
}
@Bean
@Deprecated
public WxMpMenuService wxMpMenuService(WxMpService wxMpService) {
return wxMpService.getMenuService();
}
@Bean
@Deprecated
public WxMpUserService wxMpUserService(WxMpService wxMpService) {
return wxMpService.getUserService();
}
@Bean
@Deprecated
public WxMpUserTagService wxMpUserTagService(WxMpService wxMpService) {
return wxMpService.getUserTagService();
}
@Bean
@Deprecated
public WxMpQrcodeService wxMpQrcodeService(WxMpService wxMpService) {
return wxMpService.getQrcodeService();
}
@Bean
@Deprecated
public WxMpCardService wxMpCardService(WxMpService wxMpService) {
return wxMpService.getCardService();
}
@Bean
@Deprecated
public WxMpDataCubeService wxMpDataCubeService(WxMpService wxMpService) {
return wxMpService.getDataCubeService();
}
@Bean
@Deprecated
public WxMpUserBlacklistService wxMpUserBlacklistService(WxMpService wxMpService) {
return wxMpService.getBlackListService();
}
@Bean
@Deprecated
public WxMpStoreService wxMpStoreService(WxMpService wxMpService) {
return wxMpService.getStoreService();
}
@Bean
@Deprecated
public WxMpTemplateMsgService wxMpTemplateMsgService(WxMpService wxMpService) {
return wxMpService.getTemplateMsgService();
}
@Bean
@Deprecated
public WxMpSubscribeMsgService wxMpSubscribeMsgService(WxMpService wxMpService) {
return wxMpService.getSubscribeMsgService();
}
@Bean
@Deprecated
public WxMpDeviceService wxMpDeviceService(WxMpService wxMpService) {
return wxMpService.getDeviceService();
}
@Bean
@Deprecated
public WxMpShakeService wxMpShakeService(WxMpService wxMpService) {
return wxMpService.getShakeService();
}
@Bean
@Deprecated
public WxMpMemberCardService wxMpMemberCardService(WxMpService wxMpService) {
return wxMpService.getMemberCardService();
}
@Bean
@Deprecated
public WxMpMassMessageService wxMpMassMessageService(WxMpService wxMpService) {
return wxMpService.getMassMessageService();
}
@Bean
@Deprecated
public WxMpAiOpenService wxMpAiOpenService(WxMpService wxMpService) {
return wxMpService.getAiOpenService();
}
@Bean
@Deprecated
public WxMpWifiService wxMpWifiService(WxMpService wxMpService) {
return wxMpService.getWifiService();
}
@Bean
@Deprecated
public WxMpMarketingService wxMpMarketingService(WxMpService wxMpService) {
return wxMpService.getMarketingService();
}
@Bean
@Deprecated
public WxMpCommentService wxMpCommentService(WxMpService wxMpService) {
return wxMpService.getCommentService();
}
@Bean
@Deprecated
public WxOcrService wxMpOcrService(WxMpService wxMpService) {
return wxMpService.getOcrService();
}
}

View File

@ -12,10 +12,6 @@ import java.util.List;
* @author gaigeshen
*/
public interface WxCpChatService {
@Deprecated
String chatCreate(String name, String owner, List<String> users, String chatId) throws WxErrorException;
/**
* 创建群聊会话注意刚创建的群如果没有下发消息在企业微信不会出现该群.
*
@ -28,9 +24,6 @@ public interface WxCpChatService {
*/
String create(String name, String owner, List<String> users, String chatId) throws WxErrorException;
@Deprecated
void chatUpdate(String chatId, String name, String owner, List<String> usersToAdd, List<String> usersToDelete) throws WxErrorException;
/**
* 修改群聊会话.
*
@ -43,9 +36,6 @@ public interface WxCpChatService {
*/
void update(String chatId, String name, String owner, List<String> usersToAdd, List<String> usersToDelete) throws WxErrorException;
@Deprecated
WxCpChat chatGet(String chatId) throws WxErrorException;
/**
* 获取群聊会话.
*

View File

@ -110,23 +110,6 @@ public interface WxCpOaService {
*/
WxCpApprovalDetailResult getApprovalDetail(@NonNull String spNo) throws WxErrorException;
/**
* <pre>
* 获取审批数据 (已过期, 请使用"批量获取审批单号" && "获取审批申请详情")
* 通过本接口来获取公司一段时间内的审批记录一次拉取调用最多拉取10000个审批记录可以通过多次拉取的方式来满足需求但调用频率不可超过600次/
* API doc : https://work.weixin.qq.com/api/doc#90000/90135/91530
* </pre>
*
* @param startTime 获取审批记录的开始时间
* @param endTime 获取审批记录的结束时间
* @param nextSpnum 第一个拉取的审批单号不填从该时间段的第一个审批单拉取
* @throws WxErrorException .
* @see me.chanjar.weixin.cp.api.WxCpOaService#getApprovalInfo
* @see me.chanjar.weixin.cp.api.WxCpOaService#getApprovalDetail
*/
@Deprecated
WxCpApprovalDataResult getApprovalData(Date startTime, Date endTime, Long nextSpnum) throws WxErrorException;
/**
* 获取公费电话拨打记录
*

View File

@ -17,7 +17,6 @@ import java.util.List;
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public interface WxCpTagService {
/**
* 创建标签.
* <pre>
@ -32,17 +31,6 @@ public interface WxCpTagService {
*/
String create(String name, Integer id) throws WxErrorException;
/**
* 创建标签.
*
* @param tagName 标签名
* @return 标签id
* @throws WxErrorException .
* @deprecated 建议使用 {@link #create(String, Integer)}其中后面的参数可以为空
*/
@Deprecated
String create(String tagName) throws WxErrorException;
/**
* 更新标签.
*

View File

@ -24,11 +24,10 @@ import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Chat.*;
*/
@RequiredArgsConstructor
public class WxCpChatServiceImpl implements WxCpChatService {
private final WxCpService cpService;
@Override
public String chatCreate(String name, String owner, List<String> users, String chatId) throws WxErrorException {
public String create(String name, String owner, List<String> users, String chatId) throws WxErrorException {
Map<String, Object> data = new HashMap<>(4);
if (StringUtils.isNotBlank(name)) {
data.put("name", name);
@ -48,12 +47,7 @@ public class WxCpChatServiceImpl implements WxCpChatService {
}
@Override
public String create(String name, String owner, List<String> users, String chatId) throws WxErrorException {
return this.chatCreate(name, owner, users, chatId);
}
@Override
public void chatUpdate(String chatId, String name, String owner, List<String> usersToAdd, List<String> usersToDelete)
public void update(String chatId, String name, String owner, List<String> usersToAdd, List<String> usersToDelete)
throws WxErrorException {
Map<String, Object> data = new HashMap<>(5);
if (StringUtils.isNotBlank(chatId)) {
@ -77,24 +71,13 @@ public class WxCpChatServiceImpl implements WxCpChatService {
}
@Override
public void update(String chatId, String name, String owner, List<String> usersToAdd, List<String> usersToDelete)
throws WxErrorException {
chatUpdate(chatId, name, owner, usersToAdd, usersToDelete);
}
@Override
public WxCpChat chatGet(String chatId) throws WxErrorException {
public WxCpChat get(String chatId) throws WxErrorException {
final String url = this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_GET_CHATID + chatId);
String result = this.cpService.get(url, null);
final String chatInfo = GsonParser.parse(result).getAsJsonObject("chat_info").toString();
return WxCpGsonBuilder.create().fromJson(chatInfo, WxCpChat.class);
}
@Override
public WxCpChat get(String chatId) throws WxErrorException {
return this.chatGet(chatId);
}
@Override
public void sendMsg(WxCpAppChatMessage message) throws WxErrorException {
this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(APPCHAT_SEND), message.toJson());

View File

@ -164,20 +164,6 @@ public class WxCpOaServiceImpl implements WxCpOaService {
return WxCpGsonBuilder.create().fromJson(responseContent, WxCpApprovalDetailResult.class);
}
@Override
public WxCpApprovalDataResult getApprovalData(Date startTime, Date endTime, Long nextSpnum) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("starttime", startTime.getTime() / 1000L);
jsonObject.addProperty("endtime", endTime.getTime() / 1000L);
if (nextSpnum != null) {
jsonObject.addProperty("next_spnum", nextSpnum);
}
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_APPROVAL_DATA);
String responseContent = this.mainService.post(url, jsonObject.toString());
return WxCpGsonBuilder.create().fromJson(responseContent, WxCpApprovalDataResult.class);
}
@Override
public List<WxCpDialRecord> getDialRecord(Date startTime, Date endTime, Integer offset, Integer limit)
throws WxErrorException {

View File

@ -40,13 +40,6 @@ public class WxCpTagServiceImpl implements WxCpTagService {
return this.create(o);
}
@Override
public String create(String tagName) throws WxErrorException {
JsonObject o = new JsonObject();
o.addProperty("tagname", tagName);
return this.create(o);
}
private String create(JsonObject param) throws WxErrorException {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(TAG_CREATE);
String responseContent = this.mainService.post(url, param.toString());

View File

@ -1,69 +0,0 @@
package me.chanjar.weixin.cp.bean.oa;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import java.io.Serializable;
import java.util.Map;
/**
* 企业微信 OA 审批数据.
*
* @author Element
* @date 2019-04-06 14:36
*/
@Deprecated
@Data
public class WxCpApprovalDataResult implements Serializable {
private static final long serialVersionUID = -1046940445840716590L;
@SerializedName("errcode")
private Integer errCode;
@SerializedName("errmsg")
private String errMsg;
private Integer count;
private Integer total;
@SerializedName("next_spnum")
private Long nextSpNum;
private WxCpApprovalData[] data;
@Data
public static class WxCpApprovalData implements Serializable {
private static final long serialVersionUID = -3051785319608491640L;
@SerializedName("spname")
private String spName;
@SerializedName("apply_name")
private String applyName;
@SerializedName("apply_org")
private String applyOrg;
@SerializedName("approval_name")
private String[] approvalName;
@SerializedName("notify_name")
private String[] notifyName;
@SerializedName("sp_status")
private Integer spStatus;
@SerializedName("sp_num")
private Long spNum;
@SerializedName("apply_time")
private Long applyTime;
@SerializedName("apply_user_id")
private String applyUserId;
@SerializedName("comm")
private Map<String, String> comm;
}
}

View File

@ -12,7 +12,6 @@ import java.io.Serializable;
*/
@Data
public class WxCpApprovalDetailResult implements Serializable {
private static final long serialVersionUID = 3909779949756252918L;
@SerializedName("errcode")

View File

@ -11,7 +11,6 @@ import lombok.Data;
*/
@Data
public class WxCpApprovalInfo implements Serializable {
private static final long serialVersionUID = 7387181805254287167L;
@SerializedName("errcode")

View File

@ -68,8 +68,6 @@ public final class WxCpApiPathConsts {
public static final String GET_APPROVAL_INFO = "/cgi-bin/oa/getapprovalinfo";
public static final String GET_APPROVAL_DETAIL = "/cgi-bin/oa/getapprovaldetail";
public static final String GET_DIAL_RECORD = "/cgi-bin/dial/get_dial_record";
@Deprecated
public static final String GET_APPROVAL_DATA = "/cgi-bin/corp/getapprovaldata";
public static final String GET_TEMPLATE_DETAIL = "/cgi-bin/oa/gettemplatedetail";
public static final String APPLY_EVENT = "/cgi-bin/oa/applyevent";
}

View File

@ -32,20 +32,6 @@ public interface WxMaMsgService {
*/
boolean sendKefuMsg(WxMaKefuMessage message) throws WxErrorException;
/**
* <pre>
* 发送模板消息
* 详情请见: <a href="https://developers.weixin.qq.com/miniprogram/dev/api-backend/templateMessage.send.html">发送模板消息</a>
* 接口url格式https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN
* 小程序模板消息接口将于2020年1月10日下线开发者可使用订阅消息功能
* </pre>
*
* @param templateMessage 模版消息
* @throws WxErrorException .
*/
@Deprecated
void sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException;
/**
* <pre>
* 发送订阅消息

View File

@ -229,13 +229,6 @@ public interface WxMaService extends WxService {
*/
WxMaQrcodeService getQrcodeService();
/**
* 返回模板配置相关接口方法的实现类对象, 以方便调用其各个接口.
*
* @return WxMaTemplateService
*/
WxMaTemplateService getTemplateService();
/**
* 返回订阅消息配置相关接口方法的实现类对象, 以方便调用其各个接口.
*

View File

@ -1,90 +0,0 @@
package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateAddResult;
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateLibraryGetResult;
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateLibraryListResult;
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateListResult;
import me.chanjar.weixin.common.error.WxErrorException;
import java.util.List;
/**
* @author IOManlewis.lynn1006@gmail.com
*/
@Deprecated
public interface WxMaTemplateService {
/**
* 获取小程序模板库标题列表.
*/
String TEMPLATE_LIBRARY_LIST_URL = "https://api.weixin.qq.com/cgi-bin/wxopen/template/library/list";
/**
* 获取模板库某个模板标题下关键词库.
*/
String TEMPLATE_LIBRARY_KEYWORD_URL = "https://api.weixin.qq.com/cgi-bin/wxopen/template/library/get";
/**
* 组合模板并添加至帐号下的个人模板库.
*/
String TEMPLATE_ADD_URL = "https://api.weixin.qq.com/cgi-bin/wxopen/template/add";
/**
* 获取帐号下已存在的模板列表.
*/
String TEMPLATE_LIST_URL = "https://api.weixin.qq.com/cgi-bin/wxopen/template/list";
/**
* 删除帐号下的某个模板.
*/
String TEMPLATE_DEL_URL = "https://api.weixin.qq.com/cgi-bin/wxopen/template/del";
/**
* <pre>
* 获取小程序模板库标题列表
*
* 详情请见: <a href="https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1500465446_j4CgR&token=&lang=zh_CN">获取小程序模板库标题列表</a>
* 接口url格式: https://api.weixin.qq.com/cgi-bin/wxopen/template/library/list?access_token=ACCESS_TOKEN
* </pre>
*/
WxMaTemplateLibraryListResult findTemplateLibraryList(int offset, int count) throws WxErrorException;
/**
* <pre>
* 获取模板库某个模板标题下关键词库
*
* 详情请见: <a href="https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1500465446_j4CgR&token=&lang=zh_CN">获取小程序模板库标题列表</a>
* 接口url格式: https://api.weixin.qq.com/cgi-bin/wxopen/template/library/get?access_token=ACCESS_TOKEN
* </pre>
*/
WxMaTemplateLibraryGetResult findTemplateLibraryKeywordList(String id) throws WxErrorException;
/**
* <pre>
* 组合模板并添加至帐号下的个人模板库
*
* 详情请见: <a href="https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1500465446_j4CgR&token=&lang=zh_CN">获取小程序模板库标题列表</a>
* 接口url格式: https://api.weixin.qq.com/cgi-bin/wxopen/template/add?access_token=ACCESS_TOKEN
* </pre>
*/
WxMaTemplateAddResult addTemplate(String id, List<Integer> keywordIdList) throws WxErrorException;
/**
* <pre>
* 获取帐号下已存在的模板列表
*
* 详情请见: <a href="https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1500465446_j4CgR&token=&lang=zh_CN">获取小程序模板库标题列表</a>
* 接口url格式: https://api.weixin.qq.com/cgi-bin/wxopen/template/list?access_token=ACCESS_TOKEN
* </pre>
*/
WxMaTemplateListResult findTemplateList(int offset, int count) throws WxErrorException;
/**
* <pre>
* 删除帐号下的某个模板
*
* 详情请见: <a href="https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1500465446_j4CgR&token=&lang=zh_CN">获取小程序模板库标题列表</a>
* 接口url格式: https://api.weixin.qq.com/cgi-bin/wxopen/template/list?access_token=ACCESS_TOKEN
* </pre>
*/
boolean delTemplate(String templateId) throws WxErrorException;
}

View File

@ -40,13 +40,11 @@ import java.util.concurrent.locks.Lock;
@Slf4j
public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestHttp<H, P> {
private Map<String, WxMaConfig> configMap;
private WxMaConfig wxMaConfig;
private final WxMaMsgService kefuService = new WxMaMsgServiceImpl(this);
private final WxMaMediaService materialService = new WxMaMediaServiceImpl(this);
private final WxMaUserService userService = new WxMaUserServiceImpl(this);
private final WxMaQrcodeService qrCodeService = new WxMaQrcodeServiceImpl(this);
private final WxMaTemplateService templateService = new WxMaTemplateServiceImpl(this);
private final WxMaAnalysisService analysisService = new WxMaAnalysisServiceImpl(this);
private final WxMaCodeService codeService = new WxMaCodeServiceImpl(this);
private final WxMaSettingService settingService = new WxMaSettingServiceImpl(this);
@ -275,9 +273,9 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
/**
* 设置当前的AccessToken
*
* @param resultContent
* @return
* @throws WxErrorException
* @param resultContent 响应内容
* @return access token
* @throws WxErrorException 异常
*/
protected String extractAccessToken(String resultContent) throws WxErrorException {
WxMaConfig config = this.getWxMaConfig();
@ -399,11 +397,6 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
return this.qrCodeService;
}
@Override
public WxMaTemplateService getTemplateService() {
return this.templateService;
}
@Override
public WxMaSubscribeService getSubscribeService() {
return this.subscribeService;

View File

@ -17,8 +17,7 @@ import me.chanjar.weixin.common.util.json.GsonParser;
*/
@AllArgsConstructor
public class WxMaMsgServiceImpl implements WxMaMsgService {
private WxMaService wxMaService;
private final WxMaService wxMaService;
@Override
public boolean sendKefuMsg(WxMaKefuMessage message) throws WxErrorException {
@ -26,15 +25,6 @@ public class WxMaMsgServiceImpl implements WxMaMsgService {
return responseContent != null;
}
@Override
public void sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException {
String responseContent = this.wxMaService.post(TEMPLATE_MSG_SEND_URL, templateMessage.toJson());
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}
}
@Override
public void sendSubscribeMsg(WxMaSubscribeMessage subscribeMessage) throws WxErrorException {
String responseContent = this.wxMaService.post(SUBSCRIBE_MSG_SEND_URL, subscribeMessage.toJson());

View File

@ -1,58 +0,0 @@
package cn.binarywang.wx.miniapp.api.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaTemplateService;
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateAddResult;
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateLibraryGetResult;
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateLibraryListResult;
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateListResult;
import com.google.common.collect.ImmutableMap;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import java.util.List;
import java.util.Map;
/**
* @author Binary
*/
@AllArgsConstructor
public class WxMaTemplateServiceImpl implements WxMaTemplateService {
private WxMaService wxMaService;
@Override
public WxMaTemplateLibraryListResult findTemplateLibraryList(int offset, int count) throws WxErrorException {
Map<String, Integer> params = ImmutableMap.of("offset", offset, "count", count);
String responseText = this.wxMaService.post(TEMPLATE_LIBRARY_LIST_URL, WxGsonBuilder.create().toJson(params));
return WxMaTemplateLibraryListResult.fromJson(responseText);
}
@Override
public WxMaTemplateLibraryGetResult findTemplateLibraryKeywordList(String id) throws WxErrorException {
String responseText = this.wxMaService.post(TEMPLATE_LIBRARY_KEYWORD_URL,
WxGsonBuilder.create().toJson(ImmutableMap.of("id", id)));
return WxMaTemplateLibraryGetResult.fromJson(responseText);
}
@Override
public WxMaTemplateAddResult addTemplate(String id, List<Integer> keywordIdList) throws WxErrorException {
String responseText = this.wxMaService.post(TEMPLATE_ADD_URL,
WxGsonBuilder.create().toJson(ImmutableMap.of("id", id, "keyword_id_list", keywordIdList.toArray())));
return WxMaTemplateAddResult.fromJson(responseText);
}
@Override
public WxMaTemplateListResult findTemplateList(int offset, int count) throws WxErrorException {
Map<String, Integer> params = ImmutableMap.of("offset", offset, "count", count);
String responseText = this.wxMaService.post(TEMPLATE_LIST_URL, WxGsonBuilder.create().toJson(params));
return WxMaTemplateListResult.fromJson(responseText);
}
@Override
public boolean delTemplate(String templateId) throws WxErrorException {
Map<String, String> params = ImmutableMap.of("template_id", templateId);
this.wxMaService.post(TEMPLATE_DEL_URL, WxGsonBuilder.create().toJson(params));
return true;
}
}

View File

@ -1,101 +0,0 @@
package cn.binarywang.wx.miniapp.bean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
/**
* 模板消息.
* 参考 https://developers.weixin.qq.com/miniprogram/dev/api-backend/templateMessage.send.html
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class WxMaTemplateMessage implements Serializable {
private static final long serialVersionUID = 5063374783759519418L;
/**
* 接收者用户 openid.
* <pre>
* 参数touser
* 是否必填
* 描述 接收者用户 openid
* </pre>
*/
private String toUser;
/**
* 所需下发的模板消息的id.
* <pre>
* 参数template_id
* 是否必填
* 描述 所需下发的模板消息的id
* </pre>
*/
private String templateId;
/**
* 点击模板卡片后的跳转页面仅限本小程序内的页面.
* <pre>
* 参数page
* 是否必填
* 描述 点击模板卡片后的跳转页面仅限本小程序内的页面支持带参数,示例index?foo=bar该字段不填则模板无跳转
* </pre>
*/
private String page;
/**
* 表单提交场景下 submit 事件带上的 formId支付场景下为本次支付的 prepay_id.
* <pre>
* 参数form_id
* 是否必填
* 描述 表单提交场景下 submit 事件带上的 formId支付场景下为本次支付的 prepay_id
* </pre>
*/
private String formId;
/**
* 模板内容不填则下发空模板.
* <pre>
* 参数data
* 是否必填
* 描述 模板内容不填则下发空模板
* </pre>
*/
private List<WxMaTemplateData> data;
/**
* 模板需要放大的关键词不填则默认无放大.
* <pre>
* 参数emphasis_keyword
* 是否必填
* 描述 模板需要放大的关键词不填则默认无放大
* </pre>
*/
private String emphasisKeyword;
public WxMaTemplateMessage addData(WxMaTemplateData datum) {
if (this.data == null) {
this.data = new ArrayList<>();
}
this.data.add(datum);
return this;
}
public String toJson() {
return WxMaGsonBuilder.create().toJson(this);
}
}

View File

@ -12,10 +12,25 @@ import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
*/
public interface WxMaConfig {
/**
* Gets access token.
*
* @return the access token
*/
String getAccessToken();
/**
* Gets access token lock.
*
* @return the access token lock
*/
Lock getAccessTokenLock();
/**
* Is access token expired boolean.
*
* @return the boolean
*/
boolean isAccessTokenExpired();
/**
@ -38,10 +53,25 @@ public interface WxMaConfig {
*/
void updateAccessToken(String accessToken, int expiresInSeconds);
/**
* Gets jsapi ticket.
*
* @return the jsapi ticket
*/
String getJsapiTicket();
/**
* Gets jsapi ticket lock.
*
* @return the jsapi ticket lock
*/
Lock getJsapiTicketLock();
/**
* Is jsapi ticket expired boolean.
*
* @return the boolean
*/
boolean isJsapiTicketExpired();
/**
@ -59,11 +89,23 @@ public interface WxMaConfig {
/**
* 卡券api_ticket.
*
* @return the card api ticket
*/
String getCardApiTicket();
/**
* Gets card api ticket lock.
*
* @return the card api ticket lock
*/
Lock getCardApiTicketLock();
/**
* Is card api ticket expired boolean.
*
* @return the boolean
*/
boolean isCardApiTicketExpired();
/**
@ -79,39 +121,101 @@ public interface WxMaConfig {
*/
void updateCardApiTicket(String apiTicket, int expiresInSeconds);
/**
* Gets appid.
*
* @return the appid
*/
String getAppid();
/**
* Gets secret.
*
* @return the secret
*/
String getSecret();
/**
* Gets token.
*
* @return the token
*/
String getToken();
/**
* Gets aes key.
*
* @return the aes key
*/
String getAesKey();
/**
* Gets original id.
*
* @return the original id
*/
String getOriginalId();
/**
* Gets cloud env.
*
* @return the cloud env
*/
String getCloudEnv();
/**
* Gets msg data format.
*
* @return the msg data format
*/
String getMsgDataFormat();
/**
* Gets expires time.
*
* @return the expires time
*/
long getExpiresTime();
/**
* Gets http proxy host.
*
* @return the http proxy host
*/
String getHttpProxyHost();
/**
* Gets http proxy port.
*
* @return the http proxy port
*/
int getHttpProxyPort();
/**
* Gets http proxy username.
*
* @return the http proxy username
*/
String getHttpProxyUsername();
/**
* Gets http proxy password.
*
* @return the http proxy password
*/
String getHttpProxyPassword();
/**
* http client builder
*
* @return ApacheHttpClientBuilder
* @return ApacheHttpClientBuilder apache http client builder
*/
ApacheHttpClientBuilder getApacheHttpClientBuilder();
/**
* 是否自动刷新token
*
* @return the boolean
*/
boolean autoRefreshToken();

View File

@ -1,7 +1,6 @@
package cn.binarywang.wx.miniapp.util.json;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import cn.binarywang.wx.miniapp.bean.WxMaTemplateMessage;
import cn.binarywang.wx.miniapp.bean.WxMaUniformMessage;
import cn.binarywang.wx.miniapp.bean.analysis.WxMaRetainInfo;
import cn.binarywang.wx.miniapp.bean.analysis.WxMaUserPortrait;
@ -19,7 +18,6 @@ public class WxMaGsonBuilder {
static {
INSTANCE.disableHtmlEscaping();
INSTANCE.registerTypeAdapter(WxMaTemplateMessage.class, new WxMaTemplateMessageGsonAdapter());
INSTANCE.registerTypeAdapter(WxMaSubscribeMessage.class, new WxMaSubscribeMessageGsonAdapter());
INSTANCE.registerTypeAdapter(WxMaUniformMessage.class, new WxMaUniformMessageGsonAdapter());
INSTANCE.registerTypeAdapter(WxMaCodeCommitRequest.class, new WxMaCodeCommitRequestGsonAdapter());

View File

@ -1,50 +0,0 @@
package cn.binarywang.wx.miniapp.util.json;
import java.lang.reflect.Type;
import cn.binarywang.wx.miniapp.bean.WxMaTemplateData;
import cn.binarywang.wx.miniapp.bean.WxMaTemplateMessage;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public class WxMaTemplateMessageGsonAdapter implements JsonSerializer<WxMaTemplateMessage> {
@Override
public JsonElement serialize(WxMaTemplateMessage message, Type typeOfSrc, JsonSerializationContext context) {
JsonObject messageJson = new JsonObject();
messageJson.addProperty("touser", message.getToUser());
messageJson.addProperty("template_id", message.getTemplateId());
if (message.getPage() != null) {
messageJson.addProperty("page", message.getPage());
}
if (message.getFormId() != null) {
messageJson.addProperty("form_id", message.getFormId());
}
if (message.getEmphasisKeyword() != null) {
messageJson.addProperty("emphasis_keyword", message.getEmphasisKeyword());
}
JsonObject data = new JsonObject();
messageJson.add("data", data);
if (message.getData() == null) {
return messageJson;
}
for (WxMaTemplateData datum : message.getData()) {
JsonObject dataJson = new JsonObject();
dataJson.addProperty("value", datum.getValue());
data.add(datum.getName(), dataJson);
}
return messageJson;
}
}

View File

@ -40,28 +40,6 @@ public class WxMaMsgServiceImplTest {
this.wxService.getMsgService().sendKefuMsg(message);
}
@Test(invocationCount = 5, threadPoolSize = 3)
public void testSendTemplateMsg() throws WxErrorException {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
TestConfig config = (TestConfig) this.wxService.getWxMaConfig();
WxMaTemplateMessage templateMessage = WxMaTemplateMessage.builder()
.toUser(config.getOpenid())
.formId("FORMID")
.page("index")
.data(Lists.newArrayList(
new WxMaTemplateData("keyword1", "339208499"),
new WxMaTemplateData("keyword2", dateFormat.format(new Date())),
new WxMaTemplateData("keyword3", "粤海喜来登酒店"),
new WxMaTemplateData("keyword4", "广州市天河区天河路208号")))
.templateId(config.getTemplateId())
.emphasisKeyword("keyword1.DATA")
.build();
//templateMessage.addData( new WxMaTemplateData("keyword1", "339208499", "#173177"));
this.wxService.getMsgService().sendTemplateMsg(templateMessage);
}
@Test
public void testSendSubscribeMsg() throws WxErrorException {
TestConfig config = (TestConfig) this.wxService.getWxMaConfig();

View File

@ -1,32 +0,0 @@
package cn.binarywang.wx.miniapp.bean;
import org.testng.annotations.*;
import com.google.common.collect.Lists;
import static org.testng.AssertJUnit.*;
/**
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public class WxMaTemplateMessageTest {
@Test
public void testToJson() throws Exception {
WxMaTemplateMessage tm = WxMaTemplateMessage.builder()
.toUser("OPENID")
//.color("aaaaa")
.formId("FORMID")
.page("index")
.data(Lists.newArrayList(
new WxMaTemplateData("keyword1", "339208499", "#173177"),
new WxMaTemplateData("keyword2", "2015年01月05日12:30", "#173177"),
new WxMaTemplateData("keyword3", "粤海喜来登酒店", "#173177"),
new WxMaTemplateData("keyword4", "广州市天河区天河路208号", "#173177")))
.templateId("TEMPLATE_ID")
.emphasisKeyword("keyword1.DATA")
.build();
assertEquals(tm.toJson(), "{\"touser\":\"OPENID\",\"template_id\":\"TEMPLATE_ID\",\"page\":\"index\",\"form_id\":\"FORMID\",\"emphasis_keyword\":\"keyword1.DATA\",\"data\":{\"keyword1\":{\"value\":\"339208499\",\"color\":\"#173177\"},\"keyword2\":{\"value\":\"2015年01月05日12:30\",\"color\":\"#173177\"},\"keyword3\":{\"value\":\"粤海喜来登酒店\",\"color\":\"#173177\"},\"keyword4\":{\"value\":\"广州市天河区天河路208号\",\"color\":\"#173177\"}}}");
}
}

View File

@ -4,15 +4,12 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.bean.WxMaKefuMessage;
import cn.binarywang.wx.miniapp.bean.WxMaMessage;
import cn.binarywang.wx.miniapp.bean.WxMaTemplateData;
import cn.binarywang.wx.miniapp.bean.WxMaTemplateMessage;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.constant.WxMaConstants;
import cn.binarywang.wx.miniapp.message.WxMaMessageHandler;
import cn.binarywang.wx.miniapp.message.WxMaMessageRouter;
import cn.binarywang.wx.miniapp.message.WxMaXmlOutMessage;
import cn.binarywang.wx.miniapp.test.TestConfig;
import com.google.common.collect.Lists;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.error.WxErrorException;
@ -97,22 +94,6 @@ public class WxMaDemoServer {
}
};
private static final WxMaMessageHandler templateMsgHandler = new WxMaMessageHandler() {
@Override
public WxMaXmlOutMessage handle(WxMaMessage wxMessage, Map<String, Object> context,
WxMaService service, WxSessionManager sessionManager)
throws WxErrorException {
service.getMsgService().sendTemplateMsg(WxMaTemplateMessage.builder()
.templateId(templateId).data(Lists.newArrayList(
new WxMaTemplateData("keyword1", "339208499", "#173177")))
.toUser(wxMessage.getFromUser())
.formId("自己替换可用的formid")
.build());
return null;
}
};
private static final WxMaMessageHandler customerServiceMessageHandler = new WxMaMessageHandler() {
@Override
public WxMaXmlOutMessage handle(WxMaMessage message, Map<String, Object> context, WxMaService service, WxSessionManager sessionManager) {
@ -157,7 +138,6 @@ public class WxMaDemoServer {
router = new WxMaMessageRouter(service);
router.rule().handler(logHandler).next()
.rule().async(false).content("模板").handler(templateMsgHandler).end()
.rule().async(false).content("文本").handler(textHandler).end()
.rule().async(false).content("图片").handler(picHandler).end()
.rule().async(false).content("二维码").handler(qrcodeHandler).end()

View File

@ -163,70 +163,6 @@ public interface WxMpService extends WxService {
*/
String buildQrConnectUrl(String redirectUri, String scope, String state);
/**
* <pre>
* 构造oauth2授权的url连接.
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=网页授权获取用户基本信息
* </pre>
*
* @param redirectURI 用户授权完成后的重定向链接无需urlencode, 方法内会进行encode
* @param scope scope
* @param state state
* @return url string
* @deprecated use oauth2Service.buildAuthorizationUrl() instead
*/
@Deprecated
String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state);
/**
* <pre>
* 用code换取oauth2的access token.
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=网页授权获取用户基本信息
* </pre>
*
* @param code code
* @return token对象
* @throws WxErrorException .
*/
@Deprecated
WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException;
/**
* <pre>
* 刷新oauth2的access token.
* </pre>
*
* @param refreshToken 刷新token
* @return 新的token对象
* @throws WxErrorException .
*/
@Deprecated
WxMpOAuth2AccessToken oauth2refreshAccessToken(String refreshToken) throws WxErrorException;
/**
* <pre>
* 用oauth2获取用户信息, 当前面引导授权时的scope是snsapi_userinfo的时候才可以.
* </pre>
*
* @param oAuth2AccessToken token对象
* @param lang zh_CN, zh_TW, en
* @return 用户对象
* @throws WxErrorException .
*/
@Deprecated
WxMpUser oauth2getUserInfo(WxMpOAuth2AccessToken oAuth2AccessToken, String lang) throws WxErrorException;
/**
* <pre>
* 验证oauth2的access token是否有效.
* </pre>
*
* @param oAuth2AccessToken token对象
* @return 是否有效
*/
@Deprecated
boolean oauth2validateAccessToken(WxMpOAuth2AccessToken oAuth2AccessToken);
/**
* <pre>
* 获取微信服务器IP地址

View File

@ -243,26 +243,6 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
}
}
@Override
public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException {
return this.oAuth2Service.getAccessToken(code);
}
@Override
public WxMpOAuth2AccessToken oauth2refreshAccessToken(String refreshToken) throws WxErrorException {
return this.oAuth2Service.refreshAccessToken(refreshToken);
}
@Override
public WxMpUser oauth2getUserInfo(WxMpOAuth2AccessToken token, String lang) throws WxErrorException {
return this.oAuth2Service.getUserInfo(token,lang);
}
@Override
public boolean oauth2validateAccessToken(WxMpOAuth2AccessToken token) {
return this.oAuth2Service.validateAccessToken(token);
}
@Override
public String[] getCallbackIP() throws WxErrorException {
String responseContent = this.get(GET_CALLBACK_IP_URL, null);

View File

@ -413,30 +413,6 @@ public interface WxPayService {
*/
WxScanPayNotifyResult parseScanPayNotifyResult(String xmlData) throws WxPayException;
/**
* @deprecated 建议使用 {@link RedpackService#sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest)}
*/
@Deprecated
WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request) throws WxPayException;
/**
* @deprecated 建议使用 {@link RedpackService#sendRedpack(WxPaySendRedpackRequest)}
*/
@Deprecated
WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException;
/**
* @deprecated 建议使用 {@link RedpackService#queryRedpack(String)}
*/
@Deprecated
WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException;
/**
* @deprecated 建议使用 {@link RedpackService#queryRedpack(WxPayRedpackQueryRequest)}
*/
@Deprecated
WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException;
/**
* <pre>
* 扫码支付模式一生成二维码的方法

View File

@ -250,27 +250,6 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
}
@Override
public WxPaySendMiniProgramRedpackResult sendMiniProgramRedpack(WxPaySendMiniProgramRedpackRequest request)
throws WxPayException {
return this.redpackService.sendMiniProgramRedpack(request);
}
@Override
public WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException {
return this.redpackService.sendRedpack(request);
}
@Override
public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException {
return this.redpackService.queryRedpack(mchBillNo);
}
@Override
public WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException {
return this.redpackService.queryRedpack(request);
}
@Override
public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxPayException {
WxPayOrderQueryRequest request = new WxPayOrderQueryRequest();