Skip to content

Commit 1490800

Browse files
asushiyeBinary Wang
authored and
Binary Wang
committed
🆕 #3238 【视频号】新增会员功能相关API和消息处理 !122
1 parent 2ec6a0f commit 1490800

31 files changed

+1152
-60
lines changed

weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/BaseWxChannelMessageService.java

+64
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import me.chanjar.weixin.channel.bean.message.product.CategoryAuditMessage;
2222
import me.chanjar.weixin.channel.bean.message.product.SpuAuditMessage;
2323
import me.chanjar.weixin.channel.bean.message.supplier.SupplierItemMessage;
24+
import me.chanjar.weixin.channel.bean.message.vip.ExchangeInfoMessage;
25+
import me.chanjar.weixin.channel.bean.message.vip.UserInfoMessage;
2426
import me.chanjar.weixin.channel.message.WxChannelMessage;
2527
import me.chanjar.weixin.channel.message.WxChannelMessageRouterRule;
2628
import me.chanjar.weixin.common.session.WxSessionManager;
@@ -357,6 +359,68 @@ void qrNotify(QrNotifyMessage message, final String content, final String appId,
357359
void supplierItemUpdate(SupplierItemMessage message, final String content, final String appId,
358360
final Map<String, Object> context, final WxSessionManager sessionManager);
359361

362+
363+
/**
364+
* 用户加入会员.
365+
*
366+
* @param message the message
367+
* @param content the content
368+
* @param appId the app id
369+
* @param context the context
370+
* @param sessionManager the session manager
371+
*/
372+
public void vipJoin(UserInfoMessage message, final String content, final String appId,
373+
final Map<String, Object> context, final WxSessionManager sessionManager);
374+
375+
/**
376+
* 用户注销会员.
377+
*
378+
* @param message the message
379+
* @param content the content
380+
* @param appId the app id
381+
* @param context the context
382+
* @param sessionManager the session manager
383+
*/
384+
void vipClose(UserInfoMessage message, final String content, final String appId,
385+
final Map<String, Object> context, final WxSessionManager sessionManager);
386+
387+
/**
388+
* 用户等级更新.
389+
*
390+
* @param message the message
391+
* @param content the content
392+
* @param appId the app id
393+
* @param context the context
394+
* @param sessionManager the session manager
395+
*/
396+
void vipGradeUpdate(UserInfoMessage message, final String content, final String appId,
397+
final Map<String, Object> context, final WxSessionManager sessionManager);
398+
399+
/**
400+
* 用户积分更新.
401+
*
402+
* @param message the message
403+
* @param content the content
404+
* @param appId the app id
405+
* @param context the context
406+
* @param sessionManager the session manager
407+
*/
408+
void vipScoreUpdate(UserInfoMessage message, final String content, final String appId,
409+
final Map<String, Object> context, final WxSessionManager sessionManager);
410+
411+
/**
412+
* 用户积分兑换
413+
*
414+
* @param message the message
415+
* @param content the content
416+
* @param appId the app id
417+
* @param context the context
418+
* @param sessionManager the session manager
419+
*/
420+
void vipScoreExchange(ExchangeInfoMessage message, final String content, final String appId,
421+
final Map<String, Object> context, final WxSessionManager sessionManager);
422+
423+
360424
/**
361425
* 默认消息处理
362426
*

weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/WxChannelService.java

+7
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,11 @@ public interface WxChannelService extends BaseWxChannelService {
140140
*/
141141
WxAssistantService getAssistantService();
142142

143+
144+
/**
145+
* 会员功能
146+
*
147+
* @return 会员服务
148+
*/
149+
WxChannelVipService getVipService();
143150
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package me.chanjar.weixin.channel.api;
2+
3+
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
4+
import me.chanjar.weixin.channel.bean.vip.VipInfoResponse;
5+
import me.chanjar.weixin.channel.bean.vip.VipListResponse;
6+
import me.chanjar.weixin.channel.bean.vip.VipScoreResponse;
7+
import me.chanjar.weixin.common.error.WxErrorException;
8+
9+
/**
10+
* 视频号小店 会员功能接口
11+
*
12+
* @author <a href="https://github.com/asushiye">aushiye</a>
13+
* @link <a href="https://developers.weixin.qq.com/doc/channels/API/vip/access_guide.html">会员功能接口文档</a>
14+
*/
15+
public interface WxChannelVipService {
16+
/** 拉取用户详情 */
17+
// String VIP_USER_INFO_URL = "https://api.weixin.qq.com/channels/ec/vip/user/info/get";
18+
// /** 拉取用户列表 */
19+
// String VIP_USER_LIST_URL = "https://api.weixin.qq.com/channels/ec/vip/user/list/get";
20+
//
21+
// /** 获取用户积分 */
22+
// String VIP_SCORE_URL = "https://api.weixin.qq.com/channels/ec/vip/user/score/get";
23+
// /** 增加用户积分 */
24+
// String SCORE_INCREASE_URL = "https://api.weixin.qq.com/channels/ec/vip/user/score/increase";
25+
// /** 减少用户积分 */
26+
// String SCORE_DECREASE_URL = "https://api.weixin.qq.com/channels/ec/vip/user/score/decrease";
27+
//
28+
// /** 更新用户等级 */
29+
// String GRADE_UPDATE_URL = "https://api.weixin.qq.com/channels/ec/vip/user/grade/update";
30+
31+
32+
/**
33+
* 获取用户详情
34+
*
35+
* @param openId the open id
36+
* @param needPhoneNumber the need phone number
37+
* @return the vip info
38+
* @throws WxErrorException the wx error exception
39+
*/
40+
VipInfoResponse getVipInfo(String openId, Boolean needPhoneNumber) throws WxErrorException;
41+
42+
43+
/**
44+
* 获取用户积分
45+
*
46+
* @param needPhoneNumber the need phone number
47+
* @param pageNum the page num
48+
* @param PageSize the page size
49+
* @return the vip list
50+
* @throws WxErrorException the wx error exception
51+
*/
52+
VipListResponse getVipList(Boolean needPhoneNumber, Integer pageNum, Integer PageSize) throws WxErrorException;
53+
54+
/**
55+
* 获取用户积分
56+
*
57+
* @param openId the open id
58+
* @return the vip score
59+
* @throws WxErrorException the wx error exception
60+
*/
61+
VipScoreResponse getVipScore(String openId) throws WxErrorException;
62+
63+
/**
64+
* 增加用户积分
65+
*
66+
* @param openId the open id
67+
* @param score the score
68+
* @param remark the remark
69+
* @param requestId the request id
70+
* @return the wx channel base response
71+
* @throws WxErrorException the wx error exception
72+
*/
73+
WxChannelBaseResponse increaseVipScore(String openId, String score, String remark, String requestId) throws WxErrorException;
74+
75+
/**
76+
* 减少用户积分
77+
*
78+
* @param openId the open id
79+
* @param score the score
80+
* @param remark the remark
81+
* @param requestId the request id
82+
* @return the wx channel base response
83+
* @throws WxErrorException the wx error exception
84+
*/
85+
WxChannelBaseResponse decreaseVipScore(String openId, String score, String remark, String requestId) throws WxErrorException;
86+
87+
/**
88+
* 更新用户等级
89+
*
90+
* @param openId the open id
91+
* @param score the score
92+
* @return the wx channel base response
93+
* @throws WxErrorException the wx error exception
94+
*/
95+
WxChannelBaseResponse updateVipGrade(String openId, Integer score) throws WxErrorException;
96+
97+
}

weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/BaseWxChannelMessageServiceImpl.java

+46-33
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,5 @@
11
package me.chanjar.weixin.channel.api.impl;
22

3-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.ACCOUNT_NOTIFY;
4-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.AFTER_SALE_UPDATE;
5-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.BRAND;
6-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.COMPLAINT_NOTIFY;
7-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.CREATE_COUPON;
8-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.DELETE_COUPON;
9-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.EXPIRE_COUPON;
10-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.INVALID_COUPON;
11-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.ORDER_CANCEL;
12-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.ORDER_CONFIRM;
13-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.ORDER_DELIVER;
14-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.ORDER_EXT_INFO_UPDATE;
15-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.ORDER_NEW;
16-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.ORDER_PAY;
17-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.ORDER_SETTLE;
18-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.ORDER_STATUS_UPDATE;
19-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.PRODUCT_CATEGORY_AUDIT;
20-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.PRODUCT_SPU_AUDIT;
21-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.PRODUCT_SPU_STATUS_UPDATE;
22-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.PRODUCT_SPU_UPDATE;
23-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.QRCODE_STATUS;
24-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.RECEIVE_COUPON;
25-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.SUPPLIER_ITEM_UPDATE;
26-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.UPDATE_COUPON_INFO;
27-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.USER_COUPON_EXPIRE;
28-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.USER_COUPON_UNUSE;
29-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.USER_COUPON_USE;
30-
import static me.chanjar.weixin.channel.constant.MessageEventConstants.WITHDRAW_NOTIFY;
31-
323
import java.util.Map;
334
import lombok.extern.slf4j.Slf4j;
345
import me.chanjar.weixin.channel.api.BaseWxChannelMessageService;
@@ -53,18 +24,22 @@
5324
import me.chanjar.weixin.channel.bean.message.product.CategoryAuditMessage;
5425
import me.chanjar.weixin.channel.bean.message.product.SpuAuditMessage;
5526
import me.chanjar.weixin.channel.bean.message.supplier.SupplierItemMessage;
27+
import me.chanjar.weixin.channel.bean.message.vip.ExchangeInfoMessage;
28+
import me.chanjar.weixin.channel.bean.message.vip.UserInfoMessage;
5629
import me.chanjar.weixin.channel.message.WxChannelMessage;
5730
import me.chanjar.weixin.channel.message.WxChannelMessageRouter;
5831
import me.chanjar.weixin.channel.message.WxChannelMessageRouterRule;
5932
import me.chanjar.weixin.channel.message.rule.HandlerConsumer;
6033
import me.chanjar.weixin.channel.util.JsonUtils;
6134
import me.chanjar.weixin.common.session.WxSessionManager;
6235

36+
import static me.chanjar.weixin.channel.constant.MessageEventConstants.*;
37+
6338
/**
6439
* @author <a href="https://github.com/lixize">Zeyes</a>
6540
*/
6641
@Slf4j
67-
public class BaseWxChannelMessageServiceImpl implements BaseWxChannelMessageService {
42+
public abstract class BaseWxChannelMessageServiceImpl implements BaseWxChannelMessageService {
6843

6944
/** 消息路由器 */
7045
protected WxChannelMessageRouter router;
@@ -134,6 +109,18 @@ protected void addDefaultRule() {
134109
this.addRule(QrNotifyMessage.class, QRCODE_STATUS, this::qrNotify);
135110
/* 团长 */
136111
this.addRule(SupplierItemMessage.class, SUPPLIER_ITEM_UPDATE, this::supplierItemUpdate);
112+
113+
114+
/* 用户加入会员 */
115+
this.addRule(UserInfoMessage.class, USER_VIP_JOIN, false, this::vipJoin);
116+
/* 用户注销会员 */
117+
this.addRule(UserInfoMessage.class, USER_VIP_CLOSE,false, this::vipClose);
118+
/* 用户等级信息更新 */
119+
this.addRule(UserInfoMessage.class, USER_VIP_GRADE_INFO_UPDATE, false, this::vipGradeUpdate);
120+
/* 用户积分更新 */
121+
this.addRule(UserInfoMessage.class, USER_VIP_SCORE_UPDATE, false, this::vipScoreUpdate);
122+
/* 用户积分兑换 */
123+
this.addRule(ExchangeInfoMessage.class, USER_VIP_SCORE_EXCHANGE, false, this::vipScoreExchange);
137124
}
138125

139126
/**
@@ -144,17 +131,22 @@ protected void addDefaultRule() {
144131
* @param consumer 处理器
145132
* @param <T> 消息类型
146133
*/
147-
protected <T extends WxChannelMessage> void addRule(Class<T> clazz, String event,
148-
HandlerConsumer<T, String, String, Map<String, Object>, WxSessionManager> consumer) {
134+
protected <T extends WxChannelMessage> void addRule(Class<T> clazz, String event, Boolean async,
135+
HandlerConsumer<T, String, String, Map<String, Object>, WxSessionManager> consumer) {
149136
WxChannelMessageRouterRule<T> rule = new WxChannelMessageRouterRule<>();
150-
rule.setMessageClass(clazz).setEvent(event).setAsync(true);
137+
rule.setMessageClass(clazz).setEvent(event).setAsync(async);
151138
rule.getHandlers().add((message, content, appId, context, sessionManager) -> {
152139
consumer.accept(message, content, appId, context, sessionManager);
153140
return "success";
154141
});
155142
this.addRule(rule);
156143
}
157144

145+
protected <T extends WxChannelMessage> void addRule(Class<T> clazz, String event,
146+
HandlerConsumer<T, String, String, Map<String, Object>, WxSessionManager> consumer) {
147+
this.addRule(clazz, event, true, consumer);
148+
}
149+
158150
@Override
159151
public void addRule(WxChannelMessageRouterRule<? extends WxChannelMessage> rule) {
160152
router.getRules().add(rule);
@@ -340,4 +332,25 @@ public Object defaultMessageHandler(WxChannelMessage message, String content, St
340332
log.info("默认消息处理:{}", JsonUtils.encode(message));
341333
return null;
342334
}
335+
336+
337+
@Override
338+
public abstract void vipJoin(UserInfoMessage message, String content, String appId,
339+
Map<String, Object> context, WxSessionManager sessionManager);
340+
341+
@Override
342+
public abstract void vipClose(UserInfoMessage message, String content, String appId,
343+
Map<String, Object> context, WxSessionManager sessionManager);
344+
345+
@Override
346+
public abstract void vipGradeUpdate(UserInfoMessage message, String content, String appId,
347+
Map<String, Object> context, WxSessionManager sessionManager);
348+
349+
@Override
350+
public abstract void vipScoreUpdate(UserInfoMessage message, String content, String appId,
351+
Map<String, Object> context, WxSessionManager sessionManager);
352+
353+
@Override
354+
public abstract void vipScoreExchange(ExchangeInfoMessage message, String content, String appId,
355+
Map<String, Object> context, WxSessionManager sessionManager);
343356
}

weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/BaseWxChannelServiceImpl.java

+8-22
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,7 @@
33

44
import com.google.gson.JsonObject;
55
import lombok.extern.slf4j.Slf4j;
6-
import me.chanjar.weixin.channel.api.WxAssistantService;
7-
import me.chanjar.weixin.channel.api.WxChannelAddressService;
8-
import me.chanjar.weixin.channel.api.WxChannelAfterSaleService;
9-
import me.chanjar.weixin.channel.api.WxChannelBasicService;
10-
import me.chanjar.weixin.channel.api.WxChannelBrandService;
11-
import me.chanjar.weixin.channel.api.WxChannelCategoryService;
12-
import me.chanjar.weixin.channel.api.WxChannelCouponService;
13-
import me.chanjar.weixin.channel.api.WxChannelFreightTemplateService;
14-
import me.chanjar.weixin.channel.api.WxChannelFundService;
15-
import me.chanjar.weixin.channel.api.WxChannelOrderService;
16-
import me.chanjar.weixin.channel.api.WxChannelProductService;
17-
import me.chanjar.weixin.channel.api.WxChannelService;
18-
import me.chanjar.weixin.channel.api.WxChannelSharerService;
19-
import me.chanjar.weixin.channel.api.WxChannelWarehouseService;
20-
import me.chanjar.weixin.channel.api.WxFinderLiveService;
21-
import me.chanjar.weixin.channel.api.WxLeadComponentService;
22-
import me.chanjar.weixin.channel.api.WxLeagueProductService;
23-
import me.chanjar.weixin.channel.api.WxLeaguePromoterService;
24-
import me.chanjar.weixin.channel.api.WxLeagueSupplierService;
25-
import me.chanjar.weixin.channel.api.WxLeagueWindowService;
6+
import me.chanjar.weixin.channel.api.*;
267
import me.chanjar.weixin.channel.config.WxChannelConfig;
278
import me.chanjar.weixin.channel.util.JsonUtils;
289
import me.chanjar.weixin.common.api.WxConsts;
@@ -73,6 +54,7 @@ public abstract class BaseWxChannelServiceImpl<H, P> implements WxChannelService
7354
private WxLeadComponentService leadComponentService = null;
7455
private WxFinderLiveService finderLiveService = null;
7556
private WxAssistantService assistantService = null;
57+
private WxChannelVipService vipService = new WxChannelVipServiceImpl(this);
7658

7759
protected WxChannelConfig config;
7860
private int retrySleepMillis = 1000;
@@ -115,7 +97,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
11597
} while (!locked);
11698
String response = doGetAccessTokenRequest();
11799
return extractAccessToken(response);
118-
} catch (IOException | InterruptedException e) {
100+
} catch (WxErrorException | InterruptedException e) {
119101
throw new WxRuntimeException(e);
120102
} finally {
121103
if (locked) {
@@ -130,7 +112,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
130112
* @return .
131113
* @throws IOException .
132114
*/
133-
protected abstract String doGetAccessTokenRequest() throws IOException;
115+
protected abstract String doGetAccessTokenRequest() throws WxErrorException;
134116

135117
@Override
136118
public String get(String url, String queryParam) throws WxErrorException {
@@ -425,4 +407,8 @@ public WxAssistantService getAssistantService() {
425407
return assistantService;
426408
}
427409

410+
@Override
411+
public WxChannelVipService getVipService() {
412+
return vipService;
413+
}
428414
}

0 commit comments

Comments
 (0)