记得上下班打卡 | git大法好,push需谨慎

Commit bf16e5f5 authored by jiangxiulong's avatar jiangxiulong

openSend完善100

parent 86190c0c
......@@ -140,4 +140,18 @@ public class WechatMaConfigure {
}
return null;
}
public String getWxMaAppid(Integer anum) {
switch (anum) {
case 4:
return appletAppidZhengzai;
case 1:
return appletAppidStrawberry;
case 2:
return appletAppidFive;
case 3:
return appletAppidMdsk;
}
return "";
}
}
......@@ -17,25 +17,29 @@ public class SweetOpenSendMsgParam implements Serializable {
@NotNull(message = "sendTargetType不能为空") @Min(value = 1, message = "sendTargetType无效") @Max(value = 2, message = "sendTargetType无效")
private Integer sendTargetType;
@ApiModelProperty(position = 12, required = true, value = "模版消息ID", example = "")
@ApiModelProperty(position = 12, required = true, value = "模版消息ID", example = "y-j82V1TYhlTH1j8QscuDPcPQtNiDtENb7N5IZMBvqU")
@NotBlank(message = "templateId不能为空")
private String templateId;
@ApiModelProperty(position = 13, required = true, value = "模版消息数据", example = "{\"sendTargetType\": 1, \"jumpType\": \"5\"}")
@ApiModelProperty(position = 13, required = true, value = "模版消息数据", example = "{\"first\": \"感谢关注「正在现场」服务号\", \"keyword2\": \"4006-310-750\"}")
@NotBlank(message = "templateData不能为空")
private String templateData;
@ApiModelProperty(position = 14, required = true, allowableValues = "1,2,3,4,5", value = "点击跳转类型 1草莓小程序 2五百里小程序 3mdsk小程序 4正在小程序 5url", example = "")
@ApiModelProperty(position = 14, required = true, allowableValues = "1,2,3,4,5", value = "点击跳转类型 1草莓小程序 2五百里小程序 3mdsk小程序 4正在小程序 5url")
@NotNull(message = "jumpType不能为空") @Min(value = 1, message = "jumpType无效") @Max(value = 5, message = "jumpType无效")
private Integer jumpType;
@ApiModelProperty(position = 15, value = "跳转url", example = "www.zhengzai.tv")
private String jumpUrl;
@ApiModelProperty(position = 16, allowableValues = "false,true", value = "是否需要前端配合处理跳转", example = "false")
@ApiModelProperty(position = 16, allowableValues = "false,true", value = "是否需要前端配合处理跳转,直接跳转jumpAppletPagePath为false,true时需要前端根据状态码做跳转处理")
private Boolean jumpAppletUsePath;
@ApiModelProperty(position = 17, value = "跳转小程序需要的某页地址", example = "pages/webview?query=lottery")
private String jumpAppletPagePath;
@ApiModelProperty(position = 18, required = true, value = "openId", example = "oUpkkuNe4yuVs77aaKFvuvpgNOSw")
@NotBlank(message = "openId不能为空")
private String openId;
}
package com.liquidnet.service.sweet.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.commons.lang.util.CollectionUtil;
......@@ -8,6 +9,7 @@ import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.kylin.constant.KylinRedisConst;
import com.liquidnet.service.kylin.dto.vo.middle.KylinTicketTimesVo;
import com.liquidnet.service.kylin.dto.vo.mongo.KylinPerformanceVo;
import com.liquidnet.service.sweet.config.WechatMaConfigure;
import com.liquidnet.service.sweet.config.WechatMpConfigure;
import com.liquidnet.service.sweet.entity.SweetRemind;
import com.liquidnet.service.sweet.entity.SweetWechatUser;
......@@ -28,6 +30,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* <p>
......@@ -58,8 +61,28 @@ public class SweetWechatTemplateServiceImpl {
@Autowired
WechatMpConfigure wechatMpConfigure;
@Autowired
WechatMaConfigure wechatMaConfigure;
public ResponseDto openSendMsg(SweetOpenSendMsgParam param) {
return ResponseDto.success();
WxMpTemplateMessage templateMessage = null;
if (param.getJumpType() == 5) {
templateMessage = getTemplateMessage(param.getTemplateId(), param.getOpenId(), param.getJumpUrl());
} else {
templateMessage = getTemplateMessage(param.getTemplateId(), param.getOpenId(), param.getJumpType(), param.getJumpAppletPagePath(), param.getJumpAppletUsePath());
}
// 添加模板数据
String templateData = param.getTemplateData();
JSONObject templateDataJObj = JSONObject.parseObject(templateData);
for (Map.Entry<String, Object> entry : templateDataJObj.entrySet()) {
templateMessage.addData(new WxMpTemplateData(entry.getKey(), String.valueOf(entry.getValue())));
}
String msgId = sendTmpMsg(templateMessage, param.getSendTargetType());
if (null == msgId) {
return ResponseDto.failure("模版消息发送失败");
} else {
return ResponseDto.success(msgId);
}
}
public ResponseDto sendRemindMsg() {
......@@ -189,7 +212,6 @@ public class SweetWechatTemplateServiceImpl {
.build();
return templateMessage;
}
private WxMpTemplateMessage getTemplateMessage(String templateId, String openId, String appid, String pagePath) {
//配置小程序信息
WxMpTemplateMessage.MiniProgram miniProgram = new WxMpTemplateMessage.MiniProgram();
......@@ -204,6 +226,20 @@ public class SweetWechatTemplateServiceImpl {
.build();
return templateMessage;
}
private WxMpTemplateMessage getTemplateMessage(String templateId, String openId, Integer jumpType, String jumpAppletPagePath, Boolean jumpAppletUsePath) {
//配置小程序信息
WxMpTemplateMessage.MiniProgram miniProgram = new WxMpTemplateMessage.MiniProgram();
miniProgram.setAppid(wechatMaConfigure.getWxMaAppid(jumpType));//小程序appid
miniProgram.setUsePath(jumpAppletUsePath);//true的话需要前端配合处理跳转
miniProgram.setPagePath(jumpAppletPagePath);//用户点击时需要跳转的小程序页面
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
.toUser(openId) // 接收者openid
.templateId(templateId) // 模板id
.miniProgram(miniProgram) // 模板跳转链接
.build();
return templateMessage;
}
/**
* 发送消息
......@@ -225,6 +261,20 @@ public class SweetWechatTemplateServiceImpl {
}
return msgId;
}
private String sendTmpMsg(WxMpTemplateMessage templateMessage, Integer sendTargetType) {
String msgId = null;
try {
// 发送模板消息
WxMpService wxMpService = wechatMpConfigure.getWxMpService(sendTargetType);
log.info("sendTmpMsg-isAccessTokenExpired:[{}] ", wxMpService.getWxMpConfigStorage().isAccessTokenExpired());
log.info("sendTmpMsg-getAccessToken:[{}] ", wxMpService.getWxMpConfigStorage().getAccessToken());
msgId = wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
log.info("模版消息发送成功:[msgId=[{}]", msgId);
} catch (WxErrorException e) {
log.error("模版消息发送异常", e);
}
return msgId;
}
public ResponseDto remind(String openId, String unionId, String performancesId) {
redisDataUtils.setSweetRemind(openId, unionId, performancesId);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment