Skip to content

#3279【小程序】新增小程序推广员相关接口 #3289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package cn.binarywang.wx.miniapp.api;

import cn.binarywang.wx.miniapp.bean.promoter.request.*;
import cn.binarywang.wx.miniapp.bean.promoter.response.*;
import me.chanjar.weixin.common.error.WxErrorException;

/**
* 小程序推广员
*
* @author zhuangzibin
*/
public interface WxMaPromotionService {

/**
* 管理角色接口-新增角色
*
* @param request 请求参数
* @return WxMaPromotionAddRoleResponse
*/
WxMaPromotionAddRoleResponse addRole(WxMaPromotionAddRoleRequest request) throws WxErrorException;

/**
* 管理角色接口-查询角色
*
* @param request 请求参数
* @return WxMaPromotionGetRoleResponse
*/
WxMaPromotionGetRoleResponse getRole(WxMaPromotionGetRoleRequest request) throws WxErrorException;

/**
* 管理角色接口-修改角色
*
* @param request 请求参数
* @return WxMaPromotionUpdateRoleResponse
*/
WxMaPromotionUpdateRoleResponse updateRole(WxMaPromoterUpdateRoleRequest request) throws WxErrorException;

/**
* 管理推广员接口-声明推广员身份
*
* @param request 请求参数
* @return WxMaPromotionAddPromoterResponse
*/
WxMaPromotionAddPromoterResponse addPromoter(WxMaPromotionAddPromoterRequest request) throws WxErrorException;

/**
* 管理推广员接口-查询推广员身份
*
* @param request 请求参数
* @return WxMaPromotionGetPromoterResponse
*/
WxMaPromotionGetPromoterResponse getPromoter(WxMaPromotionGetPromoterRequest request) throws WxErrorException;

/**
* 管理推广员接口-修改推广员身份
*
* @param request 请求参数
* @return WxMaPromotionUpdatePromoterResponse
*/
WxMaPromotionUpdatePromoterResponse updatePromoter(WxMaPromotionUpdatePromoterRequest request) throws WxErrorException;

/**
* 邀请推广员-获取推广员邀请素材
*
* @param request 请求参数
* @return WxMaPromotionGetInvitationMaterialResponse
*/
WxMaPromotionGetInvitationMaterialResponse getInvitationMaterial(WxMaPromotionGetInvitationMaterialRequest request) throws WxErrorException;

/**
* 推广员消息管理接口-群发消息
*
* @param request 请求参数
* @return WxMaPromotionSendMsgResponse
*/
WxMaPromotionSendMsgResponse sendMsg(WxMaPromotionSendMsgRequest request) throws WxErrorException;

/**
* 推广员消息管理接口-单发消息
*
* @param request 请求参数
* @return WxMaPromotionSingleSendMsgResponse
*/
WxMaPromotionSingleSendMsgResponse singleSendMsg(WxMaPromotionSingleSendMsgRequest request) throws WxErrorException;

/**
* 推广员消息管理接口-查询送达结果
*
* @param request 请求参数
* @return WxMaPromotionGetMsgResponse
*/
WxMaPromotionGetMsgResponse getMsg(WxMaPromotionGetMsgRequest request) throws WxErrorException;

/**
* 推广员消息管理接口-分析点击效果
*
* @param request 请求参数
* @return WxMaPromotionGetMsgClickDataResponse
*/
WxMaPromotionGetMsgClickDataResponse getMsgClickData(WxMaPromotionGetMsgClickDataRequest request) throws WxErrorException;

/**
* 推广数据接口-生成推广素材
*
* @param request 请求参数
* @return WxMaPromotionGetShareMaterialResponse
*/
WxMaPromotionGetShareMaterialResponse getShareMaterial(WxMaPromotionGetShareMaterialRequest request) throws WxErrorException;

/**
* 推广数据接口-分析触达效果
*
* @param request 请求参数
* @return WxMaPromotionGetRelationResponse
*/
WxMaPromotionGetRelationResponse getRelation(WxMaPromotionGetRelationRequest request) throws WxErrorException;

/**
* 推广数据接口-查询推广订单
*
* @param request 请求参数
* @return WxMaPromotionGetOrderResponse
*/
WxMaPromotionGetOrderResponse getOrder(WxMaPromotionGetOrderRequest request) throws WxErrorException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -547,4 +547,11 @@ public interface WxMaService extends WxService {
*/
WxMaXPayService getWxMaXPayService();
WxMaExpressDeliveryReturnService getWxMaExpressDeliveryReturnService();

/**
* 小程序推广员
*
* @return WxMaPromotionService
*/
WxMaPromotionService getWxMaPromotionService();
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
private final WxMaVodService wxMaVodService = new WxMaVodServiceImpl(this);
private final WxMaXPayService wxMaXPayService = new WxMaXPayServiceImpl(this);
private final WxMaExpressDeliveryReturnService wxMaExpressDeliveryReturnService = new WxMaExpressDeliveryReturnServiceImpl(this);
private final WxMaPromotionService wxMaPromotionService = new WxMaPromotionServiceImpl(this);

private Map<String, WxMaConfig> configMap = new HashMap<>();
private int retrySleepMillis = 1000;
Expand Down Expand Up @@ -694,4 +695,9 @@ public WxMaXPayService getWxMaXPayService() {
public WxMaExpressDeliveryReturnService getWxMaExpressDeliveryReturnService() {
return this.wxMaExpressDeliveryReturnService;
}

@Override
public WxMaPromotionService getWxMaPromotionService() {
return this.wxMaPromotionService;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package cn.binarywang.wx.miniapp.api.impl;

import cn.binarywang.wx.miniapp.api.WxMaPromotionService;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.promoter.request.*;
import cn.binarywang.wx.miniapp.bean.promoter.response.*;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;

import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Promotion.*;
import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;

/**
* @author zhuangzibin
*/
@RequiredArgsConstructor
@Slf4j
public class WxMaPromotionServiceImpl implements WxMaPromotionService {

private final WxMaService wxMaService;

private final static Integer ERR_CODE_OF_EMPTY_LIST = 103006;

@Override
public WxMaPromotionAddRoleResponse addRole(WxMaPromotionAddRoleRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_ADD_ROLE, request);
JsonObject jsonObject = GsonParser.parse(responseContent);

if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}

return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionAddRoleResponse.class);
}

@Override
public WxMaPromotionGetRoleResponse getRole(WxMaPromotionGetRoleRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_GET_ROLE, request);
JsonObject jsonObject = GsonParser.parse(responseContent);

if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}

return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetRoleResponse.class);
}

