mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-12-21 11:00:00 +08:00
合并开发分支,发布正式版
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.enums.AiLangType;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信AI开放接口(语音识别,微信翻译).
|
||||
@@ -15,24 +15,15 @@ import java.io.File;
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public interface WxMpAiOpenService {
|
||||
String TRANSLATE_URL = "http://api.weixin.qq.com/cgi-bin/media/voice/translatecontent?lfrom=%s<o=%s";
|
||||
String VOICE_UPLOAD_URL = "http://api.weixin.qq.com/cgi-bin/media/voice/addvoicetorecofortext?format=%s&voice_id=%s&lang=%s";
|
||||
String VOICE_QUERY_RESULT_URL = "http://api.weixin.qq.com/cgi-bin/media/voice/queryrecoresultfortext";
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 提交语音.
|
||||
* 接口调用请求说明
|
||||
*
|
||||
* http请求方式: POST
|
||||
* http://api.weixin.qq.com/cgi-bin/media/voice/addvoicetorecofortext?access_token=ACCESS_TOKEN&format=&voice_id=xxxxxx&lang=zh_CN
|
||||
* 参数说明
|
||||
*
|
||||
* 参数 是否必须 说明
|
||||
* access_token 是 接口调用凭证
|
||||
* format 是 文件格式 (只支持mp3,16k,单声道,最大1M)
|
||||
* voice_id 是 语音唯一标识
|
||||
* lang 否 语言,zh_CN 或 en_US,默认中文
|
||||
* 语音内容放body里或者上传文件的形式
|
||||
* </pre>
|
||||
*
|
||||
* @param lang 语言,zh_CN 或 en_US,默认中文
|
||||
@@ -46,16 +37,9 @@ public interface WxMpAiOpenService {
|
||||
* 获取语音识别结果.
|
||||
* 接口调用请求说明
|
||||
*
|
||||
* http请求方式: POST
|
||||
* http://api.weixin.qq.com/cgi-bin/media/voice/queryrecoresultfortext?access_token=ACCESS_TOKEN&voice_id=xxxxxx&lang=zh_CN
|
||||
* 请注意,添加完文件之后10s内调用这个接口
|
||||
*
|
||||
* 参数说明
|
||||
*
|
||||
* 参数 是否必须 说明
|
||||
* access_token 是 接口调用凭证
|
||||
* voice_id 是 语音唯一标识
|
||||
* lang 否 语言,zh_CN 或 en_US,默认中文
|
||||
* </pre>
|
||||
*
|
||||
* @param lang 语言,zh_CN 或 en_US,默认中文
|
||||
@@ -80,18 +64,12 @@ public interface WxMpAiOpenService {
|
||||
*
|
||||
* http请求方式: POST
|
||||
* http://api.weixin.qq.com/cgi-bin/media/voice/translatecontent?access_token=ACCESS_TOKEN&lfrom=xxx<o=xxx
|
||||
* 参数说明
|
||||
*
|
||||
* 参数 是否必须 说明
|
||||
* access_token 是 接口调用凭证
|
||||
* lfrom 是 源语言,zh_CN 或 en_US
|
||||
* lto 是 目标语言,zh_CN 或 en_US
|
||||
* 源内容放body里或者上传文件的形式(utf8格式,最大600Byte)
|
||||
* </pre>
|
||||
*
|
||||
* @param langFrom 源语言,zh_CN 或 en_US
|
||||
* @param langTo 目标语言,zh_CN 或 en_US
|
||||
* @param content 要翻译的文本内容
|
||||
* @param langTo 目标语言,zh_CN 或 en_US
|
||||
* @param content 要翻译的文本内容
|
||||
*/
|
||||
String translate(AiLangType langFrom, AiLangType langTo, String content) throws WxErrorException;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,8 @@ package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.bean.WxCardApiSignature;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.card.WxMpCardLandingPageCreateRequest;
|
||||
import me.chanjar.weixin.mp.bean.card.WxMpCardLandingPageCreateResult;
|
||||
import me.chanjar.weixin.mp.bean.card.WxMpCardQrcodeCreateResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpCardResult;
|
||||
import me.chanjar.weixin.mp.bean.card.*;
|
||||
import me.chanjar.weixin.mp.bean.card.WxMpCardResult;
|
||||
|
||||
/**
|
||||
* 卡券相关接口
|
||||
@@ -14,6 +12,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpCardResult;
|
||||
* @author yuanqixun 2018-08-29
|
||||
*/
|
||||
public interface WxMpCardService {
|
||||
String CARD_CREATE = "https://api.weixin.qq.com/card/create";
|
||||
String CARD_GET = "https://api.weixin.qq.com/card/get";
|
||||
String CARD_GET_TICKET = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=wx_card";
|
||||
String CARD_CODE_DECRYPT = "https://api.weixin.qq.com/card/code/decrypt";
|
||||
@@ -28,6 +27,11 @@ public interface WxMpCardService {
|
||||
*/
|
||||
String CARD_CODE_UNAVAILABLE = "https://api.weixin.qq.com/card/code/unavailable";
|
||||
|
||||
/**
|
||||
* 卡券删除
|
||||
*/
|
||||
String CARD_DELETE = "https://api.weixin.qq.com/card/delete";
|
||||
|
||||
/**
|
||||
* 得到WxMpService
|
||||
*/
|
||||
@@ -81,8 +85,8 @@ public interface WxMpCardService {
|
||||
String decryptCardCode(String encryptCode) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 卡券Code查询
|
||||
*
|
||||
* 卡券Code查询.
|
||||
* 文档地址: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1451025272&anchor=1
|
||||
* @param cardId 卡券ID代表一类卡券
|
||||
* @param code 单张卡券的唯一标准
|
||||
* @param checkConsume 是否校验code核销状态,填入true和false时的code异常状态返回数据不同
|
||||
@@ -142,6 +146,14 @@ public interface WxMpCardService {
|
||||
*/
|
||||
String addTestWhiteList(String openid) throws WxErrorException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cardCreateMessage
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
WxMpCardCreateResult createCard(WxMpCardCreateMessage cardCreateMessage) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 创建卡券二维码
|
||||
*
|
||||
@@ -182,4 +194,12 @@ public interface WxMpCardService {
|
||||
*/
|
||||
String unavailableCardCode(String cardId, String code, String reason) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 删除卡券接口
|
||||
* @param cardId
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
WxMpCardDeleteResult deleteCard(String cardId) throws WxErrorException;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.marketing.WxMpAdLeadFilter;
|
||||
import me.chanjar.weixin.mp.bean.marketing.WxMpAdLeadResult;
|
||||
import me.chanjar.weixin.mp.bean.marketing.WxMpUserAction;
|
||||
import me.chanjar.weixin.mp.bean.marketing.WxMpUserActionSet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信营销接口
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
public interface WxMpMarketingService {
|
||||
String API_URL_PREFIX = "https://api.weixin.qq.com/marketing/";
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 创建数据源
|
||||
* 接口调用请求说明
|
||||
* https://wximg.qq.com/wxp/pdftool/get.html?id=rkalQXDBM&pa=39
|
||||
* </pre>
|
||||
*
|
||||
* @param type 用户行为源类型
|
||||
* @param name 用户行为源名称 必填
|
||||
* @param description 用户行为源描述,字段长度最小 1 字节,长度最大 128 字节
|
||||
*/
|
||||
long addUserActionSets(String type, String name, String description) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取数据源信息
|
||||
* </pre>
|
||||
*
|
||||
* @param userActionSetId 数据源唯一ID
|
||||
*/
|
||||
List<WxMpUserActionSet> getUserActionSets(Long userActionSetId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 回传数据
|
||||
* 接口调用请求说明
|
||||
* https://wximg.qq.com/wxp/pdftool/get.html?id=rkalQXDBM&pa=39
|
||||
*
|
||||
* @param actions 用户行为源类型
|
||||
*/
|
||||
void addUserAction(List<WxMpUserAction> actions) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 获取朋友圈销售线索数据接口
|
||||
* 接口调用请求说明
|
||||
*
|
||||
* http请求方式: POST
|
||||
* http://api.weixin.qq.com/cgi-bin/media/voice/translatecontent?access_token=ACCESS_TOKEN&lfrom=xxx<o=xxx
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @param beginDate 开始日期
|
||||
* @param endDate 结束日期
|
||||
* @param filtering 过滤条件
|
||||
* @param page 页码,获取指定页数据
|
||||
* @param page_size 一页获取的数据条数(1-100)
|
||||
*/
|
||||
WxMpAdLeadResult getAdLeads(Date beginDate, Date endDate, List<WxMpAdLeadFilter> filtering, Integer page, Integer page_size) throws WxErrorException, IOException;
|
||||
}
|
||||
@@ -6,12 +6,7 @@ import me.chanjar.weixin.mp.bean.card.MemberCardActivateUserFormRequest;
|
||||
import me.chanjar.weixin.mp.bean.card.MemberCardActivateUserFormResult;
|
||||
import me.chanjar.weixin.mp.bean.card.MemberCardUpdateRequest;
|
||||
import me.chanjar.weixin.mp.bean.card.WxMpCardCreateResult;
|
||||
import me.chanjar.weixin.mp.bean.membercard.ActivatePluginParam;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardActivatedMessage;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardCreateMessage;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUpdateMessage;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUpdateResult;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUserInfoResult;
|
||||
import me.chanjar.weixin.mp.bean.membercard.*;
|
||||
|
||||
/**
|
||||
* 会员卡相关接口.
|
||||
@@ -22,14 +17,14 @@ import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUserInfoResult;
|
||||
* @date 2018-08-30
|
||||
*/
|
||||
public interface WxMpMemberCardService {
|
||||
String MEMBER_CARD_CREAET = "https://api.weixin.qq.com/card/create";
|
||||
String MEMBER_CARD_CREATE = "https://api.weixin.qq.com/card/create";
|
||||
String MEMBER_CARD_ACTIVATE = "https://api.weixin.qq.com/card/membercard/activate";
|
||||
String MEMBER_CARD_USER_INFO_GET = "https://api.weixin.qq.com/card/membercard/userinfo/get";
|
||||
String MEMBER_CARD_UPDATE_USER = "https://api.weixin.qq.com/card/membercard/updateuser";
|
||||
/**
|
||||
* 会员卡激活之微信开卡接口(wx_activate=true情况调用).
|
||||
*/
|
||||
String MEMBER_CARD_ACTIVATEUSERFORM = "https://api.weixin.qq.com/card/membercard/activateuserform/set";
|
||||
String MEMBER_CARD_ACTIVATE_USER_FORM = "https://api.weixin.qq.com/card/membercard/activateuserform/set";
|
||||
|
||||
/**
|
||||
* 获取会员卡开卡插件参数.
|
||||
@@ -41,19 +36,34 @@ public interface WxMpMemberCardService {
|
||||
*/
|
||||
String MEMBER_CARD_UPDATE = "https://api.weixin.qq.com/card/update";
|
||||
|
||||
/**
|
||||
* 跳转型会员卡开卡字段.
|
||||
* 获取用户提交资料(wx_activate=true情况调用),开发者根据activate_ticket获取到用户填写的信息
|
||||
*/
|
||||
String MEMBER_CARD_ACTIVATE_TEMP_INFO = "https://api.weixin.qq.com/card/membercard/activatetempinfo/get";
|
||||
|
||||
/**
|
||||
* 得到WxMpService.
|
||||
*
|
||||
* @return WxMpService
|
||||
*/
|
||||
WxMpService getWxMpService();
|
||||
|
||||
/**
|
||||
* 会员卡创建接口.
|
||||
*
|
||||
* @param createJson 会员卡json字符串
|
||||
* @return 返回json字符串
|
||||
* @throws WxErrorException 接口调用失败抛出的异常
|
||||
*/
|
||||
WxMpCardCreateResult createMemberCard(String createJson) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 会员卡创建接口.
|
||||
* 会员卡创建接口
|
||||
*
|
||||
* @param createMessageMessage 会员卡创建对象
|
||||
* @return 会员卡信息的结果对象
|
||||
* @throws WxErrorException 接口调用失败抛出的异常
|
||||
*/
|
||||
WxMpCardCreateResult createMemberCard(WxMpMemberCardCreateMessage createMessageMessage) throws WxErrorException;
|
||||
|
||||
@@ -61,7 +71,7 @@ public interface WxMpMemberCardService {
|
||||
* 会员卡激活接口.
|
||||
*
|
||||
* @param activatedMessage 激活所需参数
|
||||
* @return 返回json字符串
|
||||
* @return 会员卡激活后的json字符串
|
||||
* @throws WxErrorException 接口调用失败抛出的异常
|
||||
*/
|
||||
String activateMemberCard(WxMpMemberCardActivatedMessage activatedMessage) throws WxErrorException;
|
||||
@@ -91,16 +101,40 @@ public interface WxMpMemberCardService {
|
||||
|
||||
/**
|
||||
* 设置会员卡激活的字段(会员卡设置:wx_activate=true 时需要).
|
||||
*
|
||||
* @param userFormRequest 会员卡激活字段对象
|
||||
* @return 会员卡激活后结果对象
|
||||
* @throws WxErrorException 接口调用失败抛出的异常
|
||||
*/
|
||||
MemberCardActivateUserFormResult setActivateUserForm(MemberCardActivateUserFormRequest userFormRequest) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取会员卡开卡插件参数(跳转型开卡组件需要参数).
|
||||
*
|
||||
* @param cardId 会员卡的CardId,微信分配
|
||||
* @param outStr 会员卡设置商户的渠道
|
||||
* @return 会员卡开卡插件参数结果对象
|
||||
* @throws WxErrorException 接口调用失败抛出的异常
|
||||
*/
|
||||
ActivatePluginParam getActivatePluginParam(String cardId, String outStr) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 更新会员卡信息.
|
||||
*
|
||||
* @param memberCardUpdateRequest 会员卡更新对象
|
||||
* @return 会员卡更新后结果对象
|
||||
* @throws WxErrorException 接口调用失败抛出的异常
|
||||
*/
|
||||
CardUpdateResult updateCardInfo(MemberCardUpdateRequest memberCardUpdateRequest) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 解析跳转型开卡字段用户提交的资料.
|
||||
* 开发者在URL上截取ticket后须先进行urldecode
|
||||
*
|
||||
* @param activateTicket 用户提交的资料
|
||||
* @return 开卡字段的会员信息对象
|
||||
* @throws WxErrorException 接口调用失败抛出的异常
|
||||
*/
|
||||
WxMpMemberCardActivateTempInfoResult getActivateTempInfo(String activateTicket) throws WxErrorException;
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.RequestHttp;
|
||||
import me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl;
|
||||
import me.chanjar.weixin.mp.bean.WxMpSemanticQuery;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpCurrentAutoReplyInfo;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
|
||||
@@ -12,6 +13,8 @@ import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
import me.chanjar.weixin.mp.enums.TicketType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 微信公众号API的Service.
|
||||
*
|
||||
@@ -302,10 +305,50 @@ public interface WxMpService {
|
||||
WxMpConfigStorage getWxMpConfigStorage();
|
||||
|
||||
/**
|
||||
* 注入 {@link WxMpConfigStorage} 的实现.
|
||||
* 设置 {@link WxMpConfigStorage} 的实现. 兼容老版本
|
||||
*/
|
||||
void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider);
|
||||
|
||||
/**
|
||||
* {@link Map<String, WxMpConfigStorage>} 加入新的 {@link WxMpConfigStorage},适用于动态添加新的微信公众号配置
|
||||
* @param configStorage 新的微信配置
|
||||
*/
|
||||
void addConfigStorage(String mpId, WxMpConfigStorage configStorage);
|
||||
|
||||
/**
|
||||
* 从{@link Map<String, WxMpConfigStorage>} 移除 {@link String mpId} 所对应的 {@link WxMpConfigStorage},适用于动态移除微信公众号配置
|
||||
* @param mpId 对应公众号的标识
|
||||
*/
|
||||
void removeConfigStorage(String mpId);
|
||||
|
||||
/**
|
||||
* 注入多个 {@link WxMpConfigStorage} 的实现. 并为每个 {@link WxMpConfigStorage} 赋予不同的 {@link String mpId} 值
|
||||
* 随机采用一个{@link String mpId}进行Http初始化操作
|
||||
* @param configStorages WxMpConfigStorage map
|
||||
*/
|
||||
void setMultiConfigStorages(Map<String, WxMpConfigStorage> configStorages);
|
||||
|
||||
/**
|
||||
* 注入多个 {@link WxMpConfigStorage} 的实现. 并为每个 {@link WxMpConfigStorage} 赋予不同的 {@link String label} 值
|
||||
* @param configStorages WxMpConfigStorage map
|
||||
* @param defaultMpId 设置一个{@link WxMpConfigStorage} 所对应的{@link String mpId}进行Http初始化
|
||||
*/
|
||||
void setMultiConfigStorages(Map<String, WxMpConfigStorage> configStorages, String defaultMpId);
|
||||
|
||||
/**
|
||||
* 进行相应的公众号切换
|
||||
* @param mpId 公众号标识
|
||||
* @return 切换是否成功
|
||||
*/
|
||||
boolean switchover(String mpId);
|
||||
|
||||
/**
|
||||
* 进行相应的公众号切换
|
||||
* @param mpId 公众号标识
|
||||
* @return 切换成功,则返回当前对象,方便链式调用,否则抛出异常
|
||||
*/
|
||||
WxMpService switchoverTo(String mpId);
|
||||
|
||||
/**
|
||||
* 返回客服接口方法实现类,以方便调用其各个接口.
|
||||
*
|
||||
@@ -411,6 +454,13 @@ public interface WxMpService {
|
||||
*/
|
||||
WxMpMemberCardService getMemberCardService();
|
||||
|
||||
/**
|
||||
* 返回营销相关接口方法的实现类对象,以方便调用其各个接口.
|
||||
*
|
||||
* @return WxMpMarketingService
|
||||
*/
|
||||
WxMpMarketingService getMarketingService();
|
||||
|
||||
/**
|
||||
* 初始化http请求对象.
|
||||
*/
|
||||
@@ -473,4 +523,6 @@ public interface WxMpService {
|
||||
void setMassMessageService(WxMpMassMessageService massMessageService);
|
||||
|
||||
void setAiOpenService(WxMpAiOpenService aiOpenService);
|
||||
|
||||
void setMarketingService(WxMpMarketingService marketingService);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -19,37 +14,22 @@ import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.common.util.DataUtils;
|
||||
import me.chanjar.weixin.common.util.RandomUtils;
|
||||
import me.chanjar.weixin.common.util.crypto.SHA1;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.RequestHttp;
|
||||
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.URIUtil;
|
||||
import me.chanjar.weixin.mp.api.WxMpAiOpenService;
|
||||
import me.chanjar.weixin.mp.api.WxMpCardService;
|
||||
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
|
||||
import me.chanjar.weixin.mp.api.WxMpDataCubeService;
|
||||
import me.chanjar.weixin.mp.api.WxMpDeviceService;
|
||||
import me.chanjar.weixin.mp.api.WxMpKefuService;
|
||||
import me.chanjar.weixin.mp.api.WxMpMassMessageService;
|
||||
import me.chanjar.weixin.mp.api.WxMpMaterialService;
|
||||
import me.chanjar.weixin.mp.api.WxMpMemberCardService;
|
||||
import me.chanjar.weixin.mp.api.WxMpMenuService;
|
||||
import me.chanjar.weixin.mp.api.WxMpQrcodeService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.WxMpShakeService;
|
||||
import me.chanjar.weixin.mp.api.WxMpStoreService;
|
||||
import me.chanjar.weixin.mp.api.WxMpSubscribeMsgService;
|
||||
import me.chanjar.weixin.mp.api.WxMpTemplateMsgService;
|
||||
import me.chanjar.weixin.mp.api.WxMpUserBlacklistService;
|
||||
import me.chanjar.weixin.mp.api.WxMpUserService;
|
||||
import me.chanjar.weixin.mp.api.WxMpUserTagService;
|
||||
import me.chanjar.weixin.mp.api.WxMpWifiService;
|
||||
import me.chanjar.weixin.common.util.http.*;
|
||||
import me.chanjar.weixin.mp.api.*;
|
||||
import me.chanjar.weixin.mp.bean.WxMpSemanticQuery;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpCurrentAutoReplyInfo;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
import me.chanjar.weixin.mp.enums.TicketType;
|
||||
import me.chanjar.weixin.mp.util.WxMpConfigStorageHolder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
/**
|
||||
* 基础实现类.
|
||||
@@ -62,7 +42,6 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
|
||||
protected final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
protected WxSessionManager sessionManager = new StandardSessionManager();
|
||||
protected WxMpConfigStorage wxMpConfigStorage;
|
||||
private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this);
|
||||
private WxMpMaterialService materialService = new WxMpMaterialServiceImpl(this);
|
||||
private WxMpMenuService menuService = new WxMpMenuServiceImpl(this);
|
||||
@@ -81,11 +60,13 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
|
||||
private WxMpMassMessageService massMessageService = new WxMpMassMessageServiceImpl(this);
|
||||
private WxMpAiOpenService aiOpenService = new WxMpAiOpenServiceImpl(this);
|
||||
private WxMpWifiService wifiService = new WxMpWifiServiceImpl(this);
|
||||
private WxMpMarketingService marketingService = new WxMpMarketingServiceImpl(this);
|
||||
|
||||
private Map<String, WxMpConfigStorage> configStorageMap;
|
||||
|
||||
private int retrySleepMillis = 1000;
|
||||
private int maxRetryTimes = 5;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean checkSignature(String timestamp, String nonce, String signature) {
|
||||
try {
|
||||
@@ -352,15 +333,70 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
|
||||
|
||||
@Override
|
||||
public WxMpConfigStorage getWxMpConfigStorage() {
|
||||
return this.wxMpConfigStorage;
|
||||
if (this.configStorageMap.size() == 1) {
|
||||
// 只有一个公众号,直接返回其配置即可
|
||||
return this.configStorageMap.values().iterator().next();
|
||||
}
|
||||
|
||||
return this.configStorageMap.get(WxMpConfigStorageHolder.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider) {
|
||||
this.wxMpConfigStorage = wxConfigProvider;
|
||||
final String defaultMpId = WxMpConfigStorageHolder.get();
|
||||
this.setMultiConfigStorages(ImmutableMap.of(defaultMpId, wxConfigProvider), defaultMpId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMultiConfigStorages(Map<String, WxMpConfigStorage> configStorages) {
|
||||
this.setMultiConfigStorages(configStorages, configStorages.keySet().iterator().next());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMultiConfigStorages(Map<String, WxMpConfigStorage> configStorages, String defaultMpId) {
|
||||
this.configStorageMap = Maps.newHashMap(configStorages);
|
||||
WxMpConfigStorageHolder.set(defaultMpId);
|
||||
this.initHttp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addConfigStorage(String mpId, WxMpConfigStorage configStorages) {
|
||||
synchronized (this) {
|
||||
if (this.configStorageMap.containsKey(mpId)) {
|
||||
throw new RuntimeException("该公众号标识已存在,请更换其他标识!");
|
||||
}
|
||||
this.configStorageMap.put(mpId, configStorages);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeConfigStorage(String mpId) {
|
||||
synchronized (this) {
|
||||
this.configStorageMap.remove(mpId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpService switchoverTo(String mpId) {
|
||||
if (this.configStorageMap.containsKey(mpId)) {
|
||||
WxMpConfigStorageHolder.set(mpId);
|
||||
return this;
|
||||
}
|
||||
|
||||
throw new RuntimeException(String.format("无法找到对应【%s】的公众号配置信息,请核实!", mpId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean switchover(String mpId) {
|
||||
if (this.configStorageMap.containsKey(mpId)) {
|
||||
WxMpConfigStorageHolder.set(mpId);
|
||||
return true;
|
||||
}
|
||||
|
||||
log.error("无法找到对应【{}】的公众号配置信息,请核实!", mpId);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRetrySleepMillis(int retrySleepMillis) {
|
||||
this.retrySleepMillis = retrySleepMillis;
|
||||
@@ -545,4 +581,14 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
|
||||
public WxMpWifiService getWifiService() {
|
||||
return this.wifiService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpMarketingService getMarketingService() {
|
||||
return this.marketingService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMarketingService(WxMpMarketingService marketingService) {
|
||||
this.marketingService = marketingService;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import java.io.File;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import me.chanjar.weixin.common.WxType;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.enums.AiLangType;
|
||||
import me.chanjar.weixin.mp.api.WxMpAiOpenService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.enums.AiLangType;
|
||||
import me.chanjar.weixin.mp.util.requestexecuter.voice.VoiceUploadRequestExecutor;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by BinaryWang on 2018/6/9.
|
||||
@@ -20,9 +19,7 @@ import java.io.File;
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public class WxMpAiOpenServiceImpl implements WxMpAiOpenService {
|
||||
|
||||
private static final JsonParser JSON_PARSER = new JsonParser();
|
||||
public static final String TRANSLATE_URL = "http://api.weixin.qq.com/cgi-bin/media/voice/translatecontent?lfrom=%s<o=%s";
|
||||
private WxMpService wxMpService;
|
||||
|
||||
public WxMpAiOpenServiceImpl(WxMpService wxMpService) {
|
||||
@@ -48,14 +45,14 @@ public class WxMpAiOpenServiceImpl implements WxMpAiOpenService {
|
||||
|
||||
@Override
|
||||
public String translate(AiLangType langFrom, AiLangType langTo, String content) throws WxErrorException {
|
||||
final String responseContent = this.wxMpService.post(String.format(TRANSLATE_URL, langFrom.getCode(), langTo.getCode()),
|
||||
content);
|
||||
final JsonObject jsonObject = new JsonParser().parse(responseContent).getAsJsonObject();
|
||||
if (jsonObject.get("errcode") == null || jsonObject.get("errcode").getAsInt() == 0) {
|
||||
return jsonObject.get("to_content").getAsString();
|
||||
String response = this.wxMpService.post(String.format(TRANSLATE_URL, langFrom.getCode(), langTo.getCode()), content);
|
||||
|
||||
WxError error = WxError.fromJson(response, WxType.MP);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
}
|
||||
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
|
||||
return JSON_PARSER.parse(response).getAsJsonObject().get("to_content").getAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,13 +61,13 @@ public class WxMpAiOpenServiceImpl implements WxMpAiOpenService {
|
||||
lang = AiLangType.zh_CN;
|
||||
}
|
||||
|
||||
final String responseContent = this.wxMpService.get(VOICE_QUERY_RESULT_URL,
|
||||
final String response = this.wxMpService.get(VOICE_QUERY_RESULT_URL,
|
||||
String.format("voice_id=%s&lang=%s", voiceId, lang.getCode()));
|
||||
final JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
|
||||
if (jsonObject.get("errcode") == null || jsonObject.get("errcode").getAsInt() == 0) {
|
||||
return jsonObject.get("result").getAsString();
|
||||
WxError error = WxError.fromJson(response, WxType.MP);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
}
|
||||
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MP));
|
||||
return JSON_PARSER.parse(response).getAsJsonObject().get("result").getAsString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import me.chanjar.weixin.common.bean.WxCardApiSignature;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
@@ -22,12 +10,15 @@ import me.chanjar.weixin.common.util.crypto.SHA1;
|
||||
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
|
||||
import me.chanjar.weixin.mp.api.WxMpCardService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.card.WxMpCardLandingPageCreateRequest;
|
||||
import me.chanjar.weixin.mp.bean.card.WxMpCardLandingPageCreateResult;
|
||||
import me.chanjar.weixin.mp.bean.card.WxMpCardQrcodeCreateResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpCardResult;
|
||||
import me.chanjar.weixin.mp.bean.card.*;
|
||||
import me.chanjar.weixin.mp.enums.TicketType;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
/**
|
||||
* Created by Binary Wang on 2016/7/27.
|
||||
@@ -150,14 +141,6 @@ public class WxMpCardServiceImpl implements WxMpCardService {
|
||||
return jsonPrimitive.getAsString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 卡券Code查询.
|
||||
*
|
||||
* @param cardId 卡券ID代表一类卡券
|
||||
* @param code 单张卡券的唯一标准
|
||||
* @param checkConsume 是否校验code核销状态,填入true和false时的code异常状态返回数据不同
|
||||
* @return WxMpCardResult对象
|
||||
*/
|
||||
@Override
|
||||
public WxMpCardResult queryCardCode(String cardId, String code, boolean checkConsume) throws WxErrorException {
|
||||
JsonObject param = new JsonObject();
|
||||
@@ -265,6 +248,13 @@ public class WxMpCardServiceImpl implements WxMpCardService {
|
||||
return respone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpCardCreateResult createCard(WxMpCardCreateMessage cardCreateMessage) throws WxErrorException {
|
||||
|
||||
String response = this.wxMpService.post(CARD_CREATE, GSON.toJson(cardCreateMessage));
|
||||
return WxMpCardCreateResult.fromJson(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建卡券二维码.
|
||||
*/
|
||||
@@ -324,4 +314,15 @@ public class WxMpCardServiceImpl implements WxMpCardService {
|
||||
jsonRequest.addProperty("reason", reason);
|
||||
return this.wxMpService.post(CARD_CODE_UNAVAILABLE, GSON.toJson(jsonRequest));
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpCardDeleteResult deleteCard(String cardId) throws WxErrorException {
|
||||
if (StringUtils.isEmpty(cardId)) {
|
||||
throw new WxErrorException(WxError.builder().errorCode(41012).errorMsg("cardId不能为空").build());
|
||||
}
|
||||
JsonObject param = new JsonObject();
|
||||
param.addProperty("card_id", cardId);
|
||||
String response = this.wxMpService.post(CARD_DELETE, param.toString());
|
||||
return WxMpCardDeleteResult.fromJson(response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpMarketingService;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.marketing.WxMpAdLeadFilter;
|
||||
import me.chanjar.weixin.mp.bean.marketing.WxMpAdLeadResult;
|
||||
import me.chanjar.weixin.mp.bean.marketing.WxMpUserAction;
|
||||
import me.chanjar.weixin.mp.bean.marketing.WxMpUserActionSet;
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
public class WxMpMarketingServiceImpl implements WxMpMarketingService {
|
||||
protected final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
private WxMpService wxMpService;
|
||||
|
||||
public WxMpMarketingServiceImpl(WxMpService wxMpService) {
|
||||
this.wxMpService = wxMpService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long addUserActionSets(String type, String name, String description) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "user_action_sets/add?version=v1.0";
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("type", type);
|
||||
json.addProperty("name", name);
|
||||
json.addProperty("description", description);
|
||||
String responseContent = wxMpService.post(url, json.toString());
|
||||
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
|
||||
return tmpJsonElement.getAsJsonObject().get("data").getAsJsonObject().get("user_action_set_id").getAsLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxMpUserActionSet> getUserActionSets(Long userActionSetId) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "user_action_sets/get";
|
||||
String responseContent = wxMpService.get(url, "version=v1.0&user_action_set_id=" + userActionSetId);
|
||||
return WxMpUserActionSet.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addUserAction(List<WxMpUserAction> actions) throws WxErrorException {
|
||||
String url = API_URL_PREFIX + "user_actions/add?version=v1.0";
|
||||
JsonArray json = new JsonArray();
|
||||
for (WxMpUserAction action : actions) {
|
||||
json.add(action.toJsonObject());
|
||||
}
|
||||
wxMpService.post(url, json.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpAdLeadResult getAdLeads(Date beginDate, Date endDate, List<WxMpAdLeadFilter> filtering, Integer page, Integer page_size) throws WxErrorException, IOException {
|
||||
Date today = new Date();
|
||||
if (beginDate == null) {
|
||||
beginDate = today;
|
||||
}
|
||||
if (endDate == null) {
|
||||
endDate = today;
|
||||
}
|
||||
String url = API_URL_PREFIX + "wechat_ad_leads/get";
|
||||
String params = "version=v1.0";
|
||||
JsonObject dateRange = new JsonObject();
|
||||
dateRange.addProperty("begin_date", DateFormatUtils.format(beginDate, "yyyy-MM-dd"));
|
||||
dateRange.addProperty("end_date", DateFormatUtils.format(endDate, "yyyy-MM-dd"));
|
||||
params += "&date_range=" + URLEncoder.encode(dateRange.toString(), StandardCharsets.UTF_8.name());
|
||||
params += "&page=" + page;
|
||||
params += "&page_size=" + page_size;
|
||||
if (filtering != null) {
|
||||
JsonArray filterJson = new JsonArray();
|
||||
for (WxMpAdLeadFilter filter : filtering) {
|
||||
filterJson.add(filter.toJsonObject());
|
||||
}
|
||||
params += "&filtering=" + URLEncoder.encode(filterJson.toString(), StandardCharsets.UTF_8.name());
|
||||
;
|
||||
}
|
||||
String responseContent = wxMpService.get(url, params);
|
||||
return WxMpAdLeadResult.fromJson(responseContent);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import java.net.URLDecoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.membercard.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
@@ -30,13 +31,6 @@ import me.chanjar.weixin.mp.bean.card.WxMpCardCreateResult;
|
||||
import me.chanjar.weixin.mp.bean.card.enums.BusinessServiceType;
|
||||
import me.chanjar.weixin.mp.bean.card.enums.CardColor;
|
||||
import me.chanjar.weixin.mp.bean.card.enums.DateInfoType;
|
||||
import me.chanjar.weixin.mp.bean.membercard.ActivatePluginParam;
|
||||
import me.chanjar.weixin.mp.bean.membercard.ActivatePluginParamResult;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardActivatedMessage;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardCreateMessage;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUpdateMessage;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUpdateResult;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUserInfoResult;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
/**
|
||||
@@ -51,7 +45,7 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService {
|
||||
|
||||
private static final Gson GSON = WxMpGsonBuilder.create();
|
||||
|
||||
WxMpMemberCardServiceImpl(WxMpService wxMpService) {
|
||||
public WxMpMemberCardServiceImpl(WxMpService wxMpService) {
|
||||
this.wxMpService = wxMpService;
|
||||
}
|
||||
|
||||
@@ -76,7 +70,7 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService {
|
||||
return validResult;
|
||||
}
|
||||
|
||||
String response = this.wxMpService.post(MEMBER_CARD_CREAET, GSON.toJson(createMessageMessage));
|
||||
String response = this.wxMpService.post(MEMBER_CARD_CREATE, GSON.toJson(createMessageMessage));
|
||||
return WxMpCardCreateResult.fromJson(response);
|
||||
}
|
||||
|
||||
@@ -249,7 +243,7 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService {
|
||||
|
||||
@Override
|
||||
public MemberCardActivateUserFormResult setActivateUserForm(MemberCardActivateUserFormRequest userFormRequest) throws WxErrorException {
|
||||
String responseContent = this.getWxMpService().post(MEMBER_CARD_ACTIVATEUSERFORM, GSON.toJson(userFormRequest));
|
||||
String responseContent = this.getWxMpService().post(MEMBER_CARD_ACTIVATE_USER_FORM, GSON.toJson(userFormRequest));
|
||||
return MemberCardActivateUserFormResult.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@@ -284,6 +278,15 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpMemberCardActivateTempInfoResult getActivateTempInfo(String activateTicket) throws WxErrorException {
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("activate_ticket", activateTicket);
|
||||
String response = this.wxMpService.post(MEMBER_CARD_ACTIVATE_TEMP_INFO, GSON.toJson(params));
|
||||
WxMpMemberCardActivateTempInfoResult result = GSON.fromJson(response, WxMpMemberCardActivateTempInfoResult.class);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String truncateUrlPage(String strURL) {
|
||||
String strAllParam = null;
|
||||
String[] arrSplit;
|
||||
|
||||
@@ -63,37 +63,38 @@ public class WxMpServiceHttpClientImpl extends BaseWxMpServiceImpl<CloseableHttp
|
||||
|
||||
@Override
|
||||
public String getAccessToken(boolean forceRefresh) throws WxErrorException {
|
||||
if (!this.getWxMpConfigStorage().isAccessTokenExpired() && !forceRefresh) {
|
||||
return this.getWxMpConfigStorage().getAccessToken();
|
||||
}
|
||||
|
||||
Lock lock = this.getWxMpConfigStorage().getAccessTokenLock();
|
||||
lock.lock();
|
||||
try {
|
||||
lock.lock();
|
||||
if (this.getWxMpConfigStorage().isAccessTokenExpired() || forceRefresh) {
|
||||
String url = String.format(WxMpService.GET_ACCESS_TOKEN_URL,
|
||||
this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret());
|
||||
try {
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
if (this.getRequestHttpProxy() != null) {
|
||||
RequestConfig config = RequestConfig.custom().setProxy(this.getRequestHttpProxy()).build();
|
||||
httpGet.setConfig(config);
|
||||
}
|
||||
try (CloseableHttpResponse response = getRequestHttpClient().execute(httpGet)) {
|
||||
String resultContent = new BasicResponseHandler().handleResponse(response);
|
||||
WxError error = WxError.fromJson(resultContent, WxType.MP);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
}
|
||||
WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);
|
||||
this.getWxMpConfigStorage().updateAccessToken(accessToken.getAccessToken(),
|
||||
accessToken.getExpiresIn());
|
||||
} finally {
|
||||
httpGet.releaseConnection();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
String url = String.format(WxMpService.GET_ACCESS_TOKEN_URL,
|
||||
this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret());
|
||||
try {
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
if (this.getRequestHttpProxy() != null) {
|
||||
RequestConfig config = RequestConfig.custom().setProxy(this.getRequestHttpProxy()).build();
|
||||
httpGet.setConfig(config);
|
||||
}
|
||||
try (CloseableHttpResponse response = getRequestHttpClient().execute(httpGet)) {
|
||||
String resultContent = new BasicResponseHandler().handleResponse(response);
|
||||
WxError error = WxError.fromJson(resultContent, WxType.MP);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
}
|
||||
WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);
|
||||
this.getWxMpConfigStorage().updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn());
|
||||
return this.getWxMpConfigStorage().getAccessToken();
|
||||
} finally {
|
||||
httpGet.releaseConnection();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
return this.getWxMpConfigStorage().getAccessToken();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,36 +48,37 @@ public class WxMpServiceJoddHttpImpl extends BaseWxMpServiceImpl<HttpConnectionP
|
||||
|
||||
@Override
|
||||
public String getAccessToken(boolean forceRefresh) throws WxErrorException {
|
||||
if (!this.getWxMpConfigStorage().isAccessTokenExpired() && !forceRefresh) {
|
||||
return this.getWxMpConfigStorage().getAccessToken();
|
||||
}
|
||||
|
||||
Lock lock = this.getWxMpConfigStorage().getAccessTokenLock();
|
||||
lock.lock();
|
||||
try {
|
||||
lock.lock();
|
||||
String url = String.format(WxMpService.GET_ACCESS_TOKEN_URL,
|
||||
this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret());
|
||||
|
||||
if (this.getWxMpConfigStorage().isAccessTokenExpired() || forceRefresh) {
|
||||
String url = String.format(WxMpService.GET_ACCESS_TOKEN_URL,
|
||||
this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret());
|
||||
HttpRequest request = HttpRequest.get(url);
|
||||
|
||||
HttpRequest request = HttpRequest.get(url);
|
||||
if (this.getRequestHttpProxy() != null) {
|
||||
SocketHttpConnectionProvider provider = new SocketHttpConnectionProvider();
|
||||
provider.useProxy(getRequestHttpProxy());
|
||||
|
||||
if (this.getRequestHttpProxy() != null) {
|
||||
SocketHttpConnectionProvider provider = new SocketHttpConnectionProvider();
|
||||
provider.useProxy(getRequestHttpProxy());
|
||||
|
||||
request.withConnectionProvider(provider);
|
||||
}
|
||||
HttpResponse response = request.send();
|
||||
String resultContent = response.bodyText();
|
||||
WxError error = WxError.fromJson(resultContent, WxType.MP);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
}
|
||||
WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);
|
||||
this.getWxMpConfigStorage().updateAccessToken(accessToken.getAccessToken(),
|
||||
accessToken.getExpiresIn());
|
||||
request.withConnectionProvider(provider);
|
||||
}
|
||||
HttpResponse response = request.send();
|
||||
String resultContent = response.bodyText();
|
||||
WxError error = WxError.fromJson(resultContent, WxType.MP);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
}
|
||||
WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);
|
||||
this.getWxMpConfigStorage().updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn());
|
||||
|
||||
return this.getWxMpConfigStorage().getAccessToken();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
return this.getWxMpConfigStorage().getAccessToken();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.HttpType;
|
||||
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
|
||||
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import okhttp3.*;
|
||||
|
||||
@@ -36,38 +37,37 @@ public class WxMpServiceOkHttpImpl extends BaseWxMpServiceImpl<OkHttpClient, OkH
|
||||
|
||||
@Override
|
||||
public String getAccessToken(boolean forceRefresh) throws WxErrorException {
|
||||
this.log.debug("WxMpServiceOkHttpImpl is running");
|
||||
if (!this.getWxMpConfigStorage().isAccessTokenExpired() && !forceRefresh) {
|
||||
return this.getWxMpConfigStorage().getAccessToken();
|
||||
}
|
||||
|
||||
Lock lock = this.getWxMpConfigStorage().getAccessTokenLock();
|
||||
lock.lock();
|
||||
try {
|
||||
lock.lock();
|
||||
String url = String.format(WxMpService.GET_ACCESS_TOKEN_URL,
|
||||
this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret());
|
||||
|
||||
if (this.getWxMpConfigStorage().isAccessTokenExpired() || forceRefresh) {
|
||||
String url = String.format(WxMpService.GET_ACCESS_TOKEN_URL,
|
||||
this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret());
|
||||
|
||||
Request request = new Request.Builder().url(url).get().build();
|
||||
Response response = getRequestHttpClient().newCall(request).execute();
|
||||
String resultContent = response.body().string();
|
||||
WxError error = WxError.fromJson(resultContent, WxType.MP);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
}
|
||||
WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);
|
||||
this.getWxMpConfigStorage().updateAccessToken(accessToken.getAccessToken(),
|
||||
accessToken.getExpiresIn());
|
||||
Request request = new Request.Builder().url(url).get().build();
|
||||
Response response = getRequestHttpClient().newCall(request).execute();
|
||||
String resultContent = response.body().string();
|
||||
WxError error = WxError.fromJson(resultContent, WxType.MP);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
}
|
||||
WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);
|
||||
this.getWxMpConfigStorage().updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn());
|
||||
|
||||
return this.getWxMpConfigStorage().getAccessToken();
|
||||
} catch (IOException e) {
|
||||
this.log.error(e.getMessage(), e);
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
return this.getWxMpConfigStorage().getAccessToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initHttp() {
|
||||
this.log.debug("WxMpServiceOkHttpImpl initHttp");
|
||||
|
||||
WxMpConfigStorage wxMpConfigStorage = getWxMpConfigStorage();
|
||||
//设置代理
|
||||
if (wxMpConfigStorage.getHttpProxyHost() != null && wxMpConfigStorage.getHttpProxyPort() > 0) {
|
||||
httpProxy = OkHttpProxyInfo.httpProxy(wxMpConfigStorage.getHttpProxyHost(),
|
||||
|
||||
@@ -11,6 +11,7 @@ import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
/**
|
||||
* 微信会员卡高级字段信息.
|
||||
*
|
||||
* @author yuanqixun
|
||||
* date:2018-08-25 00:36
|
||||
*/
|
||||
@@ -18,13 +19,6 @@ import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
public class AdvancedInfo implements Serializable {
|
||||
private static final long serialVersionUID = -8470424140133771841L;
|
||||
|
||||
// public AdvancedInfo(){
|
||||
// useCondition = new UseCondition();
|
||||
// abstractInfo = new Abstract();
|
||||
// textImageList = new ArrayList<>();
|
||||
// timeLimit = new TimeLimit();
|
||||
// }
|
||||
|
||||
/**
|
||||
* 使用门槛(条件).
|
||||
* 若不填写使用条件则在券面拼写 :无最低消费限制,全场通用,不限品类;并在使用说明显示: 可与其他优惠共享
|
||||
@@ -56,7 +50,7 @@ public class AdvancedInfo implements Serializable {
|
||||
* 使用时段限制.
|
||||
*/
|
||||
@SerializedName("time_limit")
|
||||
private TimeLimit timeLimit;
|
||||
private List<TimeLimit> timeLimits;
|
||||
|
||||
/**
|
||||
* 是否可以分享朋友.
|
||||
@@ -66,7 +60,7 @@ public class AdvancedInfo implements Serializable {
|
||||
|
||||
public void addBusinessService(BusinessServiceType businessServiceType) {
|
||||
if (businessServiceType != null) {
|
||||
if (businessServiceList == null){
|
||||
if (businessServiceList == null) {
|
||||
businessServiceList = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package me.chanjar.weixin.mp.bean.card;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @description 卡券返回结果基础类
|
||||
* @author: fanxl
|
||||
* @date: 2019/1/22 0022 10:08
|
||||
*/
|
||||
public class BaseWxMpCardResult implements Serializable {
|
||||
|
||||
/**
|
||||
* 错误码
|
||||
*/
|
||||
private Integer errcode;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
private String errmsg;
|
||||
|
||||
public boolean isSuccess() {
|
||||
return 0 == errcode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package me.chanjar.weixin.mp.bean.card;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* .
|
||||
* @author leeis
|
||||
* @Date 2018/12/29
|
||||
*/
|
||||
@Data
|
||||
public class Card implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3697110761983756780L;
|
||||
|
||||
/**
|
||||
* 基本信息.
|
||||
*/
|
||||
@SerializedName("base_info")
|
||||
private BaseInfo baseInfo;
|
||||
|
||||
/**
|
||||
* 创建优惠券特有的高级字段.
|
||||
*/
|
||||
@SerializedName("advanced_info")
|
||||
private AdvancedInfo advancedInfo;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package me.chanjar.weixin.mp.bean.card;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Author leeis
|
||||
* @Date 2018/12/29
|
||||
*/
|
||||
@Data
|
||||
public class CardCreateRequest implements Serializable {
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package me.chanjar.weixin.mp.bean.card;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* .
|
||||
* @author leeis
|
||||
* @Date 2018/12/29
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public final class CashCard extends Card implements Serializable {
|
||||
private static final long serialVersionUID = 6965491956462769745L;
|
||||
|
||||
/**
|
||||
* 代金券专用,表示起用金额(单位为分),如果无起用门槛则填0
|
||||
*/
|
||||
@SerializedName("least_cost")
|
||||
private int leastCost;
|
||||
|
||||
/**
|
||||
* 代金券专用,表示减免金额。(单位为分)
|
||||
*/
|
||||
@SerializedName("reduce_cost")
|
||||
private int reduceCost;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxMpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
public static CashCard fromJson(String json) {
|
||||
return WxMpGsonBuilder.create().fromJson(json, CashCard.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package me.chanjar.weixin.mp.bean.card;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* .
|
||||
* @author leeis
|
||||
* @Date 2018/12/29
|
||||
*/
|
||||
@Data
|
||||
public class CashCardCreateRequest extends CardCreateRequest implements Serializable {
|
||||
@SerializedName("card_type")
|
||||
private String cardType = "CASH";
|
||||
|
||||
private CashCard cash;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxMpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package me.chanjar.weixin.mp.bean.card;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* .
|
||||
* @author leeis
|
||||
* @Date 2018/12/29
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public final class DiscountCard extends Card implements Serializable {
|
||||
private static final long serialVersionUID = 1704610082472315077L;
|
||||
|
||||
/**
|
||||
* 折扣券专用,表示打折额度(百分比)。填30就是七折。
|
||||
*/
|
||||
private int discount;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxMpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
public static DiscountCard fromJson(String json) {
|
||||
return WxMpGsonBuilder.create().fromJson(json, DiscountCard.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package me.chanjar.weixin.mp.bean.card;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* .
|
||||
* @author leeis
|
||||
* @Date 2018/12/29
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class DiscountCardCreateRequest extends CardCreateRequest implements Serializable {
|
||||
private static final long serialVersionUID = 1190518086576489692L;
|
||||
|
||||
@SerializedName("card_type")
|
||||
private String cardType = "DISCOUNT";
|
||||
|
||||
private DiscountCard discount;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxMpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package me.chanjar.weixin.mp.bean.card;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* .
|
||||
* @author leeis
|
||||
* @Date 2018/12/29
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public final class GeneralCard extends Card implements Serializable {
|
||||
private static final long serialVersionUID = -1577656733441132585L;
|
||||
|
||||
/**
|
||||
* 兑换券专用,填写兑换内容的名称。
|
||||
*/
|
||||
@SerializedName("default_detail")
|
||||
private String defaultDetail;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxMpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
public static GeneralCard fromJson(String json) {
|
||||
return WxMpGsonBuilder.create().fromJson(json, GeneralCard.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package me.chanjar.weixin.mp.bean.card;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* .
|
||||
* @author leeis
|
||||
* @Date 2018/12/29
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class GeneralCardCreateRequest extends CardCreateRequest implements Serializable {
|
||||
private static final long serialVersionUID = 1771355872211267723L;
|
||||
|
||||
@SerializedName("card_type")
|
||||
private String cardType = "GENERAL_COUPON";
|
||||
|
||||
@SerializedName("general_coupon")
|
||||
private GeneralCard generalCoupon;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxMpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package me.chanjar.weixin.mp.bean.card;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* .
|
||||
* @author leeis
|
||||
* @Date 2018/12/29
|
||||
*/
|
||||
@Data
|
||||
public final class GiftCard extends Card implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6168739707511792266L;
|
||||
|
||||
/**
|
||||
* 兑换券专用,填写兑换内容的名称。
|
||||
*/
|
||||
private String gift;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxMpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
public static GiftCard fromJson(String json) {
|
||||
return WxMpGsonBuilder.create().fromJson(json, GiftCard.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package me.chanjar.weixin.mp.bean.card;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* .
|
||||
* @author leeis
|
||||
* @Date 2018/12/29
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class GiftCardCreateRequest extends CardCreateRequest implements Serializable {
|
||||
private static final long serialVersionUID = 1283655452584811858L;
|
||||
|
||||
@SerializedName("card_type")
|
||||
private String cardType = "GIFT";
|
||||
|
||||
private GiftCard gift;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxMpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package me.chanjar.weixin.mp.bean.card;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
/**
|
||||
* .
|
||||
* @author leeis
|
||||
* @Date 2018/12/29
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public final class GrouponCard extends Card implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 3221312561666697005L;
|
||||
|
||||
/**
|
||||
* 团购券专用,团购详情
|
||||
*/
|
||||
@SerializedName("deal_detail")
|
||||
private String dealDetail;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxMpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
public static GrouponCard fromJson(String json) {
|
||||
return WxMpGsonBuilder.create().fromJson(json, GrouponCard.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package me.chanjar.weixin.mp.bean.card;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* .
|
||||
* @author leeis
|
||||
* @Date 2018/12/29
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class GrouponCardCreateRequest extends CardCreateRequest implements Serializable {
|
||||
private static final long serialVersionUID = 7551441058859934512L;
|
||||
|
||||
@SerializedName("card_type")
|
||||
private String cardType = "GROUPON";
|
||||
|
||||
private GrouponCard groupon;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxMpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
}
|
||||
@@ -38,12 +38,6 @@ public final class MemberCard implements Serializable {
|
||||
@SerializedName("auto_activate")
|
||||
private boolean autoActivate;
|
||||
|
||||
/**
|
||||
* 是否一键开卡.
|
||||
*/
|
||||
@SerializedName("wx_activate")
|
||||
private boolean wxActivate;
|
||||
|
||||
/**
|
||||
* 显示积分.
|
||||
*/
|
||||
@@ -145,6 +139,24 @@ public final class MemberCard implements Serializable {
|
||||
@SerializedName("advanced_info")
|
||||
private AdvancedInfo advancedInfo;
|
||||
|
||||
/**
|
||||
* 是否支持一键激活 ,填true或false.
|
||||
*/
|
||||
@SerializedName("wx_activate")
|
||||
private boolean wxActivate;
|
||||
|
||||
/**
|
||||
* 是否支持跳转型一键激活,填true或false.
|
||||
*/
|
||||
@SerializedName("wx_activate_after_submit")
|
||||
private boolean wxActivateAfterSubmit;
|
||||
|
||||
/**
|
||||
* 跳转型一键激活跳转的地址链接,请填写http:// 或者https://开头的链接.
|
||||
*/
|
||||
@SerializedName("wx_activate_after_submit_url")
|
||||
private String wxActivateAfterSubmitUrl;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxMpGsonBuilder.create().toJson(this);
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
package me.chanjar.weixin.mp.bean.card;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 创建会员卡请求对象.
|
||||
*
|
||||
* @author yuanqixun
|
||||
*/
|
||||
@Data
|
||||
public class MemberCardCreateRequest implements Serializable {
|
||||
private static final long serialVersionUID = -1044836608401698097L;
|
||||
|
||||
@SerializedName("card_type")
|
||||
private String cardType = "MEMBER_CARD";
|
||||
|
||||
|
||||
@@ -6,8 +6,15 @@ import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 更新会员卡请求对象.
|
||||
*
|
||||
* @author yuanqixun
|
||||
*/
|
||||
@Data
|
||||
public class MemberCardUpdateRequest implements Serializable {
|
||||
private static final long serialVersionUID = -1025759626161614466L;
|
||||
|
||||
@SerializedName("card_id")
|
||||
private String cardId;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
package me.chanjar.weixin.mp.bean.card;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -24,7 +24,11 @@ public class WxMpCard implements Serializable {
|
||||
|
||||
private String userCardStatus;
|
||||
|
||||
private Boolean canConsume;
|
||||
private String membershipNumber;
|
||||
|
||||
private String code;
|
||||
|
||||
private Integer bonus;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@@ -0,0 +1,23 @@
|
||||
package me.chanjar.weixin.mp.bean.card;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public final class WxMpCardCreateMessage implements Serializable {
|
||||
|
||||
@SerializedName("card")
|
||||
private CardCreateRequest cardCreateRequest;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxMpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
public static WxMpCardCreateMessage fromJson(String json) {
|
||||
return WxMpGsonBuilder.create().fromJson(json, WxMpCardCreateMessage.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package me.chanjar.weixin.mp.bean.card;
|
||||
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
/**
|
||||
* @description 删除卡券结果
|
||||
* @author: fanxl
|
||||
* @date: 2019/1/22 0022 10:24
|
||||
*/
|
||||
public class WxMpCardDeleteResult extends BaseWxMpCardResult {
|
||||
|
||||
public static WxMpCardDeleteResult fromJson(String json) {
|
||||
return WxMpGsonBuilder.create().fromJson(json, WxMpCardDeleteResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxMpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
package me.chanjar.weixin.mp.bean.result;
|
||||
package me.chanjar.weixin.mp.bean.card;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.mp.bean.WxMpCard;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
/**
|
||||
@@ -28,6 +27,12 @@ public class WxMpCardResult implements Serializable {
|
||||
|
||||
private Boolean canConsume;
|
||||
|
||||
private String outStr;
|
||||
|
||||
private String backgroundPicUrl;
|
||||
|
||||
private String unionid;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxMpGsonBuilder.create().toJson(this);
|
||||
@@ -109,6 +109,7 @@ public class WxMpKefuMessage implements Serializable {
|
||||
* {@link WxConsts.KefuMsgType#MPNEWS}
|
||||
* {@link WxConsts.KefuMsgType#WXCARD}
|
||||
* {@link WxConsts.KefuMsgType#MINIPROGRAMPAGE}
|
||||
* {@link WxConsts.KefuMsgType#TASKCARD}
|
||||
* </pre>
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package me.chanjar.weixin.mp.bean.marketing;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
@Data
|
||||
public class WxMpAdLead implements Serializable {
|
||||
private static final long serialVersionUID = -8889087268596440407L;
|
||||
/**
|
||||
* 点击ID
|
||||
*/
|
||||
@SerializedName("click_id")
|
||||
private String click_id;
|
||||
/**
|
||||
* 广告组ID
|
||||
*/
|
||||
@SerializedName("adgroup_id")
|
||||
private Long adgroup_id;
|
||||
/**
|
||||
* 广告组名称
|
||||
*/
|
||||
@SerializedName("adgroup_name")
|
||||
private String adgroup_name;
|
||||
/**
|
||||
* 推广计划ID
|
||||
*/
|
||||
@SerializedName("campaign_id")
|
||||
private Long campaign_id;
|
||||
/**
|
||||
* 推广计划名称
|
||||
*/
|
||||
@SerializedName("campaign_name")
|
||||
private String campaign_name;
|
||||
/**
|
||||
* 代理ID
|
||||
*/
|
||||
@SerializedName("agency_id")
|
||||
private String agency_id;
|
||||
/**
|
||||
* 代理名称
|
||||
*/
|
||||
@SerializedName("agency_name")
|
||||
private String agency_name;
|
||||
/**
|
||||
* 销售线索信息
|
||||
*/
|
||||
@SerializedName("leads_info")
|
||||
private List<WxMpAdLeadInfo> leads_info;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package me.chanjar.weixin.mp.bean.marketing;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
@Data
|
||||
public class WxMpAdLeadFilter implements Serializable {
|
||||
private static final long serialVersionUID = -1469998986497327439L;
|
||||
private String field;
|
||||
private String operator;
|
||||
private List<String> values;
|
||||
|
||||
public JsonObject toJsonObject() {
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("field", field);
|
||||
json.addProperty("operator", operator);
|
||||
if (values != null) {
|
||||
JsonArray vs = new JsonArray();
|
||||
for (String value : values) {
|
||||
vs.add(value);
|
||||
}
|
||||
}
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package me.chanjar.weixin.mp.bean.marketing;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
@Data
|
||||
public class WxMpAdLeadInfo implements Serializable {
|
||||
private static final long serialVersionUID = -6462312242780350479L;
|
||||
@SerializedName("key")
|
||||
private String key;
|
||||
@SerializedName("value")
|
||||
private String value;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package me.chanjar.weixin.mp.bean.marketing;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
@Data
|
||||
public class WxMpAdLeadPageInfo implements Serializable {
|
||||
private static final long serialVersionUID = -896765006445604780L;
|
||||
@SerializedName("page")
|
||||
private Integer page;
|
||||
@SerializedName("page_size")
|
||||
private Integer pageSize;
|
||||
@SerializedName("total_page")
|
||||
private Integer totalPage;
|
||||
@SerializedName("total_number")
|
||||
private Integer totalNumber;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package me.chanjar.weixin.mp.bean.marketing;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
@Data
|
||||
public class WxMpAdLeadResult implements Serializable {
|
||||
private static final long serialVersionUID = -1526796632563660821L;
|
||||
protected static final JsonParser JSON_PARSER = new JsonParser();
|
||||
|
||||
@SerializedName("page_info")
|
||||
private WxMpAdLeadPageInfo pageInfo;
|
||||
@SerializedName("list")
|
||||
private List<WxMpAdLead> adLeads;
|
||||
|
||||
public static WxMpAdLeadResult fromJson(String json) {
|
||||
|
||||
return WxMpGsonBuilder.create().fromJson(
|
||||
JSON_PARSER.parse(json).getAsJsonObject().get("data"),
|
||||
new TypeToken<WxMpAdLeadResult>() {
|
||||
}.getType());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package me.chanjar.weixin.mp.bean.marketing;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class WxMpUserAction implements Serializable {
|
||||
private static final long serialVersionUID = 7042393762652152209L;
|
||||
private Long userActionSetId;
|
||||
private String url;
|
||||
private Boolean actionTime;
|
||||
private String actionType;
|
||||
private String clickId;
|
||||
private Integer actionParam;
|
||||
|
||||
public JsonObject toJsonObject() {
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("user_action_set_id", this.userActionSetId);
|
||||
json.addProperty("url", this.url);
|
||||
json.addProperty("action_time", this.actionTime);
|
||||
if (this.clickId != null) {
|
||||
JsonObject traceJson = new JsonObject();
|
||||
traceJson.addProperty("click_id", this.clickId);
|
||||
json.add("trace", traceJson);
|
||||
}
|
||||
if (this.actionParam != null) {
|
||||
JsonObject actionParamJson = new JsonObject();
|
||||
actionParamJson.addProperty("value", actionParam);
|
||||
json.add("action_param", actionParamJson);
|
||||
}
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package me.chanjar.weixin.mp.bean.marketing;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class WxMpUserActionSet implements Serializable {
|
||||
private static final long serialVersionUID = 1979861770645159905L;
|
||||
protected static final JsonParser JSON_PARSER = new JsonParser();
|
||||
|
||||
/**
|
||||
* user_action_set_id
|
||||
* 用户行为源名称
|
||||
*/
|
||||
@SerializedName("user_action_set_id")
|
||||
private Long userActionSetId;
|
||||
|
||||
/**
|
||||
* title.
|
||||
* 用户行为源描述
|
||||
*/
|
||||
@SerializedName("description")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* activate_status.
|
||||
* 数据接入状态, true 表示已接入, false 表示未接入
|
||||
*/
|
||||
@SerializedName("activate_status")
|
||||
private Boolean activate_status;
|
||||
|
||||
/**
|
||||
* created_time.
|
||||
* 创建时间
|
||||
*/
|
||||
@SerializedName("created_time")
|
||||
private String createdTime;
|
||||
|
||||
public static List<WxMpUserActionSet> fromJson(String json) {
|
||||
return WxMpGsonBuilder.create().fromJson(
|
||||
JSON_PARSER.parse(json).getAsJsonObject().get("data").getAsJsonObject().get("list"),
|
||||
new TypeToken<List<WxMpUserActionSet>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package me.chanjar.weixin.mp.bean.membercard;
|
||||
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
|
||||
/**
|
||||
* @author thomas
|
||||
* @date 2019/4/26
|
||||
*/
|
||||
@Data
|
||||
public class WxMpMemberCardActivateTempInfoResult {
|
||||
|
||||
private String errorCode;
|
||||
|
||||
private String errorMsg;
|
||||
|
||||
private MemberCardUserInfo userInfo;
|
||||
|
||||
public static WxMpMemberCardActivateTempInfoResult fromJson(String json) {
|
||||
return WxMpGsonBuilder.create().fromJson(json, WxMpMemberCardActivateTempInfoResult.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
package me.chanjar.weixin.mp.bean.message;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
import lombok.Data;
|
||||
@@ -7,18 +11,26 @@ import lombok.EqualsAndHashCode;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 被动回复的图文消息xml.
|
||||
* @author chanjarster
|
||||
*/
|
||||
@XStreamAlias("xml")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class WxMpXmlOutNewsMessage extends WxMpXmlOutMessage {
|
||||
private static final long serialVersionUID = -4604402850905714772L;
|
||||
|
||||
/**
|
||||
* 图文消息信息.
|
||||
* 注意,如果图文数超过限制,则将只发限制内的条数
|
||||
*/
|
||||
@XStreamAlias("Articles")
|
||||
protected final List<Item> articles = new ArrayList<>();
|
||||
/**
|
||||
* 图文消息个数.
|
||||
* 当用户发送文本、图片、视频、图文、地理位置这五种消息时,开发者只能回复1条图文消息;其余场景最多可回复8条图文消息
|
||||
*/
|
||||
@XStreamAlias("ArticleCount")
|
||||
protected int articleCount;
|
||||
|
||||
@@ -36,23 +48,35 @@ public class WxMpXmlOutNewsMessage extends WxMpXmlOutMessage {
|
||||
public static class Item implements Serializable {
|
||||
private static final long serialVersionUID = -4971456355028904754L;
|
||||
|
||||
/**
|
||||
* 图文消息标题.
|
||||
*/
|
||||
@XStreamAlias("Title")
|
||||
@XStreamConverter(value = XStreamCDataConverter.class)
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 图文消息描述.
|
||||
*/
|
||||
@XStreamAlias("Description")
|
||||
@XStreamConverter(value = XStreamCDataConverter.class)
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 图片链接.
|
||||
* 支持JPG、PNG格式,较好的效果为大图360*200,小图200*200
|
||||
*/
|
||||
@XStreamAlias("PicUrl")
|
||||
@XStreamConverter(value = XStreamCDataConverter.class)
|
||||
private String picUrl;
|
||||
|
||||
/**
|
||||
* 点击图文消息跳转链接.
|
||||
*/
|
||||
@XStreamAlias("Url")
|
||||
@XStreamConverter(value = XStreamCDataConverter.class)
|
||||
private String url;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,23 +10,23 @@ package me.chanjar.weixin.mp.constant;
|
||||
*/
|
||||
public class WxMpEventConstants {
|
||||
/**
|
||||
* 门店审核事件
|
||||
* 门店审核事件.
|
||||
*/
|
||||
public static final String POI_CHECK_NOTIFY = "poi_check_notify";
|
||||
|
||||
/**
|
||||
* 接收会员信息事件
|
||||
* 接收会员信息事件.
|
||||
*/
|
||||
public static final String SUBMIT_MEMBERCARD_USER_INFO = "submit_membercard_user_info";
|
||||
|
||||
/**
|
||||
* 微信摇一摇周边>>摇一摇事件通知
|
||||
* 微信摇一摇周边>>摇一摇事件通知.
|
||||
*/
|
||||
public static final String SHAKEAROUND_USER_SHAKE = "ShakearoundUserShake";
|
||||
|
||||
|
||||
/**
|
||||
* 卡券相关事件
|
||||
* 卡券相关事件.
|
||||
*/
|
||||
public static class Card {
|
||||
public static final String CARD_PASS_CHECK = "card_pass_check";
|
||||
@@ -39,74 +39,89 @@ public class WxMpEventConstants {
|
||||
public static final String USER_ENTER_SESSION_FROM_CARD = "user_enter_session_from_card";
|
||||
|
||||
/**
|
||||
* 卡券转赠事件
|
||||
* 卡券转赠事件.
|
||||
*/
|
||||
public static final String USER_GIFTING_CARD = "user_gifting_card";
|
||||
|
||||
/**
|
||||
* 库存报警
|
||||
* 库存报警.
|
||||
*/
|
||||
public static final String CARD_SKU_REMIND = "card_sku_remind";
|
||||
|
||||
/**
|
||||
* 会员卡内容更新事件
|
||||
* 会员卡内容更新事件.
|
||||
*/
|
||||
public static final String UPDATE_MEMBER_CARD = "update_member_card";
|
||||
|
||||
/**
|
||||
* 券点流水详情事件
|
||||
* 券点流水详情事件.
|
||||
*/
|
||||
public static final String CARD_PAY_ORDER = "card_pay_order";
|
||||
|
||||
/**
|
||||
* 用户购买礼品卡付款成功事件.
|
||||
*/
|
||||
public static final String GIFTCARD_PAY_DONE = "giftcard_pay_done";
|
||||
|
||||
/**
|
||||
* 用户购买后赠送事件.
|
||||
*/
|
||||
public static final String GIFTCARD_SEND_TO_FRIEND = "giftcard_send_to_friend";
|
||||
|
||||
/**
|
||||
* 用户领取礼品卡成功事件.
|
||||
*/
|
||||
public static final String GIFTCARD_USER_ACCEPT = "giftcard_user_accept";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 客服相关事件
|
||||
* 客服相关事件.
|
||||
*/
|
||||
public static class CustomerService {
|
||||
/**
|
||||
* 客服接入会话
|
||||
* 客服接入会话.
|
||||
*/
|
||||
public static final String KF_CREATE_SESSION = "kf_create_session";
|
||||
|
||||
/**
|
||||
* 客服关闭会话
|
||||
* 客服关闭会话.
|
||||
*/
|
||||
public static final String KF_CLOSE_SESSION = "kf_close_session";
|
||||
|
||||
/**
|
||||
* 客服转接会话
|
||||
* 客服转接会话.
|
||||
*/
|
||||
public static final String KF_SWITCH_SESSION = "kf_switch_session";
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信认证事件
|
||||
* 微信认证事件.
|
||||
*/
|
||||
public static class Qualification {
|
||||
|
||||
/**
|
||||
* 资质认证成功
|
||||
* 资质认证成功.
|
||||
*/
|
||||
public static final String QUALIFICATION_VERIFY_SUCCESS = "qualification_verify_success";
|
||||
/**
|
||||
* 资质认证失败
|
||||
* 资质认证失败.
|
||||
*/
|
||||
public static final String QUALIFICATION_VERIFY_FAIL = "qualification_verify_fail";
|
||||
/**
|
||||
* 名称认证成功
|
||||
* 名称认证成功.
|
||||
*/
|
||||
public static final String NAMING_VERIFY_SUCCESS = "naming_verify_success";
|
||||
/**
|
||||
* 名称认证失败
|
||||
* 名称认证失败.
|
||||
*/
|
||||
public static final String NAMING_VERIFY_FAIL = "naming_verify_fail";
|
||||
/**
|
||||
* 年审通知
|
||||
* 年审通知.
|
||||
*/
|
||||
public static final String ANNUAL_RENEW = "annual_renew";
|
||||
/**
|
||||
* 认证过期失效通知
|
||||
* 认证过期失效通知.
|
||||
*/
|
||||
public static final String VERIFY_EXPIRED = "verify_expired";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package me.chanjar.weixin.mp.util;
|
||||
|
||||
|
||||
/**
|
||||
* @Author: yd
|
||||
* @Date: 2019-03-20 22:06
|
||||
*/
|
||||
public class WxMpConfigStorageHolder {
|
||||
|
||||
private final static ThreadLocal<String> WX_MP_CONFIG_STORAGE_CHOSE = new ThreadLocal<String>() {
|
||||
@Override
|
||||
protected String initialValue() {
|
||||
return "default";
|
||||
}
|
||||
};
|
||||
|
||||
public static String get() {
|
||||
return WX_MP_CONFIG_STORAGE_CHOSE.get();
|
||||
}
|
||||
|
||||
public static void set(String label) {
|
||||
WX_MP_CONFIG_STORAGE_CHOSE.set(label);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
package me.chanjar.weixin.mp.util.json;
|
||||
|
||||
import com.google.gson.*;
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
import me.chanjar.weixin.mp.bean.WxMpCard;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
import me.chanjar.weixin.mp.bean.card.WxMpCard;
|
||||
|
||||
/**
|
||||
* Created by YuJian on 15/11/11.
|
||||
*
|
||||
@@ -18,11 +22,16 @@ public class WxMpCardGsonAdapter implements JsonDeserializer<WxMpCard> {
|
||||
public WxMpCard deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext
|
||||
jsonDeserializationContext) throws JsonParseException {
|
||||
WxMpCard card = new WxMpCard();
|
||||
|
||||
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||
|
||||
card.setCardId(GsonHelper.getString(jsonObject, "card_id"));
|
||||
card.setBeginTime(GsonHelper.getLong(jsonObject, "begin_time"));
|
||||
card.setEndTime(GsonHelper.getLong(jsonObject, "end_time"));
|
||||
card.setUserCardStatus(GsonHelper.getString(jsonObject, "user_card_status"));
|
||||
card.setMembershipNumber(GsonHelper.getString(jsonObject, "membership_number"));
|
||||
card.setCode(GsonHelper.getString(jsonObject, "code"));
|
||||
card.setBonus(GsonHelper.getInteger(jsonObject, "bonus"));
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package me.chanjar.weixin.mp.util.json;
|
||||
|
||||
import com.google.gson.*;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
import me.chanjar.weixin.mp.bean.WxMpCard;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpCardResult;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import me.chanjar.weixin.mp.bean.card.WxMpCard;
|
||||
import me.chanjar.weixin.mp.bean.card.WxMpCardResult;
|
||||
|
||||
/**
|
||||
* Created by YuJian on 15/11/11.
|
||||
@@ -18,6 +22,7 @@ public class WxMpCardResultGsonAdapter implements JsonDeserializer<WxMpCardResul
|
||||
@Override
|
||||
public WxMpCardResult deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||
WxMpCardResult cardResult = new WxMpCardResult();
|
||||
|
||||
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||
|
||||
cardResult.setOpenId(GsonHelper.getString(jsonObject, "openid"));
|
||||
@@ -25,6 +30,9 @@ public class WxMpCardResultGsonAdapter implements JsonDeserializer<WxMpCardResul
|
||||
cardResult.setErrorMsg(GsonHelper.getString(jsonObject, "errmsg"));
|
||||
cardResult.setCanConsume(GsonHelper.getBoolean(jsonObject, "can_consume"));
|
||||
cardResult.setUserCardStatus(GsonHelper.getString(jsonObject, "user_card_status"));
|
||||
cardResult.setOutStr(GsonHelper.getString(jsonObject, "outer_str"));
|
||||
cardResult.setBackgroundPicUrl(GsonHelper.getString(jsonObject, "background_pic_url"));
|
||||
cardResult.setUnionid(GsonHelper.getString(jsonObject, "unionid"));
|
||||
|
||||
WxMpCard card = WxMpGsonBuilder.create().fromJson(jsonObject.get("card"),
|
||||
new TypeToken<WxMpCard>() {
|
||||
|
||||
@@ -3,9 +3,12 @@ package me.chanjar.weixin.mp.util.json;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import me.chanjar.weixin.mp.bean.*;
|
||||
import me.chanjar.weixin.mp.bean.card.WxMpCard;
|
||||
import me.chanjar.weixin.mp.bean.card.WxMpCardResult;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
|
||||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardActivateTempInfoResult;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUpdateResult;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUserInfoResult;
|
||||
import me.chanjar.weixin.mp.bean.material.*;
|
||||
@@ -56,6 +59,7 @@ public class WxMpGsonBuilder {
|
||||
INSTANCE.registerTypeAdapter(WxMpUserBlacklistGetResult.class, new WxUserBlacklistGetResultGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpMemberCardUserInfoResult.class, new WxMpMemberCardUserInfoResultGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpMemberCardUpdateResult.class, new WxMpMemberCardUpdateResultGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMpMemberCardActivateTempInfoResult.class, new WxMpMemberCardActivateTempInfoResultGsonAdapter());
|
||||
}
|
||||
|
||||
public static Gson create() {
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package me.chanjar.weixin.mp.util.json;
|
||||
|
||||
import com.google.gson.*;
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
import me.chanjar.weixin.mp.bean.membercard.MemberCardUserInfo;
|
||||
import me.chanjar.weixin.mp.bean.membercard.NameValues;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardActivateTempInfoResult;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* Json to WxMpMemberCardActivateTempInfoResultGsonAdapter 的转换适配器
|
||||
*
|
||||
* @author thomas(351402401 @ qq.com)
|
||||
* @version 2019/4/26
|
||||
*/
|
||||
public class WxMpMemberCardActivateTempInfoResultGsonAdapter implements JsonDeserializer<WxMpMemberCardActivateTempInfoResult> {
|
||||
|
||||
@Override
|
||||
public WxMpMemberCardActivateTempInfoResult deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||
WxMpMemberCardActivateTempInfoResult result = new WxMpMemberCardActivateTempInfoResult();
|
||||
|
||||
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||
|
||||
result.setErrorCode(GsonHelper.getString(jsonObject, "errcode"));
|
||||
result.setErrorMsg(GsonHelper.getString(jsonObject, "errmsg"));
|
||||
|
||||
JsonObject userInfoJsonObject = jsonObject.getAsJsonObject("info");
|
||||
MemberCardUserInfo cardUserInfo = new MemberCardUserInfo();
|
||||
|
||||
JsonArray commonFieldListObj = userInfoJsonObject.getAsJsonArray("common_field_list");
|
||||
NameValues[] commonFieldListValues = new NameValues[commonFieldListObj.size()];
|
||||
for (int i = 0; i < commonFieldListObj.size(); i++) {
|
||||
JsonObject commonField = commonFieldListObj.get(i).getAsJsonObject();
|
||||
NameValues commonNameValues = new NameValues();
|
||||
commonNameValues.setName(GsonHelper.getString(commonField, "name"));
|
||||
commonNameValues.setValue(GsonHelper.getString(commonField, "value"));
|
||||
commonFieldListValues[i] = commonNameValues;
|
||||
}
|
||||
cardUserInfo.setCommonFieldList(commonFieldListValues);
|
||||
|
||||
JsonArray customFieldListObj = userInfoJsonObject.getAsJsonArray("custom_field_list");
|
||||
NameValues[] customFieldListValues = new NameValues[customFieldListObj.size()];
|
||||
for (int i = 0; i < customFieldListObj.size(); i++) {
|
||||
JsonObject customField = customFieldListObj.get(i).getAsJsonObject();
|
||||
NameValues customNameValues = new NameValues();
|
||||
customNameValues.setName(GsonHelper.getString(customField, "name"));
|
||||
customNameValues.setValue(GsonHelper.getString(customField, "value"));
|
||||
|
||||
JsonArray valueListArray = customField.getAsJsonArray("value_list");
|
||||
String[] valueList = new String[valueListArray.size()];
|
||||
for (int j = 0; j < valueListArray.size(); j++) {
|
||||
valueList[j] = valueListArray.get(j).getAsString();
|
||||
}
|
||||
customNameValues.setValueList(valueList);
|
||||
customFieldListValues[i] = customNameValues;
|
||||
}
|
||||
cardUserInfo.setCustomFieldList(customFieldListValues);
|
||||
|
||||
result.setUserInfo(cardUserInfo);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,50 +1,62 @@
|
||||
package me.chanjar.weixin.mp.util.json;
|
||||
|
||||
import com.google.gson.*;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
import me.chanjar.weixin.mp.bean.membercard.MemberCardUserInfo;
|
||||
import me.chanjar.weixin.mp.bean.membercard.NameValues;
|
||||
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUserInfoResult;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import static me.chanjar.weixin.common.util.json.GsonHelper.getString;
|
||||
|
||||
/**
|
||||
* Json to WxMpMemberCardUserInfoResult 的转换适配器
|
||||
*
|
||||
* @author YuJian(mgcnrx11@gmail.com)
|
||||
* @author YuJian(mgcnrx11 @ gmail.com)
|
||||
* @version 2017/7/11
|
||||
*/
|
||||
public class WxMpMemberCardUserInfoResultGsonAdapter implements JsonDeserializer<WxMpMemberCardUserInfoResult> {
|
||||
|
||||
@Override
|
||||
public WxMpMemberCardUserInfoResult deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||
public WxMpMemberCardUserInfoResult deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
WxMpMemberCardUserInfoResult result = new WxMpMemberCardUserInfoResult();
|
||||
|
||||
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||
|
||||
result.setOpenId(GsonHelper.getString(jsonObject, "openid"));
|
||||
result.setErrorCode(GsonHelper.getString(jsonObject, "errcode"));
|
||||
result.setErrorMsg(GsonHelper.getString(jsonObject, "errmsg"));
|
||||
result.setNickname(GsonHelper.getString(jsonObject, "nickname"));
|
||||
result.setMembershipNumber(GsonHelper.getString(jsonObject, "membership_number"));
|
||||
result.setOpenId(getString(jsonObject, "openid"));
|
||||
result.setErrorCode(getString(jsonObject, "errcode"));
|
||||
result.setErrorMsg(getString(jsonObject, "errmsg"));
|
||||
result.setNickname(getString(jsonObject, "nickname"));
|
||||
result.setMembershipNumber(getString(jsonObject, "membership_number"));
|
||||
result.setBonus(GsonHelper.getInteger(jsonObject, "bonus"));
|
||||
result.setBalance(GsonHelper.getDouble(jsonObject, "balance"));
|
||||
result.setSex(GsonHelper.getString(jsonObject, "sex"));
|
||||
result.setUserCardStatus(GsonHelper.getString(jsonObject, "user_card_status"));
|
||||
result.setSex(getString(jsonObject, "sex"));
|
||||
result.setUserCardStatus(getString(jsonObject, "user_card_status"));
|
||||
result.setHasActive(GsonHelper.getBoolean(jsonObject, "has_active"));
|
||||
|
||||
JsonObject userInfoJsonObject = jsonObject.getAsJsonObject("user_info");
|
||||
MemberCardUserInfo cardUserInfo = new MemberCardUserInfo();
|
||||
if (userInfoJsonObject == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
JsonArray commonFieldListObj = userInfoJsonObject.getAsJsonArray("common_field_list");
|
||||
NameValues[] commonFieldListValues = new NameValues[commonFieldListObj.size()];
|
||||
for (int i = 0; i < commonFieldListObj.size(); i++) {
|
||||
JsonObject commonField = commonFieldListObj.get(i).getAsJsonObject();
|
||||
NameValues commonNameValues = new NameValues();
|
||||
commonNameValues.setName(GsonHelper.getString(commonField, "name"));
|
||||
commonNameValues.setValue(GsonHelper.getString(commonField, "value"));
|
||||
commonNameValues.setName(getString(commonField, "name"));
|
||||
commonNameValues.setValue(getString(commonField, "value"));
|
||||
commonFieldListValues[i] = commonNameValues;
|
||||
}
|
||||
|
||||
MemberCardUserInfo cardUserInfo = new MemberCardUserInfo();
|
||||
cardUserInfo.setCommonFieldList(commonFieldListValues);
|
||||
|
||||
JsonArray customFieldListObj = userInfoJsonObject.getAsJsonArray("custom_field_list");
|
||||
@@ -52,8 +64,8 @@ public class WxMpMemberCardUserInfoResultGsonAdapter implements JsonDeserializer
|
||||
for (int i = 0; i < customFieldListObj.size(); i++) {
|
||||
JsonObject customField = customFieldListObj.get(i).getAsJsonObject();
|
||||
NameValues customNameValues = new NameValues();
|
||||
customNameValues.setName(GsonHelper.getString(customField, "name"));
|
||||
customNameValues.setValue(GsonHelper.getString(customField, "value"));
|
||||
customNameValues.setName(getString(customField, "name"));
|
||||
customNameValues.setValue(getString(customField, "value"));
|
||||
|
||||
JsonArray valueListArray = customField.getAsJsonArray("value_list");
|
||||
String[] valueList = new String[valueListArray.size()];
|
||||
@@ -63,6 +75,7 @@ public class WxMpMemberCardUserInfoResultGsonAdapter implements JsonDeserializer
|
||||
customNameValues.setValueList(valueList);
|
||||
customFieldListValues[i] = customNameValues;
|
||||
}
|
||||
|
||||
cardUserInfo.setCustomFieldList(customFieldListValues);
|
||||
|
||||
result.setUserInfo(cardUserInfo);
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.test.ApiTestModule;
|
||||
import me.chanjar.weixin.mp.util.WxMpConfigStorageHolder;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by BinaryWang on 2019/3/29.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@Test
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class BaseWxMpServiceImplTest {
|
||||
@Inject
|
||||
private WxMpService wxService;
|
||||
|
||||
@Test
|
||||
public void testSwitchover() {
|
||||
assertTrue(this.wxService.switchover("another"));
|
||||
assertThat(WxMpConfigStorageHolder.get()).isEqualTo("another");
|
||||
assertFalse(this.wxService.switchover("whatever"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwitchoverTo() throws WxErrorException {
|
||||
assertThat(this.wxService.switchoverTo("another").getAccessToken()).isNotEmpty();
|
||||
assertThat(WxMpConfigStorageHolder.get()).isEqualTo("another");
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.testng.annotations.*;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.enums.AiLangType;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.test.ApiTestModule;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
import me.chanjar.weixin.mp.enums.AiLangType;
|
||||
|
||||
import java.io.File;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
@@ -35,13 +37,12 @@ public class WxMpAiOpenServiceImplTest {
|
||||
String voiceId = System.currentTimeMillis() + "a";
|
||||
AiLangType lang = AiLangType.zh_CN;
|
||||
final String result = this.wxService.getAiOpenService().recogniseVoice(voiceId, lang, new File("d:\\t.mp3"));
|
||||
System.out.println(result);
|
||||
assertThat(result).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTranslate() throws WxErrorException {
|
||||
final String responseContent = this.wxService.getAiOpenService()
|
||||
.translate(AiLangType.zh_CN, AiLangType.en_US, "微信文档很坑爹");
|
||||
System.out.println(responseContent);
|
||||
final String result = this.wxService.getAiOpenService().translate(AiLangType.zh_CN, AiLangType.en_US, "微信文档很坑爹");
|
||||
assertThat(result).isNotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,15 @@ package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.bean.WxCardApiSignature;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.test.ApiTestModule;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpCardResult;
|
||||
import org.testng.annotations.*;
|
||||
import me.chanjar.weixin.mp.bean.card.*;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.AssertJUnit.*;
|
||||
import static org.testng.AssertJUnit.assertEquals;
|
||||
import static org.testng.AssertJUnit.assertNotNull;
|
||||
|
||||
/**
|
||||
* 测试代码仅供参考,未做严格测试,因原接口作者并未提供单元测试代码
|
||||
@@ -100,4 +103,107 @@ public class WxMpCardServiceImplTest {
|
||||
assertNotNull(result);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateGrouponCard() throws WxErrorException {
|
||||
|
||||
BaseInfo base = new BaseInfo();
|
||||
base.setLogoUrl("http://mmbiz.qpic.cn/mmbiz/iaL1LJM1mF9aRKPZJkmG8xXhiaHqkKSVMMWeN3hLut7X7hicFNjakmxibMLGWpXrEXB33367o7zHN0CwngnQY7zb7g/0");
|
||||
base.setBrandName("测试优惠券");
|
||||
base.setCodeType("CODE_TYPE_QRCODE");
|
||||
base.setTitle("测试标题");
|
||||
base.setColor("Color010");
|
||||
base.setNotice("测试Notice");
|
||||
base.setServicePhone("020-88888888");
|
||||
base.setDescription("不可与其他优惠同享\\n如需团购券发票,请在消费时向商户提出\\n店内均可使用,仅限堂食");
|
||||
DateInfo info = new DateInfo();
|
||||
info.setType("DATE_TYPE_FIX_TERM");
|
||||
info.setFixedBeginTerm(0);
|
||||
info.setFixedTerm(30);
|
||||
base.setDateInfo(info);
|
||||
Sku sku = new Sku();
|
||||
sku.setQuantity(100);
|
||||
base.setSku(sku);
|
||||
base.setGetLimit(1);
|
||||
base.setCanShare(true);
|
||||
base.setCanGiveFriend(true);
|
||||
base.setUseAllLocations(true);
|
||||
base.setCenterTitle("顶部居中按钮");
|
||||
base.setCenterSubTitle("按钮下方的wording");
|
||||
base.setCenterUrl("www.qq.com");
|
||||
base.setCustomUrl("http://www.qq.com");
|
||||
base.setCustomUrlName("立即使用");
|
||||
base.setCustomUrlSubTitle("副标题tip");
|
||||
base.setPromotionUrlName("更多优惠");
|
||||
base.setPromotionUrl("http://www.qq.com");
|
||||
base.setLocationIdList("1234");
|
||||
|
||||
//团购券
|
||||
WxMpCardCreateMessage grouponMessage = new WxMpCardCreateMessage();
|
||||
GrouponCardCreateRequest grouponCardCreateRequest = new GrouponCardCreateRequest();
|
||||
GrouponCard grouponCard = new GrouponCard();
|
||||
grouponCard.setBaseInfo(base);
|
||||
grouponCard.setDealDetail("deal detail");
|
||||
|
||||
grouponCardCreateRequest.setGroupon(grouponCard);
|
||||
grouponMessage.setCardCreateRequest(grouponCardCreateRequest);
|
||||
|
||||
System.out.println(this.wxService.getCardService().createCard(grouponMessage));
|
||||
|
||||
//现金券
|
||||
WxMpCardCreateMessage cashMessage = new WxMpCardCreateMessage();
|
||||
CashCardCreateRequest cashCardCreateRequest = new CashCardCreateRequest();
|
||||
CashCard cashCard = new CashCard();
|
||||
cashCard.setBaseInfo(base);
|
||||
cashCard.setLeastCost(1000);
|
||||
cashCard.setReduceCost(100);
|
||||
|
||||
cashCardCreateRequest.setCash(cashCard);
|
||||
cashMessage.setCardCreateRequest(cashCardCreateRequest);
|
||||
|
||||
System.out.println(this.wxService.getCardService().createCard(cashMessage));
|
||||
|
||||
//折扣券
|
||||
WxMpCardCreateMessage discountMessage = new WxMpCardCreateMessage();
|
||||
DiscountCardCreateRequest discountCardCreateRequest = new DiscountCardCreateRequest();
|
||||
DiscountCard discountCard = new DiscountCard();
|
||||
discountCard.setBaseInfo(base);
|
||||
discountCard.setDiscount(30);
|
||||
|
||||
discountCardCreateRequest.setDiscount(discountCard);
|
||||
discountMessage.setCardCreateRequest(discountCardCreateRequest);
|
||||
|
||||
System.out.println(this.wxService.getCardService().createCard(discountMessage));
|
||||
|
||||
//兑换券
|
||||
WxMpCardCreateMessage giftMessage = new WxMpCardCreateMessage();
|
||||
GiftCardCreateRequest giftCardCreateRequest = new GiftCardCreateRequest();
|
||||
GiftCard giftCard = new GiftCard();
|
||||
giftCard.setBaseInfo(base);
|
||||
giftCard.setGift("星巴克雪瑞纳咖啡大杯");
|
||||
|
||||
giftCardCreateRequest.setGift(giftCard);
|
||||
giftMessage.setCardCreateRequest(giftCardCreateRequest);
|
||||
System.out.println(this.wxService.getCardService().createCard(giftMessage));
|
||||
|
||||
//普通兑换券
|
||||
WxMpCardCreateMessage generalMessage = new WxMpCardCreateMessage();
|
||||
GeneralCardCreateRequest generalCardCreateRequest = new GeneralCardCreateRequest();
|
||||
GeneralCard generalCard = new GeneralCard();
|
||||
generalCard.setBaseInfo(base);
|
||||
generalCard.setDefaultDetail("音乐木盒");
|
||||
|
||||
generalCardCreateRequest.setGeneralCoupon(generalCard);
|
||||
generalMessage.setCardCreateRequest(generalCardCreateRequest);
|
||||
System.out.println(this.wxService.getCardService().createCard(generalMessage));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteCard() throws Exception {
|
||||
String cardId = "pwkrWjtw7W4_l50kCQcZ1in1yS6g";
|
||||
WxMpCardDeleteResult result = this.wxService.getCardService().deleteCard(cardId);
|
||||
assertEquals(result.isSuccess(), true);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ public class WxMpMemberCardServiceImplTest {
|
||||
|
||||
@Inject
|
||||
protected WxMpService wxService;
|
||||
private String cardId = "p2iQk1uwOUYlzHm4s-UYdZnABW88";
|
||||
private String code = "435223630779";
|
||||
private String openId = "o2iQk1u5X-XIJkatmAK1Q8VVuS90";
|
||||
private String cardId = "p4p-v1bKn9tiQHxyO79aKmuTIZlQ";
|
||||
private String code = "224765120681";
|
||||
private String openId = "o4p-v1TIemEIpBSrSrTprkCaG6Xc";
|
||||
|
||||
@Test
|
||||
public void createMemberCard() throws Exception {
|
||||
@@ -150,6 +150,15 @@ public class WxMpMemberCardServiceImplTest {
|
||||
WxMpMemberCardService memberCardService = this.wxService.getMemberCardService();
|
||||
ActivatePluginParam response = memberCardService.getActivatePluginParam(cardId, "test");
|
||||
System.out.println(response);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetActivateTempInfo() throws Exception {
|
||||
String activateTicket = "fDZv9eMQAFfrNr3XBoqhb8eUX67DFb6h8yXDelGSMDLfg2OAIGQcU7mEKecnWZBK%2B%2Bvm%2FtZxZJrbRkdJB%2FUmpVoJkEsbeH%2BOefcntAsYDKA%3D";
|
||||
WxMpMemberCardService memberCardService = this.wxService.getMemberCardService();
|
||||
WxMpMemberCardActivateTempInfoResult result = memberCardService.getActivateTempInfo(activateTicket);
|
||||
assertNotNull(result);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,9 +9,11 @@ import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.test.ApiTestModule;
|
||||
import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
|
||||
import me.chanjar.weixin.mp.bean.menu.WxMpMenu;
|
||||
import org.testng.annotations.*;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* 测试菜单
|
||||
@@ -19,7 +21,7 @@ import static org.testng.Assert.*;
|
||||
* @author chanjarster
|
||||
* @author Binary Wang
|
||||
*/
|
||||
@Test(groups = "menuAPI")
|
||||
@Test
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMpMenuServiceImplTest {
|
||||
|
||||
@@ -88,6 +90,48 @@ public class WxMpMenuServiceImplTest {
|
||||
System.out.println(this.menuId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiCreateConditionalMenu() throws WxErrorException {
|
||||
String json = "{\n" +
|
||||
" \"button\":[\n" +
|
||||
" { \n" +
|
||||
" \"type\":\"click\",\n" +
|
||||
" \"name\":\"今日歌曲\",\n" +
|
||||
" \"key\":\"V1001_TODAY_MUSIC\" \n" +
|
||||
" },\n" +
|
||||
" { \n" +
|
||||
" \"name\":\"菜单\",\n" +
|
||||
" \"sub_button\":[\n" +
|
||||
" { \n" +
|
||||
" \"type\":\"view\",\n" +
|
||||
" \"name\":\"搜索\",\n" +
|
||||
" \"url\":\"http://www.soso.com/\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"type\":\"view\",\n" +
|
||||
" \"name\":\"视频\",\n" +
|
||||
" \"url\":\"http://v.qq.com/\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"type\":\"click\",\n" +
|
||||
" \"name\":\"赞一下我们\",\n" +
|
||||
" \"key\":\"V1001_GOOD\"\n" +
|
||||
" }]\n" +
|
||||
" }],\n" +
|
||||
"\"matchrule\":{\n" +
|
||||
" \"tag_id\":\"2\",\n" +
|
||||
" \"sex\":\"1\",\n" +
|
||||
" \"country\":\"中国\",\n" +
|
||||
" \"province\":\"广东\",\n" +
|
||||
" \"city\":\"广州\",\n" +
|
||||
" \"client_platform_type\":\"2\",\n" +
|
||||
" \"language\":\"zh_CN\"\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
this.menuId = this.wxService.getMenuService().menuCreate(json);
|
||||
System.out.println(this.menuId);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = {"testCreateConditionalMenu"})
|
||||
public void testMenuGet_AfterCreateConditionalMenu() throws WxErrorException {
|
||||
WxMpMenu wxMenu = this.wxService.getMenuService().menuGet();
|
||||
@@ -147,7 +191,7 @@ public class WxMpMenuServiceImplTest {
|
||||
System.out.println(wxMenu.toJson());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = {"testMenuGet","testMenuCreate"})
|
||||
@Test(dependsOnMethods = {"testMenuGet", "testMenuCreate"})
|
||||
public void testMenuDelete() throws WxErrorException {
|
||||
this.wxService.getMenuService().menuDelete();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import com.thoughtworks.xstream.XStream;
|
||||
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
|
||||
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.impl.WxMpServiceOkHttpImpl;
|
||||
|
||||
public class ApiTestModule implements Module {
|
||||
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
@@ -29,11 +28,13 @@ public class ApiTestModule implements Module {
|
||||
|
||||
TestConfigStorage config = this.fromXml(TestConfigStorage.class, inputStream);
|
||||
config.setAccessTokenLock(new ReentrantLock());
|
||||
WxMpService wxService = new WxMpServiceHttpClientImpl();
|
||||
wxService.setWxMpConfigStorage(config);
|
||||
WxMpService mpService = new WxMpServiceHttpClientImpl();
|
||||
|
||||
mpService.setWxMpConfigStorage(config);
|
||||
mpService.addConfigStorage("another", config);
|
||||
|
||||
binder.bind(WxMpService.class).toInstance(wxService);
|
||||
binder.bind(WxMpConfigStorage.class).toInstance(config);
|
||||
binder.bind(WxMpService.class).toInstance(mpService);
|
||||
} catch (IOException e) {
|
||||
this.log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package me.chanjar.weixin.mp.bean.result;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.marketing.WxMpAdLeadResult;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
public class WxMpAdLeadResultTest {
|
||||
@Test
|
||||
public void testFromJson() throws Exception {
|
||||
String json = "{\n" +
|
||||
"\t\"data\": {\n" +
|
||||
"\t\t\"page_info\": {\n" +
|
||||
"\t\t\t\"total_number\": 39,\n" +
|
||||
"\t\t\t\"page\": 1,\n" +
|
||||
"\t\t\t\"page_size\": 100,\n" +
|
||||
"\t\t\t\"total_page\": 1\n" +
|
||||
"\t\t},\n" +
|
||||
"\t\t\"list\": [{\n" +
|
||||
"\t\t\t\"click_id\": \"<click_id1>\",\n" +
|
||||
"\t\t\t\"adgroup_name\": \"<adgroup_name>\",\n" +
|
||||
"\t\t\t\"campaign_id\": 1800000001,\n" +
|
||||
"\t\t\t\"leads_info\": [{\n" +
|
||||
"\t\t\t\t\"value\": \"13800138000\",\n" +
|
||||
"\t\t\t\t\"key\": \"电话号码\"\n" +
|
||||
"\t\t\t}, {\n" +
|
||||
"\t\t\t\t\"value\": \"2019-03-14 00:54:34\",\n" +
|
||||
"\t\t\t\t\"key\": \"提交时间\"\n" +
|
||||
"\t\t\t}, {\n" +
|
||||
"\t\t\t\t\"value\": \"123\",\n" +
|
||||
"\t\t\t\t\"key\": \"自定义问题\"\n" +
|
||||
"\t\t\t}],\n" +
|
||||
"\t\t\t\"agency_name\": \"\",\n" +
|
||||
"\t\t\t\"agency_id\": \"\",\n" +
|
||||
"\t\t\t\"campaign_name\": \"<campaign_name>\",\n" +
|
||||
"\t\t\t\"adgroup_id\": 1800000002\n" +
|
||||
"\t\t}, {\n" +
|
||||
"\t\t\t\"click_id\": \"<click_id2>\",\n" +
|
||||
"\t\t\t\"adgroup_name\": \"<adgroup_name>\",\n" +
|
||||
"\t\t\t\"campaign_id\": 1800000001,\n" +
|
||||
"\t\t\t\"leads_info\": [{\n" +
|
||||
"\t\t\t\t\"value\": \"13800138001\",\n" +
|
||||
"\t\t\t\t\"key\": \"电话号码\"\n" +
|
||||
"\t\t\t}, {\n" +
|
||||
"\t\t\t\t\"value\": \"2019-03-14 02:10:39\",\n" +
|
||||
"\t\t\t\t\"key\": \"提交时间\"\n" +
|
||||
"\t\t\t}, {\n" +
|
||||
"\t\t\t\t\"value\": \"321\",\n" +
|
||||
"\t\t\t\t\"key\": \"自定义问题\"\n" +
|
||||
"\t\t\t}],\n" +
|
||||
"\t\t\t\"agency_name\": \"\",\n" +
|
||||
"\t\t\t\"agency_id\": \"\",\n" +
|
||||
"\t\t\t\"campaign_name\": \"<campaign_name>\",\n" +
|
||||
"\t\t\t\"adgroup_id\": 1800000002\n" +
|
||||
"\t\t}]\n" +
|
||||
"\t},\n" +
|
||||
"\t\"errcode\": 0,\n" +
|
||||
"\t\"errmsg\": \"\"\n" +
|
||||
"}";
|
||||
|
||||
WxMpAdLeadResult adLeadResult = WxMpAdLeadResult.fromJson(json);
|
||||
|
||||
assertNotNull(adLeadResult);
|
||||
assertNotNull(adLeadResult.getPageInfo());
|
||||
assertNotNull(adLeadResult.getAdLeads());
|
||||
assertTrue(adLeadResult.getAdLeads().size() > 0);
|
||||
|
||||
System.out.println(adLeadResult);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user