public static void templateSend(String appid,String secret,WxMssVO wxMssVo){
String SEND_INFO_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";
RestTemplate restTemplate = new RestTemplate();
JSONObject json = getAccessToken(appid,secret);
log.info("获取微信公众号token返回结果:"+JSON.toJSONString(json));
String accessToken=json.getString("access_token");
String url = SEND_INFO_URL + accessToken;
wxMssVo.setData(getSendData(wxMssVo));
System.out.println("请求微信公众号参数:"+JSON.toJSONString(wxMssVo));
ResponseEntity<String> responseEntity =
restTemplate.postForEntity(url, JSON.toJSONString(wxMssVo), String.class);
log.info("发送微信公众号通知返回结果:"+responseEntity.getBody());
}
public static void main(String[] args) throws IOException {
WxMssVO wxMssVO=new WxMssVO();
Map<String,Object> map=new HashMap<>();
map.put("character_string1","/order/detail/upgradeCourse/523");
map.put("time2", DateUtils.getTime());
String msg="缺少课程包id:请前往班级管理-关联课程包绑定班级消耗的课程包";
map.put("thing3",msg.length()<=20?msg:msg.substring(0,17)+"...");
wxMssVO.setData(map);
wxMssVO.setTemplate_id("xxxxxx");
wxMssVO.setTouser("xxxxxx");
templateSend(null,null,wxMssVO);
}