@Override
public WxMaPromotionUpdateRoleResponse updateRole(WxMaPromoterUpdateRoleRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_UPDATE_ROLE, request);
JsonObject jsonObject = GsonParser.parse(responseContent);

if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}

return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionUpdateRoleResponse.class);
}

@Override
public WxMaPromotionAddPromoterResponse addPromoter(WxMaPromotionAddPromoterRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_ADD_PROMOTER, request);
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}

return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionAddPromoterResponse.class);
}

@Override
public WxMaPromotionGetPromoterResponse getPromoter(WxMaPromotionGetPromoterRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_GET_PROMOTER, request);
JsonObject jsonObject = GsonParser.parse(responseContent);

if (jsonObject.get(ERR_CODE).getAsInt() != 0 || jsonObject.get(ERR_CODE).getAsInt() != ERR_CODE_OF_EMPTY_LIST) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}

return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetPromoterResponse.class);
}

@Override
public WxMaPromotionUpdatePromoterResponse updatePromoter(WxMaPromotionUpdatePromoterRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_UPDATE_PROMOTER, request);
JsonObject jsonObject = GsonParser.parse(responseContent);

if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}

return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionUpdatePromoterResponse.class);
}

@Override
public WxMaPromotionGetInvitationMaterialResponse getInvitationMaterial(WxMaPromotionGetInvitationMaterialRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_GET_INVITATION_MATERIAL, request);
JsonObject jsonObject = GsonParser.parse(responseContent);

if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}

return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetInvitationMaterialResponse.class);
}

@Override
public WxMaPromotionSendMsgResponse sendMsg(WxMaPromotionSendMsgRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_SEND_MSG, request);
JsonObject jsonObject = GsonParser.parse(responseContent);

if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}

return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionSendMsgResponse.class);
}

@Override
public WxMaPromotionSingleSendMsgResponse singleSendMsg(WxMaPromotionSingleSendMsgRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_SINGLE_SEND_MSG, request);
JsonObject jsonObject = GsonParser.parse(responseContent);

if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}

return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionSingleSendMsgResponse.class);
}

@Override
public WxMaPromotionGetMsgResponse getMsg(WxMaPromotionGetMsgRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_GET_MSG, request);
JsonObject jsonObject = GsonParser.parse(responseContent);

if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}

return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetMsgResponse.class);
}

@Override
public WxMaPromotionGetMsgClickDataResponse getMsgClickData(WxMaPromotionGetMsgClickDataRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_GET_MSG_CLICK_DATA, request);
JsonObject jsonObject = GsonParser.parse(responseContent);

if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}

return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetMsgClickDataResponse.class);
}

@Override
public WxMaPromotionGetShareMaterialResponse getShareMaterial(WxMaPromotionGetShareMaterialRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_GET_SHARE_MATERIAL, request);
JsonObject jsonObject = GsonParser.parse(responseContent);

if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}

return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetShareMaterialResponse.class);
}

@Override
public WxMaPromotionGetRelationResponse getRelation(WxMaPromotionGetRelationRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_GET_RELATION, request);
JsonObject jsonObject = GsonParser.parse(responseContent);

if (jsonObject.get(ERR_CODE).getAsInt() != 0 || jsonObject.get(ERR_CODE).getAsInt() != ERR_CODE_OF_EMPTY_LIST) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}

return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetRelationResponse.class);
}

@Override
public WxMaPromotionGetOrderResponse getOrder(WxMaPromotionGetOrderRequest request) throws WxErrorException {
String responseContent = this.wxMaService.post(PROMOTION_GET_ORDER, request);
JsonObject jsonObject = GsonParser.parse(responseContent);

if (jsonObject.get(ERR_CODE).getAsInt() != 0 || jsonObject.get(ERR_CODE).getAsInt() != ERR_CODE_OF_EMPTY_LIST) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
}

return WxMaGsonBuilder.create().fromJson(responseContent, WxMaPromotionGetOrderResponse.class);
}
}
Loading