Skip to content

Commit dd6452d

Browse files
authored
🆕 #3279【小程序】新增小程序推广员相关接口
1 parent 974ecf2 commit dd6452d

34 files changed

+2632
-2
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package cn.binarywang.wx.miniapp.api;
2+
3+
import cn.binarywang.wx.miniapp.bean.promoter.request.*;
4+
import cn.binarywang.wx.miniapp.bean.promoter.response.*;
5+
import me.chanjar.weixin.common.error.WxErrorException;
6+
7+
/**
8+
* 小程序推广员
9+
*
10+
* @author zhuangzibin
11+
*/
12+
public interface WxMaPromotionService {
13+
14+
/**
15+
* 管理角色接口-新增角色
16+
*
17+
* @param request 请求参数
18+
* @return WxMaPromotionAddRoleResponse
19+
*/
20+
WxMaPromotionAddRoleResponse addRole(WxMaPromotionAddRoleRequest request) throws WxErrorException;
21+
22+
/**
23+
* 管理角色接口-查询角色
24+
*
25+
* @param request 请求参数
26+
* @return WxMaPromotionGetRoleResponse
27+
*/
28+
WxMaPromotionGetRoleResponse getRole(WxMaPromotionGetRoleRequest request) throws WxErrorException;
29+
30+
/**
31+
* 管理角色接口-修改角色
32+
*
33+
* @param request 请求参数
34+
* @return WxMaPromotionUpdateRoleResponse
35+
*/
36+
WxMaPromotionUpdateRoleResponse updateRole(WxMaPromoterUpdateRoleRequest request) throws WxErrorException;
37+
38+
/**
39+
* 管理推广员接口-声明推广员身份
40+
*
41+
* @param request 请求参数
42+
* @return WxMaPromotionAddPromoterResponse
43+
*/
44+
WxMaPromotionAddPromoterResponse addPromoter(WxMaPromotionAddPromoterRequest request) throws WxErrorException;
45+
46+
/**
47+
* 管理推广员接口-查询推广员身份
48+
*
49+
* @param request 请求参数
50+
* @return WxMaPromotionGetPromoterResponse
51+
*/
52+
WxMaPromotionGetPromoterResponse getPromoter(WxMaPromotionGetPromoterRequest request) throws WxErrorException;
53+
54+
/**
55+
* 管理推广员接口-修改推广员身份
56+
*
57+
* @param request 请求参数
58+
* @return WxMaPromotionUpdatePromoterResponse
59+
*/
60+
WxMaPromotionUpdatePromoterResponse updatePromoter(WxMaPromotionUpdatePromoterRequest request) throws WxErrorException;
61+
62+
/**
63+
* 邀请推广员-获取推广员邀请素材
64+
*
65+
* @param request 请求参数
66+
* @return WxMaPromotionGetInvitationMaterialResponse
67+
*/
68+
WxMaPromotionGetInvitationMaterialResponse getInvitationMaterial(WxMaPromotionGetInvitationMaterialRequest request) throws WxErrorException;
69+
70+
/**
71+
* 推广员消息管理接口-群发消息
72+
*
73+
* @param request 请求参数
74+
* @return WxMaPromotionSendMsgResponse
75+
*/
76+
WxMaPromotionSendMsgResponse sendMsg(WxMaPromotionSendMsgRequest request) throws WxErrorException;
77+
78+
/**
79+
* 推广员消息管理接口-单发消息
80+
*
81+
* @param request 请求参数
82+
* @return WxMaPromotionSingleSendMsgResponse
83+
*/
84+
WxMaPromotionSingleSendMsgResponse singleSendMsg(WxMaPromotionSingleSendMsgRequest request) throws WxErrorException;
85+
86+
/**
87+
* 推广员消息管理接口-查询送达结果
88+
*
89+
* @param request 请求参数
90+
* @return WxMaPromotionGetMsgResponse
91+
*/
92+
WxMaPromotionGetMsgResponse getMsg(WxMaPromotionGetMsgRequest request) throws WxErrorException;
93+
94+
/**
95+
* 推广员消息管理接口-分析点击效果
96+
*
97+
* @param request 请求参数
98+
* @return WxMaPromotionGetMsgClickDataResponse
99+
*/
100+
WxMaPromotionGetMsgClickDataResponse getMsgClickData(WxMaPromotionGetMsgClickDataRequest request) throws WxErrorException;
101+
102+
/**
103+
* 推广数据接口-生成推广素材
104+
*
105+
* @param request 请求参数
106+
* @return WxMaPromotionGetShareMaterialResponse
107+
*/
108+
WxMaPromotionGetShareMaterialResponse getShareMaterial(WxMaPromotionGetShareMaterialRequest request) throws WxErrorException;
109+
110+
/**
111+
* 推广数据接口-分析触达效果
112+
*
113+
* @param request 请求参数
114+
* @return WxMaPromotionGetRelationResponse
115+
*/
116+
WxMaPromotionGetRelationResponse getRelation(WxMaPromotionGetRelationRequest request) throws WxErrorException;
117+
118+
/**
119+
* 推广数据接口-查询推广订单
120+
*
121+
* @param request 请求参数
122+
* @return WxMaPromotionGetOrderResponse
123+
*/
124+
WxMaPromotionGetOrderResponse getOrder(WxMaPromotionGetOrderRequest request) throws WxErrorException;
125+
}

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,4 +547,11 @@ public interface WxMaService extends WxService {
547547
*/
548548
WxMaXPayService getWxMaXPayService();
549549
WxMaExpressDeliveryReturnService getWxMaExpressDeliveryReturnService();
550+
551+
/**
552+
* 小程序推广员
553+
*
554+
* @return WxMaPromotionService
555+
*/
556+
WxMaPromotionService getWxMaPromotionService();
550557
}

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
9393
private final WxMaVodService wxMaVodService = new WxMaVodServiceImpl(this);
9494
private final WxMaXPayService wxMaXPayService = new WxMaXPayServiceImpl(this);
9595
private final WxMaExpressDeliveryReturnService wxMaExpressDeliveryReturnService = new WxMaExpressDeliveryReturnServiceImpl(this);
96+
private final WxMaPromotionService wxMaPromotionService = new WxMaPromotionServiceImpl(this);
9697

