@RestController
@RequestMapping("/applet/message")
@Api(value = "小程序消息推送接口", tags = {"小程序消息推送接口"})
public class AppletSendMessageConrtoller {
@Autowired
private WxMaProperties wxMaProperties;
@Autowired
private AppletSendMessageService appletSendMessageService;
@GetMapping("/getTemplateList")
@LogAspect
@ApiOperation(value = "获取模板信息(后台使用)", notes = "获取模板信息(后台使用)", httpMethod = "GET")
public R getTemplateList() throws WxErrorException {
return appletSendMessageService.getTemplateList();
}
@GetMapping("/getTemIdByBusiness")
@ApiOperation(value = "根据业务场景获取模板id", notes = "根据业务场景获取模板id", httpMethod = "GET")
@ApiImplicitParam(name = "businessNodeList", value = "业务场景编号集合",paramType = "query",dataType = "String",allowMultiple = true)
@LogAspect
public R getTemIdByBusiness(@RequestParam("businessNodeList") String[] businessNodeList) {
return appletSendMessageService.getTemIdByBusiness(businessNodeList);
}
@PostMapping("/send")
@ApiOperation(value = "消息推送接口", notes = "消息推送接口", httpMethod = "POST")
@ApiImplicitParam(name = "activityTemplateSendVo", value = "消息实体vo",paramType = "body",dataType = "ActivityTemplateSendVo")
@LogAspect
public R sendWxMessage(@RequestBody ActivityTemplateSendVo activityTemplateSendVo) {
return appletSendMessageService.sendWxActivityMessage(activityTemplateSendVo);
}
@PostMapping("/subscrip/permit/{touser}")
@ApiOperation(value = "记录用户订阅信息是否授权接口", notes = "记录用户订阅信息是否授权接口", httpMethod = "POST")
@ApiImplicitParams({@ApiImplicitParam(name = "touser", value = "用户openId" , paramType = "path",dataType = "String"),
@ApiImplicitParam(name = "permitResult", value = "业务场景授权键值", paramType = "body",allowMultiple = true, dataType = "SubScripData"),
})
public R subscripPermitInfo(@PathVariable("touser") String touser, @RequestBody ArrayList<SubScripData> permitResult) {
return appletSendMessageService.subscripPermitInfo(touser, permitResult);
}
@PostMapping("/compensateMessage")
@ApiOperation(value = "小程序订阅消息补偿接口", notes = "小程序订阅消息补偿接口", httpMethod = "POST")
@ApiImplicitParams({@ApiImplicitParam(name = "touser",value = "用户openId"),
@ApiImplicitParam(name = "activityId", value = "活动id",paramType = "String",dataType = "String"),
@ApiImplicitParam(name = "businessNode", value = "业务场景节点编号",paramType = "String",dataType = "String"),
})
public R compensateMessage(String touser, String activityId, String businessNode) {
return appletSendMessageService.compensateMessage(touser, activityId, businessNode);
}
}
@ApiImplicitParam 注解属性:
- name : 请求中的参数。
- value : 参数的中文解释。
- paramType :传参类型(位置),可选 query,body,path,header,form。对应@requestParam,@RequestBody,@PathVariable,@requestHeader等。
- dataType :参数类型,可选基本数据类型和引用数据类型,如String,int,也可以选择自定义对象类型,如UserDto。
- allowMultiple : 是否可以传多个参数,如果为true,则表示参数为数组或集合。
@Data
@ApiModel(value = "消息发送实体对象")
public class ActivityTemplateSendVo {
//openId
private String touser;
//业务节点
private String businessNode;
private String activityId;
//中奖日期
private Date lotteryTime;
//奖品名称
private String awardName;
//发货物品名称
private String goodsName;
//发货单号
@JsonIgnore
private String expressNumber;
//收货地址
@ApiModelProperty(value = "收获地址",required = false,hidden = true)
private String receiveAddress;
//签到时间
private Date registerTime;
}
@ApiModelProperty 注解属性
- value: 字段名。
- required :是否必传参数。
- hidden:是否隐藏。
当对象参数中的个别字段不想在swagger ui中展示出来时,可以适用@JsonIgnore或者 @ApiModelProperty(value = “收获地址”,required = false,hidden = true),注意如果使用前者,则在对象序列化时该字段不会显示,即返回给前端的对象中不会显示这个字段。