mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-30 10:07:06 +08:00
#900 增加新增团购券、现金抵扣券、折扣券、兑换券以及普通优惠券的接口
This commit is contained in:
@ -2,9 +2,7 @@ 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.card.*;
|
||||
import me.chanjar.weixin.mp.bean.result.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";
|
||||
@ -142,6 +141,14 @@ public interface WxMpCardService {
|
||||
*/
|
||||
String addTestWhiteList(String openid) throws WxErrorException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cardCreateMessage
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
WxMpCardCreateResult createCard(WxMpCardCreateMessage cardCreateMessage) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 创建卡券二维码
|
||||
*
|
||||
|
||||
@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api.impl;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.card.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -22,9 +23,6 @@ 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.enums.TicketType;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
@ -265,6 +263,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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建卡券二维码.
|
||||
*/
|
||||
|
||||
@ -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,39 @@
|
||||
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 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,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 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,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 DiscountCardCreateRequest extends CardCreateRequest implements Serializable {
|
||||
@SerializedName("card_type")
|
||||
private String cardType = "DISCOUNT";
|
||||
|
||||
private DiscountCard discount;
|
||||
|
||||
@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 me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* .
|
||||
* @author leeis
|
||||
* @Date 2018/12/29
|
||||
*/
|
||||
@Data
|
||||
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,26 @@
|
||||
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 GeneralCardCreateRequest extends CardCreateRequest implements Serializable {
|
||||
@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,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 GiftCardCreateRequest extends CardCreateRequest implements Serializable {
|
||||
@SerializedName("card_type")
|
||||
private String cardType = "GIFT";
|
||||
|
||||
private GiftCard gift;
|
||||
|
||||
@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 me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* .
|
||||
* @author leeis
|
||||
* @Date 2018/12/29
|
||||
*/
|
||||
@Data
|
||||
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,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 GrouponCardCreateRequest extends CardCreateRequest implements Serializable {
|
||||
@SerializedName("card_type")
|
||||
private String cardType = "GROUPON";
|
||||
|
||||
private GrouponCard groupon;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return WxMpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -2,8 +2,10 @@ 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.card.*;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpCardResult;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
@ -100,4 +102,98 @@ 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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user