Skip to content

Commit 95e398d

Browse files
yuanqixunbinarywang
authored andcommitted
#745 增加卡券失效接口,并修复会员卡是否支持微信支付和会员卡二维码的属性问题
* 1、增加卡券失效接口;修复会员卡是否支持微信支付和会员卡二维码的属性问题;
1 parent fca9024 commit 95e398d

File tree

6 files changed

+73
-13
lines changed

6 files changed

+73
-13
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpCardService.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* 卡券相关接口
1212
*
13-
* @author YuJian(mgcnrx11@hotmail.com) on 01/11/2016
13+
* @author YuJian(mgcnrx11 @ hotmail.com) on 01/11/2016
1414
* @author yuanqixun 2018-08-29
1515
*/
1616
public interface WxMpCardService {
@@ -23,6 +23,10 @@ public interface WxMpCardService {
2323
String CARD_TEST_WHITELIST = "https://api.weixin.qq.com/card/testwhitelist/set";
2424
String CARD_QRCODE_CREAET = "https://api.weixin.qq.com/card/qrcode/create";
2525
String CARD_LANDING_PAGE_CREAET = "https://api.weixin.qq.com/card/landingpage/create";
26+
/**
27+
* 将用户的卡券设置为失效状态
28+
*/
29+
String CARD_CODE_UNAVAILABLE = "https://api.weixin.qq.com/card/code/unavailable";
2630

2731
/**
2832
* 得到WxMpService
@@ -132,33 +136,50 @@ void markCardCode(String code, String cardId, String openId, boolean isMark) thr
132136

133137
/**
134138
* 添加测试白名单
139+
*
135140
* @param openid 用户的openid
136141
* @return
137142
*/
138143
String addTestWhiteList(String openid) throws WxErrorException;
139144

140145
/**
141146
* 创建卡券二维码
142-
* @param cardId 卡券编号
147+
*
148+
* @param cardId 卡券编号
143149
* @param outerStr 二维码标识
144150
* @return WxMpCardQrcodeCreateResult
145151
*/
146152
WxMpCardQrcodeCreateResult createQrcodeCard(String cardId, String outerStr) throws WxErrorException;
147153

148154
/**
149155
* 创建卡券二维码
150-
* @param cardId 卡券编号
151-
* @param outerStr 二维码标识
156+
*
157+
* @param cardId 卡券编号
158+
* @param outerStr 二维码标识
152159
* @param expiresIn 失效时间,单位秒,不填默认365天
153160
* @return WxMpCardQrcodeCreateResult
154161
*/
155-
WxMpCardQrcodeCreateResult createQrcodeCard(String cardId, String outerStr,int expiresIn) throws WxErrorException;
162+
WxMpCardQrcodeCreateResult createQrcodeCard(String cardId, String outerStr, int expiresIn) throws WxErrorException;
156163

157164
/**
158165
* 创建卡券货架
166+
*
159167
* @param createRequest 货架创建参数
160168
* @return
161169
* @throws WxErrorException
162170
*/
163171
WxMpCardLandingPageCreateResult createLandingPage(WxMpCardLandingPageCreateRequest createRequest) throws WxErrorException;
172+
173+
/**
174+
* 将用户的卡券设置为失效状态
175+
* 详见:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1451025272&anchor=9
176+
*
177+
* @param cardId 卡券编号
178+
* @param code 用户会员卡号
179+
* @param reason 设置为失效的原因
180+
* @return
181+
* @throws WxErrorException
182+
*/
183+
String unavailableCardCode(String cardId, String code, String reason) throws WxErrorException;
184+
164185
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImpl.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import me.chanjar.weixin.mp.bean.card.WxMpCardQrcodeCreateResult;
1616
import me.chanjar.weixin.mp.bean.result.WxMpCardResult;
1717
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
18+
import org.apache.commons.lang3.StringUtils;
1819
import org.slf4j.Logger;
1920
import org.slf4j.LoggerFactory;
2021

@@ -267,8 +268,9 @@ public WxMpCardQrcodeCreateResult createQrcodeCard(String cardId, String outerSt
267268

268269
/**
269270
* 创建卡券二维码
270-
* @param cardId 卡券编号
271-
* @param outerStr 二维码标识
271+
*
272+
* @param cardId 卡券编号
273+
* @param outerStr 二维码标识
272274
* @param expiresIn 失效时间,单位秒,不填默认365天
273275
* @return
274276
* @throws WxErrorException
@@ -301,4 +303,26 @@ public WxMpCardLandingPageCreateResult createLandingPage(WxMpCardLandingPageCrea
301303
String response = this.wxMpService.post(CARD_LANDING_PAGE_CREAET, GSON.toJson(request));
302304
return WxMpCardLandingPageCreateResult.fromJson(response);
303305
}
306+
307+
/**
308+
* 将用户的卡券设置为失效状态
309+
* 详见:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1451025272&anchor=9
310+
*
311+
* @param cardId 卡券编号
312+
* @param code 用户会员卡号
313+
* @param reason 设置为失效的原因
314+
* @return
315+
* @throws WxErrorException
316+
*/
317+
@Override
318+
public String unavailableCardCode(String cardId, String code, String reason) throws WxErrorException {
319+
if (StringUtils.isAnyBlank(cardId, code, reason))
320+
throw new WxErrorException(WxError.builder().errorCode(41012).errorMsg("参数不完整").build());
321+
JsonObject jsonRequest = new JsonObject();
322+
jsonRequest.addProperty("card_id", cardId);
323+
jsonRequest.addProperty("code", code);
324+
jsonRequest.addProperty("reason", reason);
325+
String response = this.wxMpService.post(CARD_CODE_UNAVAILABLE, GSON.toJson(jsonRequest));
326+
return response;
327+
}
304328
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/card/AdvancedInfo.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ public class AdvancedInfo implements Serializable {
5656
@SerializedName("time_limit")
5757
private TimeLimit timeLimit;
5858

59+
/**
60+
* 是否可以分享朋友
61+
*/
62+
@SerializedName("share_friends")
63+
private Boolean shareFriends;
64+
5965
public void addBusinessService(BusinessServiceType businessServiceType) {
6066
if (businessServiceType != null) {
6167
if (businessServiceList == null)

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/card/BaseInfo.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public class BaseInfo implements Serializable {
3434
@SerializedName("pay_info")
3535
private PayInfo payInfo;
3636

37+
/**
38+
* 是否设置该会员卡中部的按钮同时支持微信支付刷卡和会员卡二维码
39+
*/
40+
@SerializedName("is_pay_and_qrcode")
41+
private boolean isPayAndQrcode;
42+
3743
/**
3844
* 商户名字,字数上限为12个汉字
3945
*/

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/card/SwipeCard.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ public class SwipeCard implements Serializable {
2121
@SerializedName("is_swipe_card")
2222
private boolean isSwipeCard;
2323

24-
/**
25-
* 是否设置该会员卡中部的按钮同时支持微信支付刷卡和会员卡二维码
26-
*/
27-
@SerializedName("is_pay_and_qrcode")
28-
private boolean isPayAndQrcode;
29-
3024
public String toString() {
3125
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
3226
}

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpCardServiceImplTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,13 @@ public void testGetCardDetail() throws Exception {
9191
System.out.println(result);
9292
}
9393

94+
@Test
95+
public void testUnavailableCardCode() throws Exception {
96+
String cardId = "p2iQk1luzj50RHue6yeTPQpAx_Z4";
97+
String code = "134905347310";
98+
String reason = "换成新卡了";
99+
String result = this.wxService.getCardService().unavailableCardCode(cardId, code, reason);
100+
assertNotNull(result);
101+
System.out.println(result);
102+
}
94103
}

0 commit comments

Comments
 (0)