完成会员卡的junit 。
This commit is contained in:
parent
bdf63e3fc4
commit
ec89112ce6
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j</artifactId>
|
||||
<version>1.7.3-SNAPSHOT</version>
|
||||
<version>1.7.4-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>weixin4j</name>
|
||||
<url>https://github.com/foxinmy/weixin4j</url>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j</artifactId>
|
||||
<version>1.7.3-SNAPSHOT</version>
|
||||
<version>1.7.4-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>weixin4j-base</artifactId>
|
||||
<name>weixin4j-base</name>
|
||||
|
||||
@ -20,6 +20,8 @@ public abstract class BaseApi {
|
||||
|
||||
protected final WeixinRequestExecutor weixinExecutor;
|
||||
|
||||
private final Pattern uriPattern = Pattern.compile("(\\{[^\\}]*\\})");
|
||||
|
||||
public BaseApi() {
|
||||
this.weixinExecutor = new WeixinRequestExecutor();
|
||||
}
|
||||
@ -28,8 +30,7 @@ public abstract class BaseApi {
|
||||
|
||||
protected String getRequestUri(String key) {
|
||||
String url = weixinBundle().getString(key);
|
||||
Pattern p = Pattern.compile("(\\{[^\\}]*\\})");
|
||||
Matcher m = p.matcher(url);
|
||||
Matcher m = uriPattern.matcher(url);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String sub = null;
|
||||
while (m.find()) {
|
||||
|
||||
@ -264,7 +264,7 @@
|
||||
</error>
|
||||
<error>
|
||||
<code>40073</code>
|
||||
<text>不合法的openid</text>
|
||||
<text>不合法的cardid</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>40074</code>
|
||||
|
||||
@ -115,4 +115,11 @@ public final class CardCoupons {
|
||||
GrouponCoupon coupon = new GrouponCoupon(couponBaseInfo, explain);
|
||||
return coupon;
|
||||
}
|
||||
|
||||
|
||||
public static MemberCard createMemberCard(CouponBaseInfo.Builder baseBuilder, MemberCard.Builder memberCardBudiler) {
|
||||
baseBuilder.build();
|
||||
MemberCard memberCard = new MemberCard(baseBuilder.build(), memberCardBudiler);
|
||||
return memberCard;
|
||||
}
|
||||
}
|
||||
@ -432,9 +432,13 @@ public class CouponBaseInfo implements Serializable {
|
||||
*/
|
||||
private boolean canGiveFriend;
|
||||
|
||||
/**
|
||||
* 默认永久有效
|
||||
*/
|
||||
public Builder() {
|
||||
this.sku = new JSONObject();
|
||||
this.date = new JSONObject();
|
||||
this.date.put("type",CardActiveType.DATE_TYPE_PERMANENT);
|
||||
this.useAllLocation = true;
|
||||
this.canShare = true;
|
||||
this.canGiveFriend = true;
|
||||
@ -534,6 +538,7 @@ public class CouponBaseInfo implements Serializable {
|
||||
* @return
|
||||
*/
|
||||
public Builder quantity(int quantity) {
|
||||
quantity = quantity > 100000000 ? 100000000 : quantity;
|
||||
this.sku.put("quantity", quantity);
|
||||
return this;
|
||||
}
|
||||
@ -807,7 +812,10 @@ public class CouponBaseInfo implements Serializable {
|
||||
/**
|
||||
* 表示固定时长 (自领取后按天算。
|
||||
*/
|
||||
DATE_TYPE_FIX_TERM;
|
||||
DATE_TYPE_FIX_TERM, /**
|
||||
* 永久有效
|
||||
*/
|
||||
DATE_TYPE_PERMANENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ public class MemberCard extends CardCoupon {
|
||||
* 显示余额
|
||||
*/
|
||||
@JSONField(name = "supply_balance")
|
||||
private String supplyBalance;
|
||||
private boolean supplyBalance;
|
||||
/**
|
||||
* 设置跳转外链查看余额详情。仅适用于余额无法通过激活接口同步的情况下使用该字段。
|
||||
*/
|
||||
@ -134,6 +134,7 @@ public class MemberCard extends CardCoupon {
|
||||
this.bonusRule = builder.bonusRule;
|
||||
}
|
||||
|
||||
@JSONField(serialize = false)
|
||||
@Override
|
||||
public CardType getCardType() {
|
||||
return CardType.MEMBER_CARD;
|
||||
@ -167,7 +168,7 @@ public class MemberCard extends CardCoupon {
|
||||
return bonusUrl;
|
||||
}
|
||||
|
||||
public String getSupplyBalance() {
|
||||
public boolean getSupplyBalance() {
|
||||
return supplyBalance;
|
||||
}
|
||||
|
||||
@ -248,7 +249,7 @@ public class MemberCard extends CardCoupon {
|
||||
/**
|
||||
* 显示余额
|
||||
*/
|
||||
private String supplyBalance;
|
||||
private boolean supplyBalance;
|
||||
/**
|
||||
* 设置跳转外链查看余额详情。仅适用于余额无法通过激活接口同步的情况下使用该字段。
|
||||
*/
|
||||
@ -291,92 +292,98 @@ public class MemberCard extends CardCoupon {
|
||||
private MemCardBonusRule bonusRule;
|
||||
|
||||
|
||||
public Builder setBackgroundPicUrl(String backgroundPicUrl) {
|
||||
public Builder backgroundPicUrl(String backgroundPicUrl) {
|
||||
this.backgroundPicUrl = backgroundPicUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setPrerogative(String prerogative) {
|
||||
public Builder prerogative(String prerogative) {
|
||||
this.prerogative = prerogative;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setAutoActivate(boolean autoActivate) {
|
||||
public Builder activateWithAuto(boolean autoActivate) {
|
||||
this.autoActivate = autoActivate;
|
||||
this.activateUrl = null;
|
||||
this.wxActivate = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setWxActivate(boolean wxActivate) {
|
||||
public Builder activateWithWx(boolean wxActivate) {
|
||||
this.wxActivate = wxActivate;
|
||||
this.autoActivate = false;
|
||||
this.activateUrl = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setActivateUrl(String activateUrl) {
|
||||
public Builder activateUrl(String activateUrl) {
|
||||
this.activateUrl = activateUrl;
|
||||
this.autoActivate = false;
|
||||
this.wxActivate = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSupplyBonus(boolean supplyBonus) {
|
||||
public Builder supplyBonus(boolean supplyBonus) {
|
||||
this.supplyBonus = supplyBonus;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setBonusUrl(String bonusUrl) {
|
||||
public Builder bonusUrl(String bonusUrl) {
|
||||
this.bonusUrl = bonusUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSupplyBalance(String supplyBalance) {
|
||||
public Builder supplyBalance(boolean supplyBalance) {
|
||||
this.supplyBalance = supplyBalance;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setBalanceUrl(String balanceUrl) {
|
||||
public Builder balanceUrl(String balanceUrl) {
|
||||
this.balanceUrl = balanceUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCustomField1(FieldNameType type, String name, String url) {
|
||||
public Builder customField1(FieldNameType type, String name, String url) {
|
||||
this.customField1 = new MemCardCustomField(type, name, url);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCustomField2(FieldNameType type, String name, String url) {
|
||||
public Builder customField2(FieldNameType type, String name, String url) {
|
||||
this.customField2 = new MemCardCustomField(type, name, url);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCustomField3(FieldNameType type, String name, String url) {
|
||||
public Builder customField3(FieldNameType type, String name, String url) {
|
||||
this.customField3 = new MemCardCustomField(type, name, url);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setBonusRules(String bonusRules) {
|
||||
public Builder bonusRules(String bonusRules) {
|
||||
this.bonusRules = bonusRules;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setBalanceRules(String balanceRules) {
|
||||
public Builder balanceRules(String balanceRules) {
|
||||
this.balanceRules = balanceRules;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setBonusCleared(String bonusCleared) {
|
||||
public Builder bonusCleared(String bonusCleared) {
|
||||
this.bonusCleared = bonusCleared;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCustomCell1(String name, String url, String tips) {
|
||||
public Builder customCell1(String name, String url, String tips) {
|
||||
this.customCell1 = new MemCardCustomField(name, url, tips);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setDiscount(int discount) {
|
||||
public Builder discount(int discount) {
|
||||
this.discount = discount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setBonusRule(MemCardBonusRule bonusRule) {
|
||||
public Builder bonusRule(MemCardBonusRule bonusRule) {
|
||||
this.bonusRule = bonusRule;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -84,6 +84,14 @@ public class MemberUserForm {
|
||||
this.optionalForm = formBudiler;
|
||||
}
|
||||
|
||||
public FormBudiler getRequiredForm() {
|
||||
return requiredForm;
|
||||
}
|
||||
|
||||
public FormBudiler getOptionalForm() {
|
||||
return optionalForm;
|
||||
}
|
||||
|
||||
public final static class FormBudiler {
|
||||
|
||||
/**
|
||||
@ -91,6 +99,7 @@ public class MemberUserForm {
|
||||
* 的字段是否允许用户激活后再次修改,商户设置为true
|
||||
* 时,需要接收相应事件通知处理修改事件
|
||||
*/
|
||||
@JSONField(name = "can_modify")
|
||||
private boolean canModify;
|
||||
/**
|
||||
* 自定义富文本类型,包含以下三个字段
|
||||
@ -113,7 +122,7 @@ public class MemberUserForm {
|
||||
/**
|
||||
* 自定义富文本类型
|
||||
*/
|
||||
private FormBudiler addRichField(ActivateFormFieldType fieldType, String name, String... values) {
|
||||
public FormBudiler addRichField(ActivateFormFieldType fieldType, String name, String... values) {
|
||||
if (richFieldList == null) {
|
||||
richFieldList = new JSONArray();
|
||||
}
|
||||
@ -125,6 +134,12 @@ public class MemberUserForm {
|
||||
return this;
|
||||
}
|
||||
|
||||
public FormBudiler canModify(boolean modify){
|
||||
this.canModify = canModify;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 自定义公共字段
|
||||
*/
|
||||
@ -152,8 +167,21 @@ public class MemberUserForm {
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isCanModify() {
|
||||
return canModify;
|
||||
}
|
||||
|
||||
public JSONArray getRichFieldList() {
|
||||
return richFieldList;
|
||||
}
|
||||
|
||||
public HashSet<ActivateCommonField> getCommonFieldIdList() {
|
||||
return commonFieldIdList;
|
||||
}
|
||||
|
||||
public HashSet<String> getCustomFieldList() {
|
||||
return customFieldList;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j</artifactId>
|
||||
<version>1.7.3-SNAPSHOT</version>
|
||||
<version>1.7.4-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>weixin4j-mp</artifactId>
|
||||
<name>weixin4j-mp</name>
|
||||
|
||||
@ -1,5 +1,28 @@
|
||||
package com.foxinmy.weixin4j.mp.test;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.ApiResult;
|
||||
import com.foxinmy.weixin4j.model.card.CardCoupon;
|
||||
import com.foxinmy.weixin4j.model.card.CardCoupons;
|
||||
import com.foxinmy.weixin4j.model.card.CardQR;
|
||||
import com.foxinmy.weixin4j.model.card.CouponBaseInfo;
|
||||
import com.foxinmy.weixin4j.model.card.MemberCard;
|
||||
import com.foxinmy.weixin4j.model.card.MemberInitInfo;
|
||||
import com.foxinmy.weixin4j.model.card.MemberUpdateInfo;
|
||||
import com.foxinmy.weixin4j.model.card.MemberUserForm;
|
||||
import com.foxinmy.weixin4j.model.card.MemberUserInfo;
|
||||
import com.foxinmy.weixin4j.model.qr.QRResult;
|
||||
import com.foxinmy.weixin4j.mp.api.CardApi;
|
||||
import com.foxinmy.weixin4j.mp.api.MemberCardApi;
|
||||
import com.foxinmy.weixin4j.type.card.ActivateCommonField;
|
||||
import com.foxinmy.weixin4j.type.card.ActivateFormFieldType;
|
||||
import com.foxinmy.weixin4j.type.card.CardCodeType;
|
||||
import com.foxinmy.weixin4j.type.card.CardColor;
|
||||
import com.foxinmy.weixin4j.type.card.FieldNameType;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 会员卡测试
|
||||
*
|
||||
@ -8,9 +31,104 @@ package com.foxinmy.weixin4j.mp.test;
|
||||
*/
|
||||
public class MemberCardTest extends TokenTest {
|
||||
|
||||
private CardApi cardApi;
|
||||
|
||||
public void create(){
|
||||
private MemberCardApi memberCardApi;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
cardApi = new CardApi(tokenManager);
|
||||
memberCardApi = new MemberCardApi(tokenManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* pn-YDwk59Ft0JSFdGqObxUccUQHw
|
||||
*/
|
||||
@Test
|
||||
public void create() throws WeixinException {
|
||||
CouponBaseInfo.Builder builder = CardCoupons.customBase();
|
||||
// 基础必填字段
|
||||
builder.logoUrl(
|
||||
"http://mmbiz.qpic.cn/mmbiz_jpg/LtkLicv5iclfqzGpaDqDoMibM6FcMVTrmYXjLu7bJ1tM5MzCxNONQiaZHqrYzs0fTk2T5bLAAXLpvx32hQLmJTGBxQ/0")
|
||||
.codeType(CardCodeType.CODE_TYPE_BARCODE).brandName("***").title("***会员卡").cardColor(CardColor.Color010).notice("请出示会员卡")
|
||||
.description("***的会员卡的描述").quantity(10000);
|
||||
// 基础选填字段
|
||||
builder.canShare(false).canGiveFriend(false);
|
||||
builder.centerTitle("卡券居中按钮").centerSubTitle("显示在入口下方的提示语");
|
||||
MemberCard.Builder memberCardBuilder = CardCoupons.customMemberCard();
|
||||
//会员卡必填字段
|
||||
// 会员卡选填字段
|
||||
memberCardBuilder.prerogative("会员卡特权说明").supplyBalance(true).supplyBonus(false).activateWithWx(true);
|
||||
memberCardBuilder.customField1(FieldNameType.FIELD_NAME_TYPE_LEVEL, "等级", null);
|
||||
memberCardBuilder.backgroundPicUrl(
|
||||
"https://mmbiz.qlogo.cn/mmbiz/2FyQ9TURqmdibM6nYBiagZT49lSlY9Aicw4P3vsoa7dEZIYfNkiaMyzNVYT9jmYhjBbeC8jnkibwbibB5tghC5XcgysQ/0?wx_fmt=jpeg");
|
||||
|
||||
MemberCard memberCard = CardCoupons.createMemberCard(builder, memberCardBuilder);
|
||||
String cardId = memberCardApi.createCardCoupon(memberCard);
|
||||
System.out.println(cardId);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void createCardQR() throws WeixinException {
|
||||
CardQR.Builder builder = new CardQR.Builder("pn-YDwk59Ft0JSFdGqObxUccUQHw");
|
||||
QRResult qrResult = memberCardApi.createCardQR(36000, builder.build());
|
||||
String showUrl = qrResult.getShowUrl();
|
||||
System.out.println(showUrl);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setMemberUserForm() throws WeixinException {
|
||||
MemberUserForm memberUserForm = new MemberUserForm();
|
||||
memberUserForm.setCardId("pn-YDwk59Ft0JSFdGqObxUccUQHw");
|
||||
MemberUserForm.FormBudiler requiredForm = new MemberUserForm.FormBudiler();
|
||||
requiredForm.canModify(false);
|
||||
requiredForm.addCommonField(ActivateCommonField.USER_FORM_INFO_FLAG_EMAIL, ActivateCommonField.USER_FORM_INFO_FLAG_BIRTHDAY,
|
||||
ActivateCommonField.USER_FORM_INFO_FLAG_MOBILE)
|
||||
.addRichField(ActivateFormFieldType.FORM_FIELD_CHECK_BOX, "checkBox", "value1", "value2", "value3");
|
||||
|
||||
memberUserForm.setRequiredForm(requiredForm);
|
||||
MemberUserForm.FormBudiler optionalFormBuilder = new MemberUserForm.FormBudiler();
|
||||
optionalFormBuilder.canModify(false);
|
||||
optionalFormBuilder.addCommonField(ActivateCommonField.USER_FORM_INFO_FLAG_IDCARD)
|
||||
.addRichField(ActivateFormFieldType.FORM_FIELD_CHECK_BOX, "checkBoxOPt", "value1", "value2", "value3");
|
||||
memberUserForm.setOptionalForm(optionalFormBuilder);
|
||||
memberUserForm.setServiceStatement("会员守则","https://www.baidu.com");
|
||||
ApiResult apiResult = memberCardApi.setActivateUserForm(memberUserForm);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getMemberUserInfo() throws WeixinException {
|
||||
MemberUserInfo memberUserInfo = memberCardApi.getMemberUserInfo("pn-YDwk59Ft0JSFdGqObxUccUQHw", "270869833860");
|
||||
System.out.println(memberUserInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initMemberUser() throws WeixinException {
|
||||
MemberInitInfo memberInitInfo = new MemberInitInfo();
|
||||
memberInitInfo.setCardId("pn-YDwk59Ft0JSFdGqObxUccUQHw");
|
||||
memberInitInfo.setCode("270869833860");
|
||||
memberInitInfo.setBackgroundPicUrl("https://mmbiz.qlogo.cn/mmbiz/2FyQ9TURqmdibM6nYBiagZT49lSlY9Aicw4HnSKzouD9iaksVA8vIbFT3RuqnWDVMNZib21NDdwKn5OMVMwfSsULXGw/0?wx_fmt=jpeg");
|
||||
memberInitInfo.setInit_custom_field_value1("铂金");
|
||||
memberInitInfo.setInitBalance(2);
|
||||
memberInitInfo.setInitBonus(2);
|
||||
memberInitInfo.setInitBonusRecord("初始化积分");
|
||||
ApiResult activate = memberCardApi.activate(memberInitInfo);
|
||||
System.out.println(activate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateMmemberUser() throws WeixinException {
|
||||
MemberUpdateInfo memberUpdateInfo = new MemberUpdateInfo();
|
||||
memberUpdateInfo.setCardId("pn-YDwk59Ft0JSFdGqObxUccUQHw");
|
||||
memberUpdateInfo.setCode("270869833860");
|
||||
memberUpdateInfo.setAddBalance(20);
|
||||
memberUpdateInfo.setRecordBalance("充值");
|
||||
memberUpdateInfo.setNOtify(true,true);
|
||||
memberUpdateInfo.setCustomFieldValue1("至尊铂金",true);
|
||||
memberCardApi.updateUserInfo(memberUpdateInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.foxinmy</groupId>
|
||||
<artifactId>weixin4j</artifactId>
|
||||
<version>1.7.3-SNAPSHOT</version>
|
||||
<version>1.7.4-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>weixin4j-qy</artifactId>
|
||||
<name>weixin4j-qy</name>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user