9798
private Map<String, WxMaConfig> configMap = new HashMap<>();
9899
private int retrySleepMillis = 1000;
@@ -694,4 +695,9 @@ public WxMaXPayService getWxMaXPayService() {
694695
public WxMaExpressDeliveryReturnService getWxMaExpressDeliveryReturnService() {
695696
return this.wxMaExpressDeliveryReturnService;
696697
}
698+
699+
@Override
700+
public WxMaPromotionService getWxMaPromotionService() {
701+
return this.wxMaPromotionService;
702+
}
697703
}
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
package cn.binarywang.wx.miniapp.api.impl;
2+
3+
import cn.binarywang.wx.miniapp.api.WxMaPromotionService;
4+
import cn.binarywang.wx.miniapp.api.WxMaService;
5+
import cn.binarywang.wx.miniapp.bean.promoter.request.*;
6+
import cn.binarywang.wx.miniapp.bean.promoter.response.*;
7+
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
8+
import com.google.gson.JsonObject;
9+
import lombok.RequiredArgsConstructor;
10+
import lombok.extern.slf4j.Slf4j;
11+
import me.chanjar.weixin.common.enums.WxType;
12+
import me.chanjar.weixin.common.error.WxError;
13+
import me.chanjar.weixin.common.error.WxErrorException;
14+
import me.chanjar.weixin.common.util.json.GsonParser;
15+
16+
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Promotion.*;
17+
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
18+
19+
/**
20+
* @author zhuangzibin
21+
*/
22+
@RequiredArgsConstructor
23+
@Slf4j
24+
public class WxMaPromotionServiceImpl implements WxMaPromotionService {
25+
26+
private final WxMaService wxMaService;
27+
28+
private final static Integer ERR_CODE_OF_EMPTY_LIST = 103006;
29+
30+
@Override
31+
public WxMaPromotionAddRoleResponse addRole(WxMaPromotionAddRoleRequest request) throws WxErrorException {
32+
String responseContent = this.wxMaService.post(PROMOTION_ADD_ROLE, request);
33+
JsonObject jsonObject = GsonParser.parse(responseContent);
34+
35+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
36+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
37+
}
38+
39+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionAddRoleResponse.class);
40+
}
41+
42+
@Override
43+
public WxMaPromotionGetRoleResponse getRole(WxMaPromotionGetRoleRequest request) throws WxErrorException {
44+
String responseContent = this.wxMaService.post(PROMOTION_GET_ROLE, request);
45+
JsonObject jsonObject = GsonParser.parse(responseContent);
46+
47+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
48+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
49+
}
50+
51+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetRoleResponse.class);
52+
}
53+
54+
@Override
55+
public WxMaPromotionUpdateRoleResponse updateRole(WxMaPromoterUpdateRoleRequest request) throws WxErrorException {
56+
String responseContent = this.wxMaService.post(PROMOTION_UPDATE_ROLE, request);
57+
JsonObject jsonObject = GsonParser.parse(responseContent);
58+
59+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
60+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
61+
}
62+
63+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionUpdateRoleResponse.class);
64+
}
65+
66+
@Override
67+
public WxMaPromotionAddPromoterResponse addPromoter(WxMaPromotionAddPromoterRequest request) throws WxErrorException {
68+
String responseContent = this.wxMaService.post(PROMOTION_ADD_PROMOTER, request);
69+
JsonObject jsonObject = GsonParser.parse(responseContent);
70+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
71+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
72+
}
73+
74+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionAddPromoterResponse.class);
75+
}
76+
77+
@Override
78+
public WxMaPromotionGetPromoterResponse getPromoter(WxMaPromotionGetPromoterRequest request) throws WxErrorException {
79+
String responseContent = this.wxMaService.post(PROMOTION_GET_PROMOTER, request);
80+
JsonObject jsonObject = GsonParser.parse(responseContent);
81+
82+
if (jsonObject.get(ERR_CODE).getAsInt() != 0 || jsonObject.get(ERR_CODE).getAsInt() != ERR_CODE_OF_EMPTY_LIST) {
83+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
84+
}
85+
86+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetPromoterResponse.class);
87+
}
88+
89+
@Override
90+
public WxMaPromotionUpdatePromoterResponse updatePromoter(WxMaPromotionUpdatePromoterRequest request) throws WxErrorException {
91+
String responseContent = this.wxMaService.post(PROMOTION_UPDATE_PROMOTER, request);
92+
JsonObject jsonObject = GsonParser.parse(responseContent);
93+
94+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
95+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
96+
}
97+
98+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionUpdatePromoterResponse.class);
99+
}
100+
101+
@Override
102+
public WxMaPromotionGetInvitationMaterialResponse getInvitationMaterial(WxMaPromotionGetInvitationMaterialRequest request) throws WxErrorException {
103+
String responseContent = this.wxMaService.post(PROMOTION_GET_INVITATION_MATERIAL, request);
104+
JsonObject jsonObject = GsonParser.parse(responseContent);
105+
106+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
107+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
108+
}
109+
110+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetInvitationMaterialResponse.class);
111+
}
112+
113+
@Override
114+
public WxMaPromotionSendMsgResponse sendMsg(WxMaPromotionSendMsgRequest request) throws WxErrorException {
115+
String responseContent = this.wxMaService.post(PROMOTION_SEND_MSG, request);
116+
JsonObject jsonObject = GsonParser.parse(responseContent);
117+
118+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
119+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
120+
}
121+
122+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionSendMsgResponse.class);
123+
}
124+
125+
@Override
126+
public WxMaPromotionSingleSendMsgResponse singleSendMsg(WxMaPromotionSingleSendMsgRequest request) throws WxErrorException {
127+
String responseContent = this.wxMaService.post(PROMOTION_SINGLE_SEND_MSG, request);
128+
JsonObject jsonObject = GsonParser.parse(responseContent);
129+
130+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
131+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
132+
}
133+
134+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionSingleSendMsgResponse.class);
135+
}
136+
137+
@Override
138+
public WxMaPromotionGetMsgResponse getMsg(WxMaPromotionGetMsgRequest request) throws WxErrorException {
139+
String responseContent = this.wxMaService.post(PROMOTION_GET_MSG, request);
140+
JsonObject jsonObject = GsonParser.parse(responseContent);
141+
142+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
143+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
144+
}
145+
146+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetMsgResponse.class);
147+
}
148+
149+
@Override
150+
public WxMaPromotionGetMsgClickDataResponse getMsgClickData(WxMaPromotionGetMsgClickDataRequest request) throws WxErrorException {
151+
String responseContent = this.wxMaService.post(PROMOTION_GET_MSG_CLICK_DATA, request);
152+
JsonObject jsonObject = GsonParser.parse(responseContent);
153+
154+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
155+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
156+
}
157+
158+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetMsgClickDataResponse.class);
159+
}
160+
161+
@Override
162+
public WxMaPromotionGetShareMaterialResponse getShareMaterial(WxMaPromotionGetShareMaterialRequest request) throws WxErrorException {
163+
String responseContent = this.wxMaService.post(PROMOTION_GET_SHARE_MATERIAL, request);
164+
JsonObject jsonObject = GsonParser.parse(responseContent);
165+
166+
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
167+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
168+
}
169+
170+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetShareMaterialResponse.class);
171+
}
172+
173+
@Override
174+
public WxMaPromotionGetRelationResponse getRelation(WxMaPromotionGetRelationRequest request) throws WxErrorException {
175+
String responseContent = this.wxMaService.post(PROMOTION_GET_RELATION, request);
176+
JsonObject jsonObject = GsonParser.parse(responseContent);
177+
178+
if (jsonObject.get(ERR_CODE).getAsInt() != 0 || jsonObject.get(ERR_CODE).getAsInt() != ERR_CODE_OF_EMPTY_LIST) {
179+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
180+
}
181+
182+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetRelationResponse.class);
183+
}
184+
185+
@Override
186+
public WxMaPromotionGetOrderResponse getOrder(WxMaPromotionGetOrderRequest request) throws WxErrorException {
187+
String responseContent = this.wxMaService.post(PROMOTION_GET_ORDER, request);
188+
JsonObject jsonObject = GsonParser.parse(responseContent);
189+
190+
if (jsonObject.get(ERR_CODE).getAsInt() != 0 || jsonObject.get(ERR_CODE).getAsInt() != ERR_CODE_OF_EMPTY_LIST) {
191+
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
192+
}
193+
194+
return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetOrderResponse.class);
195+
}
196+
}

0 commit comments

Comments
 (0)