赞
踩
选择你的模版
选用自己想要的模版,点击选用之后会进入选择的不同的关键词,最多选择5个关键词。可以搜索自己的模版。
如果没有可以自己申请:
需要先触发页面同意才能收到
前端简单测试代码:
- <view>
- <view class="intro">订阅功能Demo</view>
- <button type="info" bindtap="submit">发送订阅消息</button>
- </view>
- submit(){
- wx.requestSubscribeMessage({
- tmplIds: ['你的模版id'],
- success (res) {
- //发送请求到后端,后端接收到请求后调用订阅消息接口进行推送
-
- }
- })
- },
maven:
- <dependency>
- <groupId>com.github.binarywang</groupId>
- <artifactId>wx-java-miniapp-spring-boot-starter</artifactId>
- <version>4.5.7.B</version>//选择你自己想要版本
- </dependency>
- import cn.binarywang.wx.miniapp.api.WxMaService;
- import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
- import cn.binarywang.wx.miniapp.config.WxMaConfig;
- import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
- import com.tgy.rtls.data.tool.Constant;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.stereotype.Component;
-
- /**
- * @BelongsProject: rtls
- * @BelongsPackage: com.tgy.rtls.web.config.pay.wxpay
- * @Author: wuwei
- * @CreateTime: 2023-12-01 15:54
- * @Description: TODO
- * @Version: 1.0
- */
- @Configuration
- public class WeChatMpConfig {
-
- @Bean
- public WxMaService wxMaService(){
- WxMaServiceImpl wxMaService = new WxMaServiceImpl();
- wxMaService.setWxMaConfig(wxMaConfig());
- return wxMaService;
- }
-
- @Bean
- public WxMaConfig wxMaConfig(){
- WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
- wxMaConfig.setAppid("");//你的appid
- wxMaConfig.setSecret("");//你的密钥
- return wxMaConfig;
- }
- }
业务代码:
根据实际情况来,我这只是测试,所以参数是写死的。
- import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
-
- import java.util.*;
-
- @RestController
- @RequestMapping("/wechat")
- @CrossOrigin
- @RequiredArgsConstructor
- public class SendTemplateMsgController{
- private final WxMpService wxMpService;
-
- @RequestMapping("/send")
- @SneakyThrows(Exception.class)
- public void send() {
- List<WxMaSubscribeMessage.MsgData> data=
- Arrays.asList(
- new WxMaSubscribeMessage.MsgData("car_number1","鄂FU89x1"),
- new WxMaSubscribeMessage.MsgData("thing2","VIP9"),
- new WxMaSubscribeMessage.MsgData("time3","2023/02/03 15:15:15"),
- new WxMaSubscribeMessage.MsgData("thing4","您是VIP9,每日不限时停车"),
- new WxMaSubscribeMessage.MsgData("thing5","祝您购物愉快")
- );
-
- wxMaService.getSubscribeService().sendSubscribeMsg(
- WxMaSubscribeMessage.builder()
- .toUser("你的openid")
- .templateId(你的模版id)
- .miniprogramState("developer")
- .data(data)
- .build()
- );
- }
- }
我这里启动报错:me.chanjar.weixin.common.bean.WxAccessTokenEntity
我搜索这个WxAccessTokenEntity好像找不到这个,没有依赖引入。
加入下面依赖就可以解决:
- <dependency>
- <groupId>com.github.binarywang</groupId>
- <artifactId>weixin-java-common</artifactId>
- <version>4.5.7.B</version>
- </dependency>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。