|
@@ -1,5 +1,7 @@
|
|
|
package com.ylx.web.controller.massage;
|
|
|
|
|
|
+import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
+import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.ylx.common.annotation.Log;
|
|
@@ -19,13 +21,17 @@ import com.ylx.massage.utils.LocationUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -50,6 +56,12 @@ public class TJsController extends BaseController {
|
|
|
@Resource
|
|
|
private TWxUserService wxUserService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private WxMaService wxMaService;
|
|
|
+
|
|
|
+ @Value("${wx.template_id_1}")
|
|
|
+ private String msgTemplateId1;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 添加技师申请
|
|
@@ -243,4 +255,33 @@ public class TJsController extends BaseController {
|
|
|
return R.fail("系统异常");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation("通知")
|
|
|
+ @RequestMapping(value = "/tongzhi", method = RequestMethod.GET)
|
|
|
+ public boolean sendSubscribeMessage(String openId) {
|
|
|
+ String page="pages/index/index"; // 应该是消息点击后跳转页面
|
|
|
+ WxMaSubscribeMessage message = new WxMaSubscribeMessage();
|
|
|
+ message.setTemplateId(msgTemplateId1);
|
|
|
+ message.setToUser(openId);
|
|
|
+ message.setPage(page);
|
|
|
+ List<WxMaSubscribeMessage.MsgData> subscribeDataList = new ArrayList<>();
|
|
|
+ WxMaSubscribeMessage.MsgData subscribeData = new WxMaSubscribeMessage.MsgData();
|
|
|
+ subscribeData.setName("key1"); // 你在小程序自定义的key(比如“商家名称”)
|
|
|
+ subscribeData.setValue("夜来香"); //key对应的内容
|
|
|
+
|
|
|
+ WxMaSubscribeMessage.MsgData msgData = new WxMaSubscribeMessage.MsgData();
|
|
|
+ msgData.setName("key2");
|
|
|
+ msgData.setValue("你好,f");
|
|
|
+ //添加你配置要且要展示的内容
|
|
|
+ subscribeDataList.add(subscribeData);
|
|
|
+
|
|
|
+ message.setData(subscribeDataList);
|
|
|
+ try {
|
|
|
+ wxMaService.getMsgService().sendSubscribeMsg(message);
|
|
|
+ return true;
|
|
|
+ } catch (WxErrorException e) {
|
|
|
+ log.error("发送小程序订阅消息失败,errCode:{},errMsg:{}", e.getError().getErrorCode(), e.getError().getErrorMsg());
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|