feat(shop): 添加微信模板消息推送功能- 新增 PushTemplateMessageController 控制器用于发送微信模板消息- 在 ShopDealerUser 实体中添加 openid 字段并配置为非表字段
- 更新 ShopDealerUserMapper.xml 以关联查询 sys_user 表获取 openid - 实现升级为管理员时自动发送微信模板消息的通知逻辑 - 集成 WxNotificationService 进行实际的消息推送调用 - 使用 TemplateMessageRequest 构造模板消息内容及小程序跳转参数
This commit is contained in:
@@ -0,0 +1,75 @@
|
|||||||
|
package com.gxwebsoft.sdy.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.gxwebsoft.common.core.web.ApiResult;
|
||||||
|
import com.gxwebsoft.common.core.web.BaseController;
|
||||||
|
import com.gxwebsoft.common.system.entity.User;
|
||||||
|
import com.gxwebsoft.common.system.param.UserParam;
|
||||||
|
import com.gxwebsoft.common.system.service.UserService;
|
||||||
|
import com.gxwebsoft.hjm.dto.TemplateMessageRequest;
|
||||||
|
import com.gxwebsoft.hjm.entity.HjmCar;
|
||||||
|
import com.gxwebsoft.hjm.entity.HjmCourses;
|
||||||
|
import com.gxwebsoft.hjm.service.HjmCarService;
|
||||||
|
import com.gxwebsoft.hjm.service.WxNotificationService;
|
||||||
|
import com.gxwebsoft.shop.entity.ShopDealerUser;
|
||||||
|
import com.gxwebsoft.shop.service.ShopDealerUserService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务
|
||||||
|
*
|
||||||
|
* @author 科技小王子
|
||||||
|
* @since 2022-12-15 19:11:07
|
||||||
|
*/
|
||||||
|
@Tag(name = "定时任务")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/sdy/sdy-template-message")
|
||||||
|
public class PushTemplateMessageController extends BaseController {
|
||||||
|
@Resource
|
||||||
|
private UserService userService;
|
||||||
|
@Resource
|
||||||
|
private WxNotificationService wxNotificationService;
|
||||||
|
@Resource
|
||||||
|
private ShopDealerUserService shopDealerUserService;
|
||||||
|
|
||||||
|
@Operation(summary = "升级为管理员")
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ApiResult<?> pushByUpdateAdmin(@PathVariable("id") Integer id) {
|
||||||
|
final ShopDealerUser dealerUser = shopDealerUserService.getByUserIdRel(id);
|
||||||
|
if(ObjectUtil.isNotEmpty(dealerUser)){
|
||||||
|
updateToAdmin(dealerUser);
|
||||||
|
}
|
||||||
|
return fail("发送失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 升级为管理员
|
||||||
|
*/
|
||||||
|
public void updateToAdmin(ShopDealerUser item) {
|
||||||
|
// 发送模板消息
|
||||||
|
final TemplateMessageRequest templateMessageRequest = new TemplateMessageRequest();
|
||||||
|
templateMessageRequest.setToUser(item.getOpenid());
|
||||||
|
templateMessageRequest.setTemplateId("KxGoeBpHW60QFUIU7Vo3c_48g_3V55tWWr23tUUl8gI");
|
||||||
|
// templateMessageRequest.setUrl("https://mp.websoft.top");
|
||||||
|
final TemplateMessageRequest.MiniProgram miniProgram = new TemplateMessageRequest.MiniProgram();
|
||||||
|
miniProgram.setAppid("wx51962d6ac21f2ed2");
|
||||||
|
miniProgram.setPagepath("pages/index/index");
|
||||||
|
templateMessageRequest.setMiniprogram(miniProgram);
|
||||||
|
HashMap<String, TemplateMessageRequest.TemplateDataItem> map = new HashMap<>();
|
||||||
|
map.put("thing1", new TemplateMessageRequest.TemplateDataItem(item.getRealName()));
|
||||||
|
map.put("thing2", new TemplateMessageRequest.TemplateDataItem("升级为管理员"));
|
||||||
|
templateMessageRequest.setData(map);
|
||||||
|
wxNotificationService.sendTemplateMessage(10560, templateMessageRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.gxwebsoft.shop.entity;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
@@ -32,6 +33,10 @@ public class ShopDealerUser implements Serializable {
|
|||||||
@Schema(description = "自增ID")
|
@Schema(description = "自增ID")
|
||||||
private Integer userId;
|
private Integer userId;
|
||||||
|
|
||||||
|
@Schema(description = "微信openid")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String openid;
|
||||||
|
|
||||||
@Schema(description = "姓名")
|
@Schema(description = "姓名")
|
||||||
private String realName;
|
private String realName;
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,9 @@
|
|||||||
|
|
||||||
<!-- 关联查询sql -->
|
<!-- 关联查询sql -->
|
||||||
<sql id="selectSql">
|
<sql id="selectSql">
|
||||||
SELECT a.*
|
SELECT a.*, b.openid
|
||||||
FROM shop_dealer_user a
|
FROM shop_dealer_user a
|
||||||
|
LEFT JOIN gxwebsoft_core.sys_user b ON a.user_id = b.user_id
|
||||||
<where>
|
<where>
|
||||||
<if test="param.id != null">
|
<if test="param.id != null">
|
||||||
AND a.id = #{param.id}
|
AND a.id = #{param.id}
|
||||||
|
|||||||
Reference in New Issue
Block a user