官网文档地址
https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html
参考代码
@Resource RestTemplate restTemplate; @RequestMapping("/test") public String test(){ String token = "xxxxxxxxxxxxxxxxxxxxxxxx"; String teamName = "微信推送测试"; //接口地址 String sendMsgApi = String.format("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%s",token); //要发给指定的人openId String toUser = "xxxxxxxxxxxxxxxxx"; //消息模板id String template_id = "xxxxxxxxxxxxxxxxxxxx"; //整体参数map Map<String, Object> paramMap = new HashMap<String, Object>(); //消息主题显示相关map Map<String, Object> dataMap = new HashMap<String, Object>(); //根据自己的模板定义内容和颜色 dataMap.put("first",new WechatData(teamName,"#fff")); paramMap.put("touser", toUser); paramMap.put("template_id", template_id); paramMap.put("data", dataMap); //调用微信接口,发送模板消息 Map<String,Object> result = restTemplate.postForObject(sendMsgApi,paramMap, Map.class); if(result.get("errcode").equals(0)){ // return "ok"; } return "ko"; } class WechatData{ private String name; private String color; public WechatData(){ } public WechatData(String name,String color){ } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } }