更新sql和代码规范修改

This commit is contained in:
moxiangrong
2024-02-18 15:26:45 +08:00
parent 6f5e6e4662
commit c132b68745
1293 changed files with 43935 additions and 18456 deletions

View File

@ -36,7 +36,6 @@
</dependency>
</dependencies>
</project>

View File

@ -18,12 +18,12 @@ import lombok.Getter;
@Getter
@AllArgsConstructor
public enum WechatTempateEnum {
PAY_SUCCESS("pay_success","支付成功通知"),
DELIVERY_SUCCESS("delivery_success","发货成功通知"),
REFUND_SUCCESS("refund_success","退款成功通知"),
RECHARGE_SUCCESS("recharge_success","充值成功通知"),
TEMPLATES("template","公众号模板消息"),
SUBSCRIBE("subscribe","小程序订阅消息");
PAY_SUCCESS("pay_success", "支付成功通知"),
DELIVERY_SUCCESS("delivery_success", "发货成功通知"),
REFUND_SUCCESS("refund_success", "退款成功通知"),
RECHARGE_SUCCESS("recharge_success", "充值成功通知"),
TEMPLATES("template", "公众号模板消息"),
SUBSCRIBE("subscribe", "小程序订阅消息");
private String value; //模板编号
private String desc; //模板id

View File

@ -71,7 +71,6 @@
</dependency>
</dependencies>
</project>

View File

@ -1,7 +1,9 @@
package co.yixiang.yshop.module.message.controller.admin.wechattemplate;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -16,11 +18,13 @@ import java.io.IOException;
import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.framework.common.pojo.CommonResult;
import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;
import co.yixiang.yshop.framework.excel.core.util.ExcelUtils;
import co.yixiang.yshop.framework.operatelog.core.annotations.OperateLog;
import static co.yixiang.yshop.framework.operatelog.core.enums.OperateTypeEnum.*;
import co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo.*;
@ -92,7 +96,7 @@ public class WechatTemplateController {
@PreAuthorize("@ss.hasPermission('message:wechat-template:export')")
@OperateLog(type = EXPORT)
public void exportWechatTemplateExcel(@Valid WechatTemplateExportReqVO exportReqVO,
HttpServletResponse response) throws IOException {
HttpServletResponse response) throws IOException {
List<WechatTemplateDO> list = wechatTemplateService.getWechatTemplateList(exportReqVO);
// 导出 Excel
List<WechatTemplateExcelVO> datas = WechatTemplateConvert.INSTANCE.convertList02(list);

View File

@ -2,15 +2,16 @@ package co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import javax.validation.constraints.*;
/**
* 微信模板 Base VO提供给添加、修改、详细的子 VO 使用
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
*/
* 微信模板 Base VO提供给添加、修改、详细的子 VO 使用
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
*/
@Data
public class WechatTemplateBaseVO {

View File

@ -1,8 +1,11 @@
package co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 微信模板创建 Request VO")

View File

@ -2,6 +2,7 @@ package co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;

View File

@ -1,10 +1,14 @@
package co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import co.yixiang.yshop.framework.common.pojo.PageParam;
import java.time.LocalDateTime;
import org.springframework.format.annotation.DateTimeFormat;
import static co.yixiang.yshop.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;

View File

@ -1,10 +1,13 @@
package co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import co.yixiang.yshop.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static co.yixiang.yshop.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;

View File

@ -2,6 +2,7 @@ package co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 微信模板 Response VO")

View File

@ -2,6 +2,7 @@ package co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;

View File

@ -24,32 +24,31 @@ public class WeixinNoticeConsumer extends AbstractStreamMessageListener<WeixinNo
private WeixinTemplateService weixinTemplateService;
@Override
public void onMessage(WeixinNoticeMessage message) {
log.info("[onMessage][消息内容({})]", message);
//公众号
if(WechatTempateEnum.TEMPLATES.getValue().equals(message.getType())) {
if(WechatTempateEnum.PAY_SUCCESS.getValue().equals(message.getTempkey())){
weixinTemplateService.paySuccessNotice(message.getOrderId(),message.getPrice(),message.getUid());
}else if(WechatTempateEnum.DELIVERY_SUCCESS.getValue().equals(message.getTempkey())){
weixinTemplateService.deliverySuccessNotice(message.getOrderId(),message.getDeliveryName(),
message.getDeliveryId(),message.getUid());
} else if(WechatTempateEnum.REFUND_SUCCESS.getValue().equals(message.getTempkey())){
if (WechatTempateEnum.TEMPLATES.getValue().equals(message.getType())) {
if (WechatTempateEnum.PAY_SUCCESS.getValue().equals(message.getTempkey())) {
weixinTemplateService.paySuccessNotice(message.getOrderId(), message.getPrice(), message.getUid());
} else if (WechatTempateEnum.DELIVERY_SUCCESS.getValue().equals(message.getTempkey())) {
weixinTemplateService.deliverySuccessNotice(message.getOrderId(), message.getDeliveryName(),
message.getDeliveryId(), message.getUid());
} else if (WechatTempateEnum.REFUND_SUCCESS.getValue().equals(message.getTempkey())) {
weixinTemplateService.refundSuccessNotice("您的订单退款申请被通过,钱款将很快还至您的支付账户。",
message.getOrderId(),message.getDeliveryName(),message.getUid(),message.getTime());
message.getOrderId(), message.getDeliveryName(), message.getUid(), message.getTime());
}
}else if(WechatTempateEnum.SUBSCRIBE.getValue().equals(message.getType())){
} else if (WechatTempateEnum.SUBSCRIBE.getValue().equals(message.getType())) {
//小程序
if(WechatTempateEnum.PAY_SUCCESS.getValue().equals(message.getTempkey())){
weiXinSubscribeService.paySuccessNotice(message.getOrderId(),message.getPrice(),message.getUid());
}else if(WechatTempateEnum.DELIVERY_SUCCESS.getValue().equals(message.getTempkey())){
weiXinSubscribeService.deliverySuccessNotice(message.getOrderId(),message.getDeliveryName(),
message.getDeliveryId(),message.getUid());
} else if(WechatTempateEnum.REFUND_SUCCESS.getValue().equals(message.getTempkey())){
weiXinSubscribeService.refundSuccessNotice(message.getOrderId(),message.getDeliveryName(),
message.getUid(),message.getTime());
if (WechatTempateEnum.PAY_SUCCESS.getValue().equals(message.getTempkey())) {
weiXinSubscribeService.paySuccessNotice(message.getOrderId(), message.getPrice(), message.getUid());
} else if (WechatTempateEnum.DELIVERY_SUCCESS.getValue().equals(message.getTempkey())) {
weiXinSubscribeService.deliverySuccessNotice(message.getOrderId(), message.getDeliveryName(),
message.getDeliveryId(), message.getUid());
} else if (WechatTempateEnum.REFUND_SUCCESS.getValue().equals(message.getTempkey())) {
weiXinSubscribeService.refundSuccessNotice(message.getOrderId(), message.getDeliveryName(),
message.getUid(), message.getTime());
}
}

View File

@ -33,7 +33,6 @@ public class WeixinNoticeMessage extends AbstractStreamMessage {
private String deliveryId;
@Override
public String getStreamKey() {
return "weixin.msg.notice";

View File

@ -15,11 +15,12 @@ public class WeixinNoticeProducer {
/**
* 发送消息
*
* @param tempkey 订单编号
* @param type 类型
* @param type 类型
*/
public void sendNoticeMessage( Long uid,String tempkey,String type,String orderId,String price,
String time,String deliveryName,String deliveryId) {
public void sendNoticeMessage(Long uid, String tempkey, String type, String orderId, String price,
String time, String deliveryName, String deliveryId) {
WeixinNoticeMessage weixinNoticeMessage = new WeixinNoticeMessage()
.setTempkey(tempkey).setType(type).setOrderId(orderId).setUid(uid)
.setPrice(price).setDeliveryId(deliveryId).setTime(time).setDeliveryName(deliveryName);

View File

@ -36,129 +36,137 @@ public class WeiXinSubscribeService {
private WechatTemplateService wechatTemplateService;
@Resource
private WxMaService wxMaService;
/**
* 充值成功通知
* @param time 时间
*
* @param time 时间
* @param price 金额
* @param uid uid
* @param uid uid
*/
public void rechargeSuccessNotice(String time,String price,Long uid){
public void rechargeSuccessNotice(String time, String price, Long uid) {
String openid = this.getUserOpenid(uid);
if(StrUtil.isBlank(openid)) {
if (StrUtil.isBlank(openid)) {
return;
}
Map<String,String> map = new HashMap<>();
map.put("first","您的账户金币发生变动,详情如下:");
map.put("keyword1","充值");
map.put("keyword2",time);
map.put("keyword3",price);
Map<String, String> map = new HashMap<>();
map.put("first", "您的账户金币发生变动,详情如下:");
map.put("keyword1", "充值");
map.put("keyword2", time);
map.put("keyword3", price);
map.put("remark", ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
String tempId = this.getTempId(WechatTempateEnum.RECHARGE_SUCCESS.getValue());
if(StrUtil.isNotBlank(tempId)) {
this.sendSubscribeMsg( openid, tempId, "/user/account",map);
if (StrUtil.isNotBlank(tempId)) {
this.sendSubscribeMsg(openid, tempId, "/user/account", map);
}
}
/**
* 支付成功通知
*
* @param orderId 订单号
* @param price 金额
* @param uid uid
* @param price 金额
* @param uid uid
*/
public void paySuccessNotice(String orderId,String price,Long uid){
public void paySuccessNotice(String orderId, String price, Long uid) {
String openid = this.getUserOpenid(uid);
if(StrUtil.isBlank(openid)) {
if (StrUtil.isBlank(openid)) {
return;
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
Map<String,String> map = new HashMap<>();
map.put("amount1",price);
Map<String, String> map = new HashMap<>();
map.put("amount1", price);
map.put("date2", simpleDateFormat.format(new Date()));
map.put("character_string3",orderId);
map.put("time4",simpleDateFormat.format(new Date()));
map.put("thing5","yshop购买商品");
map.put("character_string3", orderId);
map.put("time4", simpleDateFormat.format(new Date()));
map.put("thing5", "yshop购买商品");
String tempId = this.getTempId(WechatTempateEnum.PAY_SUCCESS.getValue());
if(StrUtil.isNotBlank(tempId)) {
this.sendSubscribeMsg( openid,tempId, "/order/detail/"+orderId,map);
if (StrUtil.isNotBlank(tempId)) {
this.sendSubscribeMsg(openid, tempId, "/order/detail/" + orderId, map);
}
}
/**
* 退款成功通知
*
* @param orderId 订单号
* @param price 金额
* @param uid uid
* @param time 时间
* @param price 金额
* @param uid uid
* @param time 时间
*/
public void refundSuccessNotice(String orderId,String price,Long uid,String time){
public void refundSuccessNotice(String orderId, String price, Long uid, String time) {
String openid = this.getUserOpenid(uid);
if(StrUtil.isBlank(openid)) {
if (StrUtil.isBlank(openid)) {
return;
}
Map<String,String> map = new HashMap<>();
map.put("first","您的订单退款申请被通过,钱款将很快还至您的支付账户。");
Map<String, String> map = new HashMap<>();
map.put("first", "您的订单退款申请被通过,钱款将很快还至您的支付账户。");
//订单号
map.put("keyword1",orderId);
map.put("keyword2",price);
map.put("keyword1", orderId);
map.put("keyword2", price);
map.put("keyword3", time);
map.put("remark",ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
map.put("remark", ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
String tempId = this.getTempId(WechatTempateEnum.REFUND_SUCCESS.getValue());
if(StrUtil.isNotBlank(tempId)) {
this.sendSubscribeMsg( openid,tempId, "/order/detail/"+orderId,map);
if (StrUtil.isNotBlank(tempId)) {
this.sendSubscribeMsg(openid, tempId, "/order/detail/" + orderId, map);
}
}
/**
* 发货成功通知
* @param orderId 单号
*
* @param orderId 单号
* @param deliveryName 快递公司
* @param deliveryId 快递单号
* @param uid uid
* @param deliveryId 快递单号
* @param uid uid
*/
public void deliverySuccessNotice(String orderId,String deliveryName,
String deliveryId,Long uid){
public void deliverySuccessNotice(String orderId, String deliveryName,
String deliveryId, Long uid) {
String openid = this.getUserOpenid(uid);
if(StrUtil.isEmpty(openid)) {
if (StrUtil.isEmpty(openid)) {
return;
}
Map<String,String> map = new HashMap<>();
map.put("first","亲,宝贝已经启程了,好想快点来到你身边。");
map.put("keyword2",deliveryName);
map.put("keyword1",orderId);
map.put("keyword3",deliveryId);
map.put("remark",ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
Map<String, String> map = new HashMap<>();
map.put("first", "亲,宝贝已经启程了,好想快点来到你身边。");
map.put("keyword2", deliveryName);
map.put("keyword1", orderId);
map.put("keyword3", deliveryId);
map.put("remark", ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
String tempId = this.getTempId(WechatTempateEnum.DELIVERY_SUCCESS.getValue());
if(StrUtil.isNotBlank(tempId)) {
this.sendSubscribeMsg( openid,tempId, "/order/detail/"+orderId,map);
if (StrUtil.isNotBlank(tempId)) {
this.sendSubscribeMsg(openid, tempId, "/order/detail/" + orderId, map);
}
}
/**
* 构建小程序一次性订阅消息
* @param openId 单号
*
* @param openId 单号
* @param templateId 模板id
* @param page 跳转页面
* @param map map内容
* @param page 跳转页面
* @param map map内容
*/
private void sendSubscribeMsg(String openId, String templateId, String page, Map<String,String> map){
private void sendSubscribeMsg(String openId, String templateId, String page, Map<String, String> map) {
WxMaSubscribeMessage wxMaSubscribeMessage = WxMaSubscribeMessage.builder()
.toUser(openId)
.templateId(templateId)
.page(page)
.build();
map.forEach( (k,v)-> { wxMaSubscribeMessage.addData(new WxMaSubscribeMessage.MsgData(k, v));} );
// WxMaService wxMaService = WxMaConfiguration.getWxMaService();
map.forEach((k, v) -> {
wxMaSubscribeMessage.addData(new WxMaSubscribeMessage.MsgData(k, v));
});
// WxMaService wxMaService = WxMaConfiguration.getWxMaService();
try {
wxMaService.getMsgService().sendSubscribeMsg(wxMaSubscribeMessage);
} catch (WxErrorException e) {
@ -168,16 +176,17 @@ public class WeiXinSubscribeService {
/**
* 获取模板消息id
*
* @param key 模板key
* @return string
*/
private String getTempId(String key){
private String getTempId(String key) {
WechatTemplateDO yxWechatTemplate = wechatTemplateService.lambdaQuery()
.eq(WechatTemplateDO::getType,"subscribe")
.eq(WechatTemplateDO::getTempkey,key)
.eq(WechatTemplateDO::getType, "subscribe")
.eq(WechatTemplateDO::getTempkey, key)
.one();
if (yxWechatTemplate == null) {
throw exception(new ErrorCode(9999999,"请后台配置key:" + key + "订阅消息id"));
throw exception(new ErrorCode(9999999, "请后台配置key:" + key + "订阅消息id"));
}
return yxWechatTemplate.getTempid();
}
@ -185,20 +194,21 @@ public class WeiXinSubscribeService {
/**
* 获取openid
*
* @param uid uid
* @return String
*/
private String getUserOpenid(Long uid){
private String getUserOpenid(Long uid) {
MemberUserDO yxUser = userService.getById(uid);
if(yxUser == null) {
if (yxUser == null) {
return "";
}
WechatUserDTO wechatUserDto = yxUser.getWxProfile();
if(wechatUserDto == null) {
if (wechatUserDto == null) {
return "";
}
if(StrUtil.isBlank(wechatUserDto.getRoutineOpenId())) {
if (StrUtil.isBlank(wechatUserDto.getRoutineOpenId())) {
return "";
}
return wechatUserDto.getRoutineOpenId();

View File

@ -49,139 +49,142 @@ public class WeixinTemplateService {
private WxMpService wxMpService;
/**
* 充值成功通知
* @param time 时间
*
* @param time 时间
* @param price 金额
* @param uid uid
* @param uid uid
*/
public void rechargeSuccessNotice(String time,String price,Long uid){
public void rechargeSuccessNotice(String time, String price, Long uid) {
String openid = this.getUserOpenid(uid);
if(StrUtil.isBlank(openid)) {
if (StrUtil.isBlank(openid)) {
return;
}
Map<String,String> map = new HashMap<>();
map.put("first","您的账户金币发生变动,详情如下:");
map.put("keyword1","充值");
map.put("keyword2",time);
map.put("keyword3",price);
Map<String, String> map = new HashMap<>();
map.put("first", "您的账户金币发生变动,详情如下:");
map.put("keyword1", "充值");
map.put("keyword2", time);
map.put("keyword3", price);
map.put("remark", ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
String tempId = this.getTempId(WechatTempateEnum.RECHARGE_SUCCESS.getValue());
if(StrUtil.isNotBlank(tempId)) {
this.sendWxMpTemplateMessage( openid, tempId, "https://www.yixiang.co",map);
if (StrUtil.isNotBlank(tempId)) {
this.sendWxMpTemplateMessage(openid, tempId, "https://www.yixiang.co", map);
}
}
/**
* 支付成功通知
*
* @param orderId 订单号
* @param price 金额
* @param uid uid
* @param price 金额
* @param uid uid
*/
public void paySuccessNotice(String orderId,String price,Long uid){
public void paySuccessNotice(String orderId, String price, Long uid) {
String openid = this.getUserOpenid(uid);
if(StrUtil.isBlank(openid)) {
if (StrUtil.isBlank(openid)) {
return;
}
Map<String,String> map = new HashMap<>();
map.put("first","您的订单已支付成功,我们会尽快为您发货。");
Map<String, String> map = new HashMap<>();
map.put("first", "您的订单已支付成功,我们会尽快为您发货。");
//订单号
map.put("keyword1",orderId);
map.put("keyword2",price);
map.put("remark",ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
map.put("keyword1", orderId);
map.put("keyword2", price);
map.put("remark", ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
String tempId = this.getTempId(WechatTempateEnum.PAY_SUCCESS.getValue());
if(StrUtil.isNotBlank(tempId)) {
this.sendWxMpTemplateMessage( openid,tempId, "https://www.yixiang.co",map);
if (StrUtil.isNotBlank(tempId)) {
this.sendWxMpTemplateMessage(openid, tempId, "https://www.yixiang.co", map);
}
}
/**
* 退款成功通知
*
* @param orderId 订单号
* @param price 金额
* @param uid uid
* @param time 时间
* @param price 金额
* @param uid uid
* @param time 时间
*/
public void refundSuccessNotice(String title,String orderId,String price,Long uid,String time){
public void refundSuccessNotice(String title, String orderId, String price, Long uid, String time) {
String openid = this.getUserOpenid(uid);
if(StrUtil.isBlank(openid)) {
if (StrUtil.isBlank(openid)) {
return;
}
Map<String,String> map = new HashMap<>();
map.put("first",title);
Map<String, String> map = new HashMap<>();
map.put("first", title);
//订单号
map.put("keyword1",orderId);
map.put("keyword2",price);
map.put("keyword1", orderId);
map.put("keyword2", price);
map.put("keyword3", time);
map.put("remark",ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
map.put("remark", ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
String tempId = this.getTempId(WechatTempateEnum.REFUND_SUCCESS.getValue());
if(StrUtil.isNotBlank(tempId)) {
this.sendWxMpTemplateMessage( openid,tempId, "https://www.yixiang.co",map);
if (StrUtil.isNotBlank(tempId)) {
this.sendWxMpTemplateMessage(openid, tempId, "https://www.yixiang.co", map);
}
}
/**
* 发货成功通知
* @param orderId 单号
*
* @param orderId 单号
* @param deliveryName 快递公司
* @param deliveryId 快递单号
* @param uid uid
* @param deliveryId 快递单号
* @param uid uid
*/
public void deliverySuccessNotice(String orderId,String deliveryName,
String deliveryId,Long uid){
public void deliverySuccessNotice(String orderId, String deliveryName,
String deliveryId, Long uid) {
String openid = this.getUserOpenid(uid);
if(StrUtil.isEmpty(openid)) {
if (StrUtil.isEmpty(openid)) {
return;
}
Map<String,String> map = new HashMap<>();
map.put("first","亲,宝贝已经启程了,好想快点来到你身边。");
map.put("keyword2",deliveryName);
map.put("keyword1",orderId);
map.put("keyword3",deliveryId);
map.put("remark",ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
Map<String, String> map = new HashMap<>();
map.put("first", "亲,宝贝已经启程了,好想快点来到你身边。");
map.put("keyword2", deliveryName);
map.put("keyword1", orderId);
map.put("keyword3", deliveryId);
map.put("remark", ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
String tempId = this.getTempId(WechatTempateEnum.DELIVERY_SUCCESS.getValue());
if(StrUtil.isNotBlank(tempId)) {
this.sendWxMpTemplateMessage( openid,tempId, "https://www.yixiang.co",map);
if (StrUtil.isNotBlank(tempId)) {
this.sendWxMpTemplateMessage(openid, tempId, "https://www.yixiang.co", map);
}
}
/**
* 构建微信模板通知
* @param openId 单号
*
* @param openId 单号
* @param templateId 模板id
* @param url 跳转url
* @param map map内容
* @param url 跳转url
* @param map map内容
* @return String
*/
private String sendWxMpTemplateMessage(String openId, String templateId, String url, Map<String,String> map){
private String sendWxMpTemplateMessage(String openId, String templateId, String url, Map<String, String> map) {
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
.toUser(openId)
.templateId(templateId)
.url(url)
.build();
map.forEach( (k,v)-> { templateMessage.addData(new WxMpTemplateData(k, v, "#000000"));} );
map.forEach((k, v) -> {
templateMessage.addData(new WxMpTemplateData(k, v, "#000000"));
});
String msgId = null;
try {
msgId = wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
msgId = wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
} catch (WxErrorException e) {
e.printStackTrace();
}
@ -189,24 +192,22 @@ public class WeixinTemplateService {
}
/**
* 获取模板消息id
*
* @param key 模板key
* @return string
*/
private String getTempId(String key){
private String getTempId(String key) {
WechatTemplateDO yxWechatTemplate = wechatTemplateService.lambdaQuery()
.eq(WechatTemplateDO::getType,"template")
.eq(WechatTemplateDO::getTempkey,key)
.eq(WechatTemplateDO::getType, "template")
.eq(WechatTemplateDO::getTempkey, key)
.one();
if (yxWechatTemplate == null) {
throw exception(new ErrorCode(9999999,"请后台配置key:" + key + "订阅消息id"));
throw exception(new ErrorCode(9999999, "请后台配置key:" + key + "订阅消息id"));
}
if(ShopCommonEnum.NO.getValue().equals(yxWechatTemplate.getStatus())){
if (ShopCommonEnum.NO.getValue().equals(yxWechatTemplate.getStatus())) {
return "";
}
@ -214,23 +215,23 @@ public class WeixinTemplateService {
}
/**
* 获取openid
*
* @param uid uid
* @return String
*/
private String getUserOpenid(Long uid){
private String getUserOpenid(Long uid) {
MemberUserDO yxUser = userService.getById(uid);
if(yxUser == null) {
if (yxUser == null) {
return "";
}
WechatUserDTO wechatUserDto = yxUser.getWxProfile();
if(wechatUserDto == null) {
if (wechatUserDto == null) {
return "";
}
if(StrUtil.isBlank(wechatUserDto.getOpenId())) {
if (StrUtil.isBlank(wechatUserDto.getOpenId())) {
return "";
}
return wechatUserDto.getOpenId();