Skip to content

Commit

Permalink
礼品卡API实现
Browse files Browse the repository at this point in the history
  • Loading branch information
Kit committed Sep 12, 2019
1 parent 674ae6f commit b20e09c
Show file tree
Hide file tree
Showing 16 changed files with 2,171 additions and 41 deletions.
37 changes: 23 additions & 14 deletions weixin4j-base/src/main/java/com/foxinmy/weixin4j/api/MchApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class MchApi extends BaseApi {

private final static ResourceBundle WEIXIN_BUNDLE;

private final static String PEM_CERT_PREFIX = "-----BEGIN CERTIFICATE-----";

static {
WEIXIN_BUNDLE = ResourceBundle.getBundle("com/foxinmy/weixin4j/payment/weixin");
}
Expand Down Expand Up @@ -93,21 +95,28 @@ public WeixinSignature getWeixinSignature() {
*/
protected WeixinRequestExecutor getWeixinSSLExecutor() throws WeixinException {
if (weixinSSLExecutor == null) {
try {
InputStream is = null;
File certificate = new File(
Weixin4jConfigUtil.replaceClassPathValue(weixinAccount.getCertificateFile()));
if (!certificate.exists() || !certificate.isFile()) {
is = Weixin4jConfigUtil.CLASSLOADER.getResourceAsStream(certificate.getName());
} else {
is = new FileInputStream(certificate);
}
if (is == null) {
throw new WeixinException("Invalid certificate file : " + certificate.toString());
if(weixinAccount.getCertificateFile().startsWith(PEM_CERT_PREFIX)){
// 证书是PEM格式,直接使用PEM内容生成请求执行类
this.weixinSSLExecutor = weixinExecutor.createSSLRequestExecutor(weixinAccount.getMchId(),
weixinAccount.getCertificateFile(), weixinAccount.getCertificateKey());
}else {
// 证书是p12格式,读取证书文件并生成请求执行类
try {
InputStream is = null;
File certificate = new File(
Weixin4jConfigUtil.replaceClassPathValue(weixinAccount.getCertificateFile()));
if (!certificate.exists() || !certificate.isFile()) {
is = Weixin4jConfigUtil.CLASSLOADER.getResourceAsStream(certificate.getName());
} else {
is = new FileInputStream(certificate);
}
if (is == null) {
throw new WeixinException("Invalid certificate file : " + certificate.toString());
}
this.weixinSSLExecutor = weixinExecutor.createSSLRequestExecutor(weixinAccount.getCertificateKey(), is);
} catch (IOException e) {
throw new WeixinException("IO Error on createSSLRequestExecutor", e);
}
this.weixinSSLExecutor = weixinExecutor.createSSLRequestExecutor(weixinAccount.getCertificateKey(), is);
} catch (IOException e) {
throw new WeixinException("IO Error on createSSLRequestExecutor", e);
}
}
return this.weixinSSLExecutor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ public static CouponAdvanceInfo.Builder customAdvance() {
public static MemberCard.Builder customMemberCard(){
return new MemberCard.Builder();
}

/**
* 礼品卡信息构造器
*
* @return
*/
public static GiftCard.Builder customGiftCard() {
return new GiftCard.Builder();
}

/**
* 礼品卡货架主题信息构造器
*
* @return
*/
public static PageTheme.Builder customCardPageTheme(){ return new PageTheme.Builder(); }

/**
* 礼品卡货架信息构造器
*
* @return
*/
public static GiftCardPage.Builder customCardPage(){ return new GiftCardPage.Builder(); }

/**
* 创建代金券
*
Expand Down Expand Up @@ -122,4 +146,32 @@ public static MemberCard createMemberCard(CouponBaseInfo.Builder baseBuilder, Me
MemberCard memberCard = new MemberCard(baseBuilder.build(), memberCardBudiler);
return memberCard;
}

/**
* 创建单品类礼品卡
*
* @param baseBuilder
* 卡券基础信息构造器 必填
* @param giftCardBuilder
* 礼品卡自身参数构造器 必填
* @return
*/
public static VoucherCard createVoucherCard(CouponBaseInfo.Builder baseBuilder, GiftCard.Builder giftCardBuilder){
baseBuilder.build();
VoucherCard voucherCard = new VoucherCard(baseBuilder.build(), giftCardBuilder);
return voucherCard;
}

/**
* 创建储值类礼品卡
*
* @param baseBuilder
* @param giftCardBuilder
* @return
*/
public static GiftCard createGiftCard(CouponBaseInfo.Builder baseBuilder, GiftCard.Builder giftCardBuilder){
baseBuilder.build();
GiftCard giftCard = new GiftCard(baseBuilder.build(), giftCardBuilder);
return giftCard;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package com.foxinmy.weixin4j.model.card;

import com.alibaba.fastjson.annotation.JSONField;

/**
* 已领取的礼品卡信息
* 用于查询用户的礼品卡信息时,作为参数或返回对象
*
* @author kit (kit@muses.cc)
* @date 2018-11-23
*/
public class CardInfo {
/**
* 礼品卡的code
*/
private String code;
/**
* 礼品卡的card_id
*/
@JSONField(name = "card_id")
private String cardId;
/**
* 生效时间
*/
@JSONField(name = "begin_time")
private long beginTime;
/**
* 结束时间
*/
@JSONField(name = "end_time")
private long endTime;
/**
* 当前的余额额度
*/
private int balance;
/**
* 礼品卡卡面显示的卡号,若没设置则与code相同
*/
@JSONField(name = "card_number")
private String cardNumber;
/**
* 用于支持商家激活时针对单个礼品卡分配自定义的礼品卡背景。
*/
@JSONField(name = "background_pic_url")
private String backgroundPicUrl;
/**
* 自定义金额消耗记录,不超过14个汉字。
*/
@JSONField(name = "record_balance")
private String recordBalance;
/**
* 创建时字段custom_field1定义类型的最新数值,限制为4个汉字,12字节。
*/
@JSONField(name = "custom_field_value1")
private String customFieldValue1;
/**
* 创建时字段custom_field2定义类型的最新数值,限制为4个汉字,12字节。
*/
@JSONField(name = "custom_field_value2")
private String customFieldValue2;
/**
* 创建时字段custom_field3定义类型的最新数值,限制为4个汉字,12字节。
*/
@JSONField(name = "custom_field_value3")
private String customFieldValue3;
/**
* 控制本次积分变动后转赠入口是否出现
*/
@JSONField(name = "can_give_friend")
private Boolean canGiveFriend;
/**
* 该卡的价格
*/
private int price;
/**
* 祝福语
*/
@JSONField(name = "default_gifting_msg")
private String defaultGiftingMsg;

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

public String getCardId() {
return cardId;
}

public void setCardId(String cardId) {
this.cardId = cardId;
}

public long getBeginTime() {
return beginTime;
}

public void setBeginTime(long beginTime) {
this.beginTime = beginTime;
}

public long getEndTime() {
return endTime;
}

public void setEndTime(long endTime) {
this.endTime = endTime;
}

public int getBalance() {
return balance;
}

public void setBalance(int balance) {
this.balance = balance;
}

public String getCardNumber() {
return cardNumber;
}

public void setCardNumber(String cardNumber) {
this.cardNumber = cardNumber;
}

public String getBackgroundPicUrl() {
return backgroundPicUrl;
}

public void setBackgroundPicUrl(String backgroundPicUrl) {
this.backgroundPicUrl = backgroundPicUrl;
}

public String getRecordBalance() {
return recordBalance;
}

public void setRecordBalance(String recordBalance) {
this.recordBalance = recordBalance;
}

public String getCustomFieldValue1() {
return customFieldValue1;
}

public void setCustomFieldValue1(String customFieldValue1) {
this.customFieldValue1 = customFieldValue1;
}

public String getCustomFieldValue2() {
return customFieldValue2;
}

public void setCustomFieldValue2(String customFieldValue2) {
this.customFieldValue2 = customFieldValue2;
}

public String getCustomFieldValue3() {
return customFieldValue3;
}

public void setCustomFieldValue3(String customFieldValue3) {
this.customFieldValue3 = customFieldValue3;
}

public Boolean getCanGiveFriend() {
return canGiveFriend;
}

public void setCanGiveFriend(Boolean canGiveFriend) {
this.canGiveFriend = canGiveFriend;
}

public void CardItem(){}

public void CardItem(String code, String cardId){
this.code = code;
this.cardId = cardId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.foxinmy.weixin4j.model.card;

import com.alibaba.fastjson.annotation.JSONField;

/**
* 礼品卡货架主题内的礼品卡描述项
*
* @author kit(kit.li@qq.com)
* @date 2018年10月30日
*/
public class CardItem {
/**
* 待上架的card_id
*/
@JSONField(name = "card_id")
private String cardId;
/**
* 商品名,不填写默认为卡名称
*/
private String title;
/**
* 商品缩略图,1000像素*600像素以下
*/
@JSONField(name = "pic_url")
private String picUrl;
/**
* 商品简介
*/
private String desc;

public CardItem(){

}

public CardItem(String cardId) {
this.cardId = cardId;
}

public CardItem(String cardId, String title, String picUrl, String desc) {
this.cardId = cardId;
this.title = title;
this.picUrl = picUrl;
this.desc = desc;
}

public String getCardId() {
return cardId;
}

public String getTitle() {
return title;
}

public String getPicUrl() {
return picUrl;
}

public String getDesc() {
return desc;
}

public void setCardId(String cardId) {
this.cardId = cardId;
}

public void setTitle(String title) {
this.title = title;
}

public void setPicUrl(String picUrl) {
this.picUrl = picUrl;
}

public void setDesc(String desc) {
this.desc = desc;
}
}
Loading

0 comments on commit b20e09c

Please sign in to comment.