Skip to content

Commit f90f72f

Browse files
yuanqixunbinarywang
authored andcommitted
#733 微信卡券增加会员卡新增,卡券二维码,添加白名单,新增卡券货架等接口
1 parent b327724 commit f90f72f

28 files changed

+1531
-29
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
import me.chanjar.weixin.common.bean.WxCardApiSignature;
44
import me.chanjar.weixin.common.error.WxErrorException;
5+
import me.chanjar.weixin.mp.bean.card.WxMpCardLandingPageCreateRequest;
6+
import me.chanjar.weixin.mp.bean.card.WxMpCardLandingPageCreateResult;
7+
import me.chanjar.weixin.mp.bean.card.WxMpCardQrcodeCreateResult;
58
import me.chanjar.weixin.mp.bean.result.WxMpCardResult;
69

710
/**
811
* 卡券相关接口
912
*
1013
* @author YuJian(mgcnrx11@hotmail.com) on 01/11/2016
14+
* @author yuanqixun 2018-08-29
1115
*/
1216
public interface WxMpCardService {
1317
String CARD_GET = "https://api.weixin.qq.com/card/get";
@@ -16,6 +20,9 @@ public interface WxMpCardService {
1620
String CARD_CODE_GET = "https://api.weixin.qq.com/card/code/get";
1721
String CARD_CODE_CONSUME = "https://api.weixin.qq.com/card/code/consume";
1822
String CARD_CODE_MARK = "https://api.weixin.qq.com/card/code/mark";
23+
String CARD_TEST_WHITELIST = "https://api.weixin.qq.com/card/testwhitelist/set";
24+
String CARD_QRCODE_CREAET = "https://api.weixin.qq.com/card/qrcode/create";
25+
String CARD_LANDING_PAGE_CREAET = "https://api.weixin.qq.com/card/landingpage/create";
1926

2027
/**
2128
* 得到WxMpService
@@ -122,4 +129,27 @@ void markCardCode(String code, String cardId, String openId, boolean isMark) thr
122129
* <br> 可由 com.google.gson.JsonParser#parse 等方法直接取JSON串中的某个字段。
123130
*/
124131
String getCardDetail(String cardId) throws WxErrorException;
132+
133+
/**
134+
* 添加测试白名单
135+
* @param openid 用户的openid
136+
* @return
137+
*/
138+
String addTestWhiteList(String openid) throws WxErrorException;
139+
140+
/**
141+
* 创建卡券二维码
142+
* @param cardId 卡券编号
143+
* @param outerStr 二维码标识
144+
* @return WxMpCardQrcodeCreateResult
145+
*/
146+
WxMpCardQrcodeCreateResult createQrcodeCard(String cardId, String outerStr) throws WxErrorException;
147+
148+
/**
149+
* 创建卡券货架
150+
* @param createRequest 货架创建参数
151+
* @return
152+
* @throws WxErrorException
153+
*/
154+
WxMpCardLandingPageCreateResult createLandingPage(WxMpCardLandingPageCreateRequest createRequest) throws WxErrorException;
125155
}

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package me.chanjar.weixin.mp.api;
22

33
import me.chanjar.weixin.common.error.WxErrorException;
4-
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardActivatedMessage;
5-
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUpdateMessage;
6-
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUpdateResult;
7-
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUserInfoResult;
4+
import me.chanjar.weixin.mp.bean.card.WxMpCardCreateResult;
5+
import me.chanjar.weixin.mp.bean.card.WxMpCardQrcodeCreateResult;
6+
import me.chanjar.weixin.mp.bean.membercard.*;
87

98
/**
109
* 会员卡相关接口
@@ -19,11 +18,27 @@ public interface WxMpMemberCardService {
1918
*/
2019
WxMpService getWxMpService();
2120

21+
/**
22+
* 会员卡创建接口
23+
* @param createJson
24+
* @return
25+
* @throws WxErrorException
26+
*/
27+
WxMpCardCreateResult createMemberCard(String createJson) throws WxErrorException;
28+
29+
/**
30+
* 会员卡创建接口
31+
* @param createMessageMessage
32+
* @return WxMpCardCreateResult
33+
* @throws WxErrorException
34+
*/
35+
WxMpCardCreateResult createMemberCard(WxMpMemberCardCreateMessage createMessageMessage) throws WxErrorException;
36+
2237
/**
2338
* 会员卡激活接口
2439
*
2540
* @param activatedMessage 激活所需参数
26-
* @return 调用返回的JSON字符串。
41+
* @return 返回json字符串
2742
* @throws WxErrorException 接口调用失败抛出的异常
2843
*/
2944
String activateMemberCard(WxMpMemberCardActivatedMessage activatedMessage) throws WxErrorException;
@@ -50,4 +65,5 @@ public interface WxMpMemberCardService {
5065
* @throws WxErrorException 接口调用失败抛出的异常
5166
*/
5267
WxMpMemberCardUpdateResult updateUserMemberCard(WxMpMemberCardUpdateMessage updateUserMessage) throws WxErrorException;
68+
5369
}

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

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package me.chanjar.weixin.mp.api.impl;
22

3-
import com.google.gson.JsonElement;
4-
import com.google.gson.JsonObject;
5-
import com.google.gson.JsonParser;
6-
import com.google.gson.JsonPrimitive;
3+
import com.google.gson.*;
74
import com.google.gson.reflect.TypeToken;
85
import me.chanjar.weixin.common.bean.WxCardApiSignature;
96
import me.chanjar.weixin.common.error.WxError;
@@ -13,6 +10,9 @@
1310
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
1411
import me.chanjar.weixin.mp.api.WxMpCardService;
1512
import me.chanjar.weixin.mp.api.WxMpService;
13+
import me.chanjar.weixin.mp.bean.card.WxMpCardLandingPageCreateRequest;
14+
import me.chanjar.weixin.mp.bean.card.WxMpCardLandingPageCreateResult;
15+
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;
1818
import org.slf4j.Logger;
@@ -30,6 +30,8 @@ public class WxMpCardServiceImpl implements WxMpCardService {
3030

3131
private WxMpService wxMpService;
3232

33+
private static final Gson GSON = new Gson();
34+
3335
public WxMpCardServiceImpl(WxMpService wxMpService) {
3436
this.wxMpService = wxMpService;
3537
}
@@ -236,4 +238,51 @@ public String getCardDetail(String cardId) throws WxErrorException {
236238

237239
return responseContent;
238240
}
241+
242+
/**
243+
* 添加测试白名单
244+
*
245+
* @param openid 用户的openid
246+
* @return
247+
*/
248+
public String addTestWhiteList(String openid) throws WxErrorException {
249+
JsonArray array = new JsonArray();
250+
array.add(openid);
251+
JsonObject jsonObject = new JsonObject();
252+
jsonObject.add("openid", array);
253+
String respone = this.wxMpService.post(CARD_TEST_WHITELIST, GSON.toJson(jsonObject));
254+
return respone;
255+
}
256+
257+
/**
258+
* 创建卡券二维码
259+
* @param cardId
260+
* @param outerStr
261+
* @return
262+
*/
263+
public WxMpCardQrcodeCreateResult createQrcodeCard(String cardId, String outerStr) throws WxErrorException {
264+
JsonObject jsonObject = new JsonObject();
265+
jsonObject.addProperty("action_name", "QR_CARD");
266+
jsonObject.addProperty("expire_seconds", 1800);
267+
JsonObject actionInfoJson = new JsonObject();
268+
JsonObject cardJson = new JsonObject();
269+
cardJson.addProperty("card_id", cardId);
270+
cardJson.addProperty("outer_str", outerStr);
271+
actionInfoJson.add("card", cardJson);
272+
jsonObject.add("action_info", actionInfoJson);
273+
String response = this.wxMpService.post(CARD_QRCODE_CREAET, GSON.toJson(jsonObject));
274+
return WxMpCardQrcodeCreateResult.fromJson(response);
275+
}
276+
277+
/**
278+
* 创建卡券货架接口
279+
* @param request
280+
* @return
281+
* @throws WxErrorException
282+
*/
283+
@Override
284+
public WxMpCardLandingPageCreateResult createLandingPage(WxMpCardLandingPageCreateRequest request) throws WxErrorException {
285+
String response = this.wxMpService.post(CARD_LANDING_PAGE_CREAET,GSON.toJson(request));
286+
return WxMpCardLandingPageCreateResult.fromJson(response);
287+
}
239288
}

0 commit comments

Comments
 (0)