| @@ -27,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 | |||
| */ | |||
| @@ -189,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; | |||
| } | |||
| @@ -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,14 +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.WxMpCardCreateMessage; | |||
| import me.chanjar.weixin.mp.bean.card.WxMpCardCreateResult; | |||
| 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.card.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. | |||
| @@ -325,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,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,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,29 +1,16 @@ | |||
| package me.chanjar.weixin.mp.api.impl; | |||
| import org.testng.annotations.*; | |||
| 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.card.BaseInfo; | |||
| import me.chanjar.weixin.mp.bean.card.CashCard; | |||
| import me.chanjar.weixin.mp.bean.card.CashCardCreateRequest; | |||
| import me.chanjar.weixin.mp.bean.card.DateInfo; | |||
| import me.chanjar.weixin.mp.bean.card.DiscountCard; | |||
| import me.chanjar.weixin.mp.bean.card.DiscountCardCreateRequest; | |||
| import me.chanjar.weixin.mp.bean.card.GeneralCard; | |||
| import me.chanjar.weixin.mp.bean.card.GeneralCardCreateRequest; | |||
| import me.chanjar.weixin.mp.bean.card.GiftCard; | |||
| import me.chanjar.weixin.mp.bean.card.GiftCardCreateRequest; | |||
| import me.chanjar.weixin.mp.bean.card.GrouponCard; | |||
| import me.chanjar.weixin.mp.bean.card.GrouponCardCreateRequest; | |||
| import me.chanjar.weixin.mp.bean.card.Sku; | |||
| import me.chanjar.weixin.mp.bean.card.WxMpCardCreateMessage; | |||
| import me.chanjar.weixin.mp.bean.card.WxMpCardResult; | |||
| import static org.testng.AssertJUnit.*; | |||
| import me.chanjar.weixin.mp.bean.card.*; | |||
| import org.testng.annotations.Guice; | |||
| import org.testng.annotations.Test; | |||
| import static org.testng.AssertJUnit.assertEquals; | |||
| import static org.testng.AssertJUnit.assertNotNull; | |||
| /** | |||
| * 测试代码仅供参考,未做严格测试,因原接口作者并未提供单元测试代码 | |||
| @@ -210,4 +197,13 @@ public class WxMpCardServiceImplTest { | |||
| 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); | |||
| } | |||
| } | |||