当前位置:   article > 正文

微信小程序订阅消息java+uniapp_java uniapp 实现小程序订阅消息

java uniapp 实现小程序订阅消息

在微信小程序中进行了某种操作后,推送消息告知用户的操作结果。或者微信端办公流程提交给下一个人审批后,得到审批通过或是驳回修改的命令 - 使用场景具体如下图,可用在签到、提醒、通知、警告、催办等方面:

 实现步骤

1.选用公共模板库中的模板

 

2.java代码 

在这里首先梳理一下Java端要做哪些事及其步骤;

  1. 定义一个消息模板的参数实体。并往里面塞值
  2. 定义一个消息配置实体。这个实体包含了一些重要的属性,主要如下 2.1:touser:接收者(用户)的 openid 2.2:template_id:所需下发的消息模板id 2.3:page:用户点击消息后跳转到小程序指定的页面路径 2.4:data:消息模板的实体
  3. 获取openid。由第2步可以知道,我们已经可以得到在微信公众平台配置的模板id、自定义的跳转路径、和第1步设置的消息模板的实体。那我们还需要设置touser(即获取到用户的openid),openid决定了我们要把消息推送给哪个用户
  4. 获取access_token。作为参数拼接出微信小程序推送消息的url接口。
  5. 推送消息

2.1参数实体

  1. package xxx.xxx.common.wx2;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. /*服务申请受理通知*/
  5. public class WxMsgTemplateFWTZ {
  6. //服务内容
  7. private Map<String, String> thing1;
  8. //温馨提示
  9. private Map<String, String> thing2;
  10. //处理人
  11. private Map<String, String> thing5;
  12. //联系人
  13. private Map<String, String> thing9;
  14. //联系方式
  15. private Map<String, String> phone_number10;
  16. public Map<String, String> getThing1() {
  17. return thing1;
  18. }
  19. public void setThing1(String thing1) {
  20. this.thing1 = getFormat(thing1);
  21. }
  22. public Map<String, String> getThing2() {
  23. return thing2;
  24. }
  25. public void setThing2(String thing2) {
  26. this.thing2 = getFormat(thing2);
  27. }
  28. public Map<String, String> getThing5() {
  29. return thing5;
  30. }
  31. public void setThing5(String thing5) {
  32. this.thing5 = getFormat(thing5);
  33. }
  34. public Map<String, String> getThing9() {
  35. return thing9;
  36. }
  37. public void setThing9(String thing9) {
  38. this.thing9 = getFormat(thing9);
  39. }
  40. public Map<String, String> getPhone_number10() {
  41. return phone_number10;
  42. }
  43. public void setPhone_number10(String phone_number10) {
  44. this.phone_number10 = getFormat(phone_number10);
  45. }
  46. public HashMap<String, String> getFormat(String str) {
  47. return new HashMap<String, String>() {
  48. {
  49. put("value", str);
  50. }};
  51. }
  52. }

2.2消息配置实体

  1. package xxx.xxx.common.wx2;
  2. public class WxMsgConfig {
  3. /*接收者(用户)的 openid*/
  4. private String touser;
  5. /*所需下发的订阅模板id*/
  6. private String template_id;
  7. /*点击消息后跳转的页面*/
  8. private String page;
  9. /*跳转小程序
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号