| @@ -283,4 +283,15 @@ public interface WxMpCardService { | |||||
| void cardSelfConsumeCellSet(String cardId, Boolean isOpen, | void cardSelfConsumeCellSet(String cardId, Boolean isOpen, | ||||
| Boolean needVerifyCod, Boolean needRemarkAmount) throws WxErrorException; | Boolean needVerifyCod, Boolean needRemarkAmount) throws WxErrorException; | ||||
| /** | |||||
| * 获取用户已领取卡券接口 | |||||
| * https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Managing_Coupons_Vouchers_and_Cards.html#1 | |||||
| * | |||||
| * @param openId 需要查询的用户openid | |||||
| * @param cardId 卡券ID。不填写时默认查询当前appid下的卡券 | |||||
| * @return | |||||
| * @throws WxErrorException | |||||
| */ | |||||
| WxUserCardListResult getUserCardList(String openId, String cardId) throws WxErrorException; | |||||
| } | } | ||||
| @@ -351,6 +351,16 @@ public class WxMpCardServiceImpl implements WxMpCardService { | |||||
| } | } | ||||
| @Override | |||||
| public WxUserCardListResult getUserCardList(String openId, String cardId) throws WxErrorException { | |||||
| JsonObject param = new JsonObject(); | |||||
| param.addProperty("openid", openId); | |||||
| param.addProperty("card_id", cardId); | |||||
| String response = this.wxMpService.post(WxMpApiUrl.Card.CARD_USER_CARD_LIST, param.toString()); | |||||
| return WxUserCardListResult.fromJson(response); | |||||
| } | |||||
| private void checkCardId(String cardId) throws WxErrorException { | private void checkCardId(String cardId) throws WxErrorException { | ||||
| if (StringUtils.isEmpty(cardId)) { | if (StringUtils.isEmpty(cardId)) { | ||||
| throw new WxErrorException(WxError.builder().errorCode(41012).errorMsg("cardId不能为空").build()); | throw new WxErrorException(WxError.builder().errorCode(41012).errorMsg("cardId不能为空").build()); | ||||
| @@ -0,0 +1,34 @@ | |||||
| package me.chanjar.weixin.mp.bean.card; | |||||
| import com.google.gson.annotations.SerializedName; | |||||
| import lombok.Data; | |||||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
| /** | |||||
| * 用户已领卡圈对象 | |||||
| * @author yang229 | |||||
| * @date 2019/12/22 | |||||
| */ | |||||
| @Data | |||||
| public class UserCard implements java.io.Serializable { | |||||
| /** | |||||
| * 用户卡券code码 | |||||
| */ | |||||
| @SerializedName("code") | |||||
| private String code; | |||||
| /** | |||||
| * 卡券ID | |||||
| */ | |||||
| @SerializedName("card_id") | |||||
| private String cardId; | |||||
| public static UserCard fromJson(String json) { | |||||
| return WxMpGsonBuilder.create().fromJson(json, UserCard.class); | |||||
| } | |||||
| @Override | |||||
| public String toString() { | |||||
| return WxMpGsonBuilder.create().toJson(this); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,38 @@ | |||||
| package me.chanjar.weixin.mp.bean.card; | |||||
| import com.google.gson.annotations.SerializedName; | |||||
| import lombok.Data; | |||||
| import me.chanjar.weixin.mp.bean.result.WxMpResult; | |||||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||||
| import java.util.List; | |||||
| /** | |||||
| * 用户已领卡券返回 | |||||
| * @author yang229 | |||||
| * @date 2019/12/22 | |||||
| */ | |||||
| @Data | |||||
| public class WxUserCardListResult extends WxMpResult implements java.io.Serializable { | |||||
| /** | |||||
| * 卡券列表 | |||||
| */ | |||||
| @SerializedName("card_list") | |||||
| private List<UserCard> cardList; | |||||
| /** | |||||
| * 是否有可用的朋友的券 | |||||
| */ | |||||
| @SerializedName("has_share_card") | |||||
| private Boolean hasShareCard; | |||||
| public static WxUserCardListResult fromJson(String json) { | |||||
| return WxMpGsonBuilder.create().fromJson(json, WxUserCardListResult.class); | |||||
| } | |||||
| @Override | |||||
| public String toString() { | |||||
| return WxMpGsonBuilder.create().toJson(this); | |||||
| } | |||||
| } | |||||
| @@ -596,6 +596,11 @@ public interface WxMpApiUrl { | |||||
| * 设置自助核销接口 | * 设置自助核销接口 | ||||
| */ | */ | ||||
| CARD_SELF_CONSUME_CELL_SET(API_DEFAULT_HOST_URL, "/card/selfconsumecell/set"), | CARD_SELF_CONSUME_CELL_SET(API_DEFAULT_HOST_URL, "/card/selfconsumecell/set"), | ||||
| /** | |||||
| * 获取用户已领取卡券接口 | |||||
| */ | |||||
| CARD_USER_CARD_LIST(API_DEFAULT_HOST_URL, "/card/user/getcardlist"), | |||||
| ; | ; | ||||
| private String prefix; | private String prefix; | ||||
| @@ -227,4 +227,13 @@ public class WxMpCardServiceImplTest { | |||||
| @Test | @Test | ||||
| public void testCreateLandingPage() { | public void testCreateLandingPage() { | ||||
| } | } | ||||
| @Test | |||||
| public void testGetUserCardList() throws WxErrorException { | |||||
| String openId = "ou7Gr5sJZgFGgj38sRCNQg5pc3Fc"; | |||||
| String cardId = "pu7Gr5secJXPkxBeuYUhmp8TYsuY"; | |||||
| WxUserCardListResult result = this.wxService.getCardService().getUserCardList(openId, cardId); | |||||
| assertTrue(result.isSuccess()); | |||||
| System.out.println(result); | |||||
| } | |||||
| } | } | ||||