Commit e60bcc72 authored by mlchun's avatar mlchun

1.添加微信消息模板推送

parent 87bba441
package io.hmit.config;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
/**
* @Description :
* @Author : Shen Yuanfeng
* @Date: 2021/3/12 16:03
*/
@Component
public class WeChatMpConfig {
@Autowired
private WechatAccountConfig wechatAccountConfig;
@Bean
public WxMpService wxMpService(){
WxMpService wxMpService = new WxMpServiceImpl();
wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
return wxMpService;
}
@Bean
public WxMpConfigStorage wxMpConfigStorage(){
WxMpInMemoryConfigStorage wxMpConfigStorage = new WxMpInMemoryConfigStorage();
wxMpConfigStorage.setAppId(wechatAccountConfig.getMpAppId());
wxMpConfigStorage.setSecret(wechatAccountConfig.getMpAppSecret());
return wxMpConfigStorage;
}
}
package io.hmit.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @Description :
* @Author : Shen Yuanfeng
* @Date: 2021/3/12 16:02
*/
@Data
@Component
@ConfigurationProperties(prefix = "wechat")
public class WechatAccountConfig {
private String mpAppId;
private String mpAppSecret;
}
...@@ -12,6 +12,7 @@ import io.hmit.modules.serviceOrder.dto.*; ...@@ -12,6 +12,7 @@ import io.hmit.modules.serviceOrder.dto.*;
import io.hmit.modules.serviceOrder.entity.PensionOrderDocumentEntity; import io.hmit.modules.serviceOrder.entity.PensionOrderDocumentEntity;
import io.hmit.modules.serviceOrder.entity.PensionOrderEntity; import io.hmit.modules.serviceOrder.entity.PensionOrderEntity;
import io.hmit.modules.serviceOrder.service.*; import io.hmit.modules.serviceOrder.service.*;
import io.hmit.service.PushMessage;
import io.hmit.service.UserService; import io.hmit.service.UserService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -55,6 +56,9 @@ public class PensionOrderServiceImpl extends CrudServiceImpl<PensionOrderDao, Pe ...@@ -55,6 +56,9 @@ public class PensionOrderServiceImpl extends CrudServiceImpl<PensionOrderDao, Pe
@Autowired @Autowired
private UserService userService; private UserService userService;
@Autowired
private PushMessage pushMessage;
//查询全部订单 //查询全部订单
@Override @Override
public PageData<PensionOrderDTO> getAllOrderPage(Map<String, Object> params, Long userId) { public PageData<PensionOrderDTO> getAllOrderPage(Map<String, Object> params, Long userId) {
...@@ -85,7 +89,7 @@ public class PensionOrderServiceImpl extends CrudServiceImpl<PensionOrderDao, Pe ...@@ -85,7 +89,7 @@ public class PensionOrderServiceImpl extends CrudServiceImpl<PensionOrderDao, Pe
save(pensionOrderDTO); save(pensionOrderDTO);
PensionOrderServiceDTO orderServiceDTO = new PensionOrderServiceDTO().assemblePensionOrderService(pensionOrderDTO); PensionOrderServiceDTO orderServiceDTO = new PensionOrderServiceDTO().assemblePensionOrderService(pensionOrderDTO);
pensionOrderServiceService.save(orderServiceDTO); pensionOrderServiceService.save(orderServiceDTO);
pushMessage.sendMsg(pensionOrderDTO, userService.getUserByUserId(pensionOrderDTO.getCreator()).getOpenid());
} }
@Override @Override
......
package io.hmit.service;
import io.hmit.modules.serviceOrder.dto.PensionOrderDTO;
public interface PushMessage {
void sendMsg(PensionOrderDTO pensionOrderDTO, String openId);
}
package io.hmit.service.impl;
import io.hmit.modules.serviceOrder.dto.PensionOrderDTO;
import io.hmit.service.PushMessage;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
/**
* @Description :
* @Author : Shen Yuanfeng
* @Date: 2021/3/12 14:40
*/
@Slf4j
@Service
public class PushMessageImpl implements PushMessage {
@Autowired
private WxMpService wxMpService;
@Override
public void sendMsg(PensionOrderDTO pensionOrderDTO, String openId) {
WxMpTemplateMessage templateMessage = new WxMpTemplateMessage();
templateMessage.setTemplateId("GsGydVGl-vzOv5aA0LaIdA-FcMM88TEpe37U-lZ6HJ8");
templateMessage.setToUser(openId);
List<WxMpTemplateData> data = Arrays.asList(
new WxMpTemplateData("first", "订单预约成功!"),
new WxMpTemplateData("keyword1", pensionOrderDTO.getServiceName()),
new WxMpTemplateData("keyword2", pensionOrderDTO.getAppointmentTime().toString()),
new WxMpTemplateData("keyword3", pensionOrderDTO.getStatusName())
);
templateMessage.setData(data);
try{
wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
}catch (WxErrorException e){
log.error("【微信模板消息】发送失败,{}", e);
}
}
}
...@@ -72,4 +72,8 @@ mybatis-plus: ...@@ -72,4 +72,8 @@ mybatis-plus:
jdbc-type-for-null: 'null' jdbc-type-for-null: 'null'
QR: QR:
# download-path: D:/123/ /home/websoft/java_jar/pension_service/myfile/ # download-path: D:/123/ /home/websoft/java_jar/pension_service/myfile/
download-path: /home/websoft/java_jar/pension_service/myfile/ download-path: /home/websoft/java_jar/pension_service/myfile/
\ No newline at end of file
wechat:
mpAppId: wxfa2386639794d998
mpAppSecret: 8f624f83c9585baa9d1697e24fdffd81
\ No newline at end of file
...@@ -195,6 +195,11 @@ ...@@ -195,6 +195,11 @@
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>${lombok.version}</version> <version>${lombok.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-mp</artifactId>
<version>2.7.0</version>
</dependency>
</dependencies> </dependencies>
<!-- 阿里云maven仓库 --> <!-- 阿里云maven仓库 -->
......
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