ylbtech-Java-Class-Miniprogram:com.ylbtech.common.utils.miniprogram.TemplateMessage
1.返回顶部
1.1、
package com.ylbtech.common.utils.miniprogram;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate; import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map; /**
* 模板消息
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/template-message/templateMessage.addTemplate.html
*/
public class TemplateMessage { /**
* 组合模板并添加至帐号下的个人模板库
* @param access_token 接口调用凭证
* @param id 模板标题id,可通过接口获取,也可登录小程序后台查看获取
* @param keyword_id_list 开发者自行组合好的模板关键词列表,关键词顺序可以自由搭配(例如[3,5,4]或[4,5,3]),最多支持10个关键词组合
* @param restTemplate
* @return
*/
public static String addTemplate(String access_token, String id, List<Integer> keyword_id_list, RestTemplate restTemplate) { restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8)); // 防止中文乱码
String url = "https://api.weixin.qq.com/cgi-bin/wxopen/template/add?access_token="+access_token;
//请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
//请求体
Map<String, Object> requestParam = new HashMap<>();
requestParam.put("id", id);
requestParam.put("keyword_id_list",keyword_id_list); //封装成一个请求对象
HttpEntity entity = new HttpEntity(requestParam, headers);
//发送数据方法
ResponseEntity<String> forEntity = restTemplate.postForEntity(url, entity, String.class); //得到返回的数据body
return forEntity.getBody();
} /**
* 删除帐号下的某个模板
* @param access_token 接口调用凭证
* @param template_id 要删除的模板id
* @param restTemplate
* @return
*/
public static String deleteTemplate(String access_token, String template_id, RestTemplate restTemplate) { restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8)); // 防止中文乱码
String url = "https://api.weixin.qq.com/cgi-bin/wxopen/template/del?access_token="+access_token;
//请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
//请求体
Map<String, Object> requestParam = new HashMap<>();
requestParam.put("template_id", template_id); //封装成一个请求对象
HttpEntity entity = new HttpEntity(requestParam, headers);
//发送数据方法
ResponseEntity<String> forEntity = restTemplate.postForEntity(url, entity, String.class); //得到返回的数据body
return forEntity.getBody();
} /**
* 获取模板库某个模板标题下关键词库
* @param access_token 接口调用凭证
* @param id 模板标题id,可通过接口获取,也可登录小程序后台查看获取
* @param restTemplate
* @return
*/
public static String getTemplateLibraryById(String access_token, String id, RestTemplate restTemplate) { restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8)); // 防止中文乱码
String url = "https://api.weixin.qq.com/cgi-bin/wxopen/template/library/get?access_token="+access_token;
//请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
//请求体
Map<String, Object> requestParam = new HashMap<>();
requestParam.put("id", id); //封装成一个请求对象
HttpEntity entity = new HttpEntity(requestParam, headers);
//发送数据方法
ResponseEntity<String> forEntity = restTemplate.postForEntity(url, entity, String.class); //得到返回的数据body
return forEntity.getBody();
} /**
* 获取小程序模板库标题列表
* @param access_token 接口调用凭证
* @param offset 用于分页,表示从offset开始。从 0 开始计数
* @param count 用于分页,表示拉取count条记录。最大为 20
* @param restTemplate
* @return
*/
public static String getTemplateLibraryList(String access_token, Integer offset, Integer count, RestTemplate restTemplate) { restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8)); // 防止中文乱码
String url = "https://api.weixin.qq.com/cgi-bin/wxopen/template/library/list?access_token="+access_token;
//请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
//请求体
Map<String, Object> requestParam = new HashMap<>();
requestParam.put("offset", offset);
requestParam.put("count", count); //封装成一个请求对象
HttpEntity entity = new HttpEntity(requestParam, headers);
//发送数据方法
ResponseEntity<String> forEntity = restTemplate.postForEntity(url, entity, String.class); //得到返回的数据body
return forEntity.getBody();
} /**
* 发送模板消息
* @param access_token 接口调用凭证
* @param touser 接收者(用户)的 openid
* @param template_id 所需下发的模板消息的id
* @param form_id 表单提交场景下,为 submit 事件带上的 formId;支付场景下,为本次支付的 prepay_id
* @param restTemplate
* @return
*/
public static String send(String access_token,String touser, String template_id, String form_id, RestTemplate restTemplate) { restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8)); // 防止中文乱码
String url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token="+access_token;
//请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
//请求体
Map<String, Object> requestParam = new HashMap<>();
requestParam.put("touser", touser);
requestParam.put("template_id", template_id);
//requestParam.put("page", "index");
requestParam.put("form_id", form_id);
//requestParam.put("data", "");
//requestParam.put("emphasis_keyword", ""); //封装成一个请求对象
HttpEntity entity = new HttpEntity(requestParam, headers);
//发送数据方法
ResponseEntity<String> forEntity = restTemplate.postForEntity(url, entity, String.class); //得到返回的数据body
return forEntity.getBody();
}
}
1.2、
2.返回顶部
 
3.返回顶部
 
4.返回顶部
 
5.返回顶部
 
 
6.返回顶部
 
作者:ylbtech
出处:http://ylbtech.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

Java-Class-Miniprogram:com.ylbtech.common.utils.miniprogram.TemplateMessage的更多相关文章

  1. Java-Class-Miniprogram:com.common.utils.miniprogram.Auth

    ylbtech-Java-Class-miniprogram:com.common.utils.miniprogram.Auth 1.返回顶部 1.1. package com.ylbtech.com ...

  2. 启动服务报错:nested exception is java.lang.NoSuchMethodError: org.apache.cxf.common.jaxb.JAXBUtils.closeUnmarshaller(Ljavax/xml/bind/Unmarshaller;)V

    1.启动tomcat时报错:Error creating bean with name 'payInfService': Invocation of init method failed; neste ...

  3. Java-Class-C:com.ylbtech.api.platfrom.util.RedisUtils.class

    ylbtech-Java-Class-C:com.ylbtech.api.platfrom.util.RedisUtils.class 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶 ...

  4. Java虚拟机9:Java类加载机制

    前言 我们知道我们写的程序经过编译后成为了.class文件,.class文件中描述了类的各种信息,最终都需要加载到虚拟机之后才能运行和使用.而虚拟机如何加载这些.class文件?.class文件的信息 ...

  5. Caused by: java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.MetadataPro

    1.错误描述 信息: MLog clients using java 1.4+ standard logging. 2014-7-12 19:29:20 com.mchange.v2.c3p0.C3P ...

  6. Java虚拟机13:Java类加载机制

    前言 我们知道我们写的程序经过编译后成为了.class文件,.class文件中描述了类的各种信息,最终都需要加载到虚拟机之后才能运行和使用.而虚拟机如何加载这些.class文件?.class文件的信息 ...

  7. Java日期类:Date和Calendar的使用

    总是使用这两个类,总是需要百度.还不如一次全部整理完. 一.介绍: Date 类 Date 表示特定的瞬间,精确到毫秒. 在 JDK 1.1 之前,类 Date 有两个其他的函数.它允许把日期解释为年 ...

  8. Java进阶学习:将文件上传到七牛云中

    Java进阶学习:将文件上传到七牛云中 通过本文,我们将讲述如何利用七牛云官方SDK,将我们的本地文件传输到其存储空间中去. JavaSDK:https://developer.qiniu.com/k ...

  9. 基于JavaMail的Java邮件发送:复杂邮件发送

    参考:http://blog.csdn.net/xietansheng/article/details/51722660package com.bfd.ftp.utils;import java.ut ...

随机推荐

  1. Hibernate插入错误:GenericJDBCException: could not insert:

    数据库中一般不能建立user(表名为User)表,将User类改名,又一次建立映射,问题就能够解决 当然,还有还有一种情况.就是类中id类型错误.要设置为Integer型才干够设置自己主动增长,否则也 ...

  2. ObjectiveC开发教程--字符串的连接

    NSString *type = @"hello"; NSString *subtype = @"good"; NSString *typesub = [NSS ...

  3. 金典 SQL笔记(6)

    page223-索引 --利用SQL 语句创建索引 --CREATE INDEX 索引名称on 表名(字段 ,字段, 字段字段n) --索引名称必须为唯一的,字段 ,字段, 同意一个到多个 --范例为 ...

  4. Android应用程序无法读写USB设备的解决方法

    假设android系统中的API或者apk无法读写usb设备.可能是没有加入读写usb的权限,须要依照例如以下方法进行设置: 1. 在android.hardware.usb.host.xml文件里加 ...

  5. mac 显示隐藏文件的命令行和快捷键

    命令行方式: 显示隐藏文件: defaults write com.apple.Finder AppleShowAllFiles YES;KillAll Finder 不显示隐藏文件: default ...

  6. cached

    /proc/sys/vm/ 关于Linux cached内存简析 - CSDN博客 http://blog.csdn.net/fox_hacker/article/details/41351687 [ ...

  7. HDFS02

    读取流程 写流程 ============SecondaryNameNode============ Namenode的一个快照 周期性的备份namenode 记录namenode中的metadata ...

  8. SQL 字符串处理函数大全

    select语句中只能使用sql函数对字段进行操作(链接sql server),select 字段1 from 表1 where 字段1.IndexOf("云")=1;这条语句不对 ...

  9. PCB WebAPI 接口测试工具与接口文档生成

    我们自己写WebAPI或调用对方系统提供的WebAPI时,测试WebAPI接口工具用哪些工具呢. 这里将3种WebAPI常用到的工具使用说明.主要是讲对第3种WebApiTestClientWebAp ...

  10. codevs3304水果姐逛街(线段数)

    3304 水果姐逛水果街Ⅰ  时间限制: 2 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond   题目描述 Description 水果姐今天心情不错,来到了水果街. 水果 ...