【代码评审】SYSTEM:微信小程序的订阅消息
This commit is contained in:
parent
b917d92af5
commit
7f87f26f3a
|
@ -15,7 +15,10 @@ public interface MessageTemplateConstants {
|
|||
|
||||
//======================= 订阅消息模版 =======================
|
||||
|
||||
// TODO @puhui999:建议 TRADE_AFTER_SALE_CHANGE
|
||||
String ORDER_AFTERSALE_CHANGE = "售后进度通知";
|
||||
|
||||
// TODO @puhui999:是不是改成 PAY_WALLET_CHANGE 放在 PAY 模块
|
||||
String MONEY_CHANGE = "充值成功通知";
|
||||
|
||||
}
|
||||
|
|
|
@ -8,10 +8,7 @@ import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
|
|||
import cn.iocoder.yudao.module.member.controller.app.social.vo.*;
|
||||
import cn.iocoder.yudao.module.system.api.social.SocialClientApi;
|
||||
import cn.iocoder.yudao.module.system.api.social.SocialUserApi;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxQrcodeReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.social.dto.*;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
@ -74,7 +71,8 @@ public class AppSocialUserController {
|
|||
@GetMapping("/get-subscribe-template")
|
||||
@Operation(summary = "获得微信小程订阅模板")
|
||||
public CommonResult<List<AppSocialWxSubscribeTemplateRespVO>> getSubscribeTemplate() {
|
||||
return success(BeanUtils.toBean(socialClientApi.getSubscribeTemplate(), AppSocialWxSubscribeTemplateRespVO.class));
|
||||
List<SocialWxSubscribeTemplateRespDTO> template = socialClientApi.getSubscribeTemplate();
|
||||
return success(BeanUtils.toBean(template, AppSocialWxSubscribeTemplateRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,19 +7,22 @@ import lombok.Data;
|
|||
@Data
|
||||
public class AppSocialWxSubscribeTemplateRespVO {
|
||||
|
||||
@Schema(description = "添加至账号下的模板 id,发送小程序订阅消息时所需", requiredMode = Schema.RequiredMode.REQUIRED, example = "9Aw5ZV1j9xdWTFEkqCpZ7mIBbSC34khK55OtzUPl0rU")
|
||||
// TODO @puhui999:是不是使用 id 作为字段,更干净些哈;
|
||||
@Schema(description = "模版编号", requiredMode = Schema.RequiredMode.REQUIRED,
|
||||
example = "9Aw5ZV1j9xdWTFEkqCpZ7mIBbSC34khK55OtzUPl0rU")
|
||||
private String priTmplId;
|
||||
|
||||
@Schema(description = "模版标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "订单支付通知")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "模版内容", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(description = "模版内容", requiredMode = Schema.RequiredMode.REQUIRED,
|
||||
example = "{ {result.DATA} }\\n\\n领奖金额:{ {withdrawMoney.DATA} }\\n领奖时间: { {withdrawTime.DATA} }")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "模板内容示例", requiredMode = Schema.RequiredMode.REQUIRED, example = "下单时间:2016年8月8日")
|
||||
private String example;
|
||||
|
||||
@Schema(description = "模版类型,2 为一次性订阅,3 为长期订阅", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private Integer type;
|
||||
@Schema(description = "模版类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private Integer type; // 2 为一次性订阅,3 为长期订阅
|
||||
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public interface SocialClientApi {
|
|||
List<SocialWxSubscribeTemplateRespDTO> getSubscribeTemplate();
|
||||
|
||||
/**
|
||||
* 发送订阅消息
|
||||
* 发送微信小程序订阅消息
|
||||
*
|
||||
* @param reqDTO 请求
|
||||
*/
|
||||
|
|
|
@ -6,6 +6,7 @@ import lombok.Data;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
// TODO @puhui99:1)参考 SocialWxQrcodeReqDTO,可以 @see 文档。这样,注释会更见见一点。2)是不是少了 Send:SocialWxSubscribeMessageSendReqDTO
|
||||
/**
|
||||
* 微信小程序订阅消息 Request DTO
|
||||
*
|
||||
|
@ -14,6 +15,7 @@ import java.util.List;
|
|||
@Data
|
||||
public class SocialWxSubscribeMessageReqDTO {
|
||||
|
||||
// TODO @puhui999:参数校验
|
||||
/**
|
||||
* 接收者(用户)的 openid.
|
||||
* <pre>
|
||||
|
@ -58,6 +60,7 @@ public class SocialWxSubscribeMessageReqDTO {
|
|||
*/
|
||||
private String lang;
|
||||
|
||||
// TODO @puhui999:是必须 List<KeyValue<String, String>>,还是 Map<String, String 即可)
|
||||
/**
|
||||
* 模板内容,不填则下发空模板.
|
||||
* <pre>
|
||||
|
|
|
@ -11,6 +11,7 @@ import lombok.Data;
|
|||
@Data
|
||||
public class SocialWxSubscribeTemplateRespDTO {
|
||||
|
||||
// TODO @puhui999:建议搞成 id
|
||||
/**
|
||||
* 添加至账号下的模板 id,发送小程序订阅消息时所需
|
||||
*/
|
||||
|
@ -31,8 +32,12 @@ public class SocialWxSubscribeTemplateRespDTO {
|
|||
*/
|
||||
private String example;
|
||||
|
||||
// TODO @puhui999:这个在 wxjava 里面,有枚举字段么?
|
||||
/**
|
||||
* 模版类型,2 为一次性订阅,3 为长期订阅
|
||||
* 模版类型
|
||||
*
|
||||
* 2 为一次性订阅
|
||||
* 3 为长期订阅
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
|
|
|
@ -72,6 +72,7 @@ public class SocialClientController {
|
|||
|
||||
//======================= TODO 测试发送订阅消息 =======================
|
||||
|
||||
// TODO @puhui999:这个接口,其实可以留着。然后把参数挪到 .http 文件。先直接用 SocialWxSubscribeMessageReqDTO 接参数
|
||||
@PostMapping("/send-subscribe-message")
|
||||
public void testSendSubscribeMessage() {
|
||||
SocialWxSubscribeMessageReqDTO reqDTO = new SocialWxSubscribeMessageReqDTO().setLang("zh_CN")
|
||||
|
|
|
@ -81,7 +81,7 @@ public interface SocialClientService {
|
|||
List<TemplateInfo> getSubscribeTemplate();
|
||||
|
||||
/**
|
||||
* 发送订阅消息
|
||||
* 发送微信小程序订阅消息
|
||||
*
|
||||
* @param reqDTO 请求
|
||||
*/
|
||||
|
|
|
@ -236,6 +236,7 @@ public class SocialClientServiceImpl implements SocialClientService {
|
|||
try {
|
||||
return service.getUserService().getPhoneNoInfo(phoneCode);
|
||||
} catch (WxErrorException e) {
|
||||
// TODO @puhui999:这里的日志,reqDTO 要打进去
|
||||
log.error("[getPhoneNoInfo][userType({}) phoneCode({}) 获得手机号失败]", userType, phoneCode, e);
|
||||
throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR);
|
||||
}
|
||||
|
@ -262,11 +263,12 @@ public class SocialClientServiceImpl implements SocialClientService {
|
|||
|
||||
@Override
|
||||
public List<TemplateInfo> getSubscribeTemplate() {
|
||||
// TODO @puhui999:这个 userType 最好通过参数,传递过来;然后这个方法名,貌似叫 getSubscribeTemplateList 更合适哈;
|
||||
WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue());
|
||||
try {
|
||||
WxMaSubscribeService subscribeService = service.getSubscribeService();
|
||||
return subscribeService.getTemplateList();
|
||||
}catch (WxErrorException e) {
|
||||
} catch (WxErrorException e) {
|
||||
log.error("[getSubscribeTemplate][获得小程序订阅消息模版]", e);
|
||||
throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_TEMPLATE_ERROR);
|
||||
}
|
||||
|
@ -274,13 +276,15 @@ public class SocialClientServiceImpl implements SocialClientService {
|
|||
|
||||
@Override
|
||||
public void sendSubscribeMessage(SocialWxSubscribeMessageReqDTO reqDTO) {
|
||||
// TODO @puhui999:这个 userType 最好通过参数,
|
||||
WxMaService service = getWxMaService(UserTypeEnum.MEMBER.getValue());
|
||||
try {
|
||||
WxMaSubscribeService subscribeService = service.getSubscribeService();
|
||||
WxMaSubscribeMessage message = BeanUtils.toBean(reqDTO, WxMaSubscribeMessage.class);
|
||||
reqDTO.getMessages().forEach(item-> message.addData(new WxMaSubscribeMessage.MsgData(item.getKey(), item.getValue())));
|
||||
subscribeService.sendSubscribeMsg(message);
|
||||
}catch (WxErrorException e) {
|
||||
} catch (WxErrorException e) {
|
||||
// TODO @puhui999:这里的日志,reqDTO 要打进去
|
||||
log.error("[sendSubscribeMessage][发送小程序订阅消息]", e);
|
||||
throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_MESSAGE_ERROR);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue