新增公众号模板消息发送
This commit is contained in:
parent
e8bdc1ace5
commit
9e10c9bdff
@ -0,0 +1,57 @@
|
||||
package ink.wgink.module.wechat.controller.api.official.account;
|
||||
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.module.wechat.pojo.vos.official.account.OfficialAccountTemplateMessageSendVO;
|
||||
import ink.wgink.module.wechat.service.official.account.IOfficialAccountTemplateMessageService;
|
||||
import ink.wgink.pojo.result.SuccessResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: OfficialAccountDemoController
|
||||
* @Description: 公众号Demo
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/9/30 10:58 上午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "公众号")
|
||||
@RestController
|
||||
@RequestMapping(ISystemConstant.API_PREFIX + "/official/account")
|
||||
public class OfficialAccountDemoController {
|
||||
|
||||
@Autowired
|
||||
private IOfficialAccountTemplateMessageService officialAccountTemplateMessageService;
|
||||
|
||||
@GetMapping("send")
|
||||
public SuccessResult send() {
|
||||
OfficialAccountTemplateMessageSendVO officialAccountTemplateMessageSendVO = new OfficialAccountTemplateMessageSendVO();
|
||||
officialAccountTemplateMessageSendVO.setTouser("oXtnkwxZGEccnCVitqEcFV6TyNvM");
|
||||
officialAccountTemplateMessageSendVO.setTemplate_id("K5MLWBBVBE30bIo1cc04nYoePRWN5wlqlWDU9x5lxc4");
|
||||
Map<String, OfficialAccountTemplateMessageSendVO.Data> data = new HashMap<>();
|
||||
|
||||
OfficialAccountTemplateMessageSendVO.Data startTime = new OfficialAccountTemplateMessageSendVO.Data();
|
||||
startTime.setValue("2021-10-01");
|
||||
|
||||
OfficialAccountTemplateMessageSendVO.Data endTime = new OfficialAccountTemplateMessageSendVO.Data();
|
||||
endTime.setValue("2021-10-07");
|
||||
|
||||
OfficialAccountTemplateMessageSendVO.Data remarks = new OfficialAccountTemplateMessageSendVO.Data();
|
||||
remarks.setValue("敬请期待");
|
||||
|
||||
data.put("startTime", startTime);
|
||||
data.put("endTime", endTime);
|
||||
data.put("remarks", remarks);
|
||||
|
||||
officialAccountTemplateMessageSendVO.setData(data);
|
||||
|
||||
officialAccountTemplateMessageService.send(officialAccountTemplateMessageSendVO);
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package ink.wgink.module.wechat.pojo.vos.official.account;
|
||||
|
||||
import ink.wgink.annotation.CheckBeanAnnotation;
|
||||
import ink.wgink.annotation.CheckEmptyAnnotation;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: TemplateMessageSendVO
|
||||
* @Description: 模板消息发送
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/9/30 9:51 上午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class OfficialAccountTemplateMessageSendVO {
|
||||
|
||||
@CheckEmptyAnnotation(name = "touser", value = "接收者openid")
|
||||
private String touser;
|
||||
@CheckEmptyAnnotation(name = "template_id", value = "模板ID")
|
||||
private String template_id;
|
||||
private String url;
|
||||
@CheckBeanAnnotation
|
||||
private Miniapp miniprogram;
|
||||
private Map<String, Data> data;
|
||||
|
||||
public String getTouser() {
|
||||
return touser == null ? "" : touser.trim();
|
||||
}
|
||||
|
||||
public void setTouser(String touser) {
|
||||
this.touser = touser;
|
||||
}
|
||||
|
||||
public String getTemplate_id() {
|
||||
return template_id == null ? "" : template_id.trim();
|
||||
}
|
||||
|
||||
public void setTemplate_id(String template_id) {
|
||||
this.template_id = template_id;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url == null ? "" : url.trim();
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public Miniapp getMiniprogram() {
|
||||
return miniprogram;
|
||||
}
|
||||
|
||||
public void setMiniprogram(Miniapp miniprogram) {
|
||||
this.miniprogram = miniprogram;
|
||||
}
|
||||
|
||||
public Map<String, Data> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Map<String, Data> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static class Miniapp {
|
||||
@CheckEmptyAnnotation(name = "appid", value = "所需跳转到的小程序appid")
|
||||
private String appid;
|
||||
@CheckEmptyAnnotation(name = "pagepath", value = "所需跳转到小程序的具体页面路径")
|
||||
private String pagepath;
|
||||
|
||||
public String getAppid() {
|
||||
return appid == null ? "" : appid.trim();
|
||||
}
|
||||
|
||||
public void setAppid(String appid) {
|
||||
this.appid = appid;
|
||||
}
|
||||
|
||||
public String getPagepath() {
|
||||
return pagepath == null ? "" : pagepath.trim();
|
||||
}
|
||||
|
||||
public void setPagepath(String pagepath) {
|
||||
this.pagepath = pagepath;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Data {
|
||||
private String value;
|
||||
private String color;
|
||||
|
||||
public String getValue() {
|
||||
return value == null ? "" : value.trim();
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color == null ? "#000000" : color.trim();
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package ink.wgink.module.wechat.remote.official.account;
|
||||
|
||||
import ink.wgink.annotation.rpc.rest.RemoteService;
|
||||
import ink.wgink.annotation.rpc.rest.method.RemotePostMethod;
|
||||
import ink.wgink.annotation.rpc.rest.params.RemoteJsonBodyParams;
|
||||
import ink.wgink.annotation.rpc.rest.params.RemoteQueryParams;
|
||||
import ink.wgink.annotation.rpc.rest.params.RemoteServerParams;
|
||||
import ink.wgink.module.wechat.pojo.vos.official.account.OfficialAccountTemplateMessageSendVO;
|
||||
import ink.wgink.module.wechat.result.TemplateMessageWechatResult;
|
||||
|
||||
/**
|
||||
* @ClassName: ITemplateMessageRemoteService
|
||||
* @Description: 模板消息
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/9/30 9:19 上午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@RemoteService
|
||||
public interface IOfficialAccountTemplateMessageRemoteService {
|
||||
|
||||
/**
|
||||
* 发送消息模板
|
||||
*
|
||||
* @param server
|
||||
* @param accessToken
|
||||
* @param officialAccountTemplateMessageSendVO
|
||||
* @return
|
||||
*/
|
||||
@RemotePostMethod("/cgi-bin/message/template/send")
|
||||
TemplateMessageWechatResult send(@RemoteServerParams String server, @RemoteQueryParams("access_token") String accessToken, @RemoteJsonBodyParams OfficialAccountTemplateMessageSendVO officialAccountTemplateMessageSendVO);
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package ink.wgink.module.wechat.result;
|
||||
|
||||
/**
|
||||
* @ClassName: TemplateMessageWechatResult
|
||||
* @Description: 模板消息返回结果
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/9/30 9:41 上午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class TemplateMessageWechatResult extends BaseWechatResult {
|
||||
|
||||
private String msgid;
|
||||
|
||||
public String getMsgid() {
|
||||
return msgid == null ? "" : msgid.trim();
|
||||
}
|
||||
|
||||
public void setMsgid(String msgid) {
|
||||
this.msgid = msgid;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package ink.wgink.module.wechat.service.official.account;
|
||||
|
||||
import ink.wgink.module.wechat.pojo.vos.official.account.OfficialAccountTemplateMessageSendVO;
|
||||
|
||||
/**
|
||||
* @ClassName: IOfficialAccountTemplateMessageService
|
||||
* @Description: 消息模板
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/9/30 10:09 上午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface IOfficialAccountTemplateMessageService {
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*
|
||||
* @param officialAccountTemplateMessageSendVO
|
||||
*/
|
||||
void send(OfficialAccountTemplateMessageSendVO officialAccountTemplateMessageSendVO);
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package ink.wgink.module.wechat.service.official.account.impl;
|
||||
|
||||
import ink.wgink.common.base.DefaultBaseService;
|
||||
import ink.wgink.exceptions.ParamsException;
|
||||
import ink.wgink.exceptions.rpc.RemoteRequestException;
|
||||
import ink.wgink.module.wechat.manager.OfficialAccountAccessTokenManager;
|
||||
import ink.wgink.module.wechat.pojo.vos.official.account.OfficialAccountTemplateMessageSendVO;
|
||||
import ink.wgink.module.wechat.remote.official.account.IOfficialAccountTemplateMessageRemoteService;
|
||||
import ink.wgink.module.wechat.result.TemplateMessageWechatResult;
|
||||
import ink.wgink.module.wechat.service.official.account.IOfficialAccountTemplateMessageService;
|
||||
import ink.wgink.properties.wechat.official.account.OfficialAccountProperties;
|
||||
import ink.wgink.util.BeanPropertyCheckUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @ClassName: OfficialAccountTemplateMessageServiceImpl
|
||||
* @Description: 模板消息
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/9/30 10:09 上午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class OfficialAccountTemplateMessageServiceImpl extends DefaultBaseService implements IOfficialAccountTemplateMessageService {
|
||||
|
||||
@Autowired
|
||||
private IOfficialAccountTemplateMessageRemoteService officialAccountTemplateMessageRemoteService;
|
||||
@Autowired
|
||||
private OfficialAccountProperties officialAccountProperties;
|
||||
|
||||
@Override
|
||||
public void send(OfficialAccountTemplateMessageSendVO officialAccountTemplateMessageSendVO) {
|
||||
BeanPropertyCheckUtil.checkField(officialAccountTemplateMessageSendVO);
|
||||
if (officialAccountTemplateMessageSendVO.getData() == null) {
|
||||
throw new ParamsException("模板数据为空");
|
||||
}
|
||||
String accessToken = OfficialAccountAccessTokenManager.getInstance().getAccessToken().getAccessToken();
|
||||
TemplateMessageWechatResult templateMessageWechatResult = officialAccountTemplateMessageRemoteService.send(officialAccountProperties.getApiUrl(), accessToken, officialAccountTemplateMessageSendVO);
|
||||
if (templateMessageWechatResult.getErrcode() != 0) {
|
||||
throw new RemoteRequestException(templateMessageWechatResult.getErrmsg());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user