微信公众号发送中奖模板消息

xiaoxiao2021-02-28  135

WinnerMessage实体类

private String touser; //用户OpenID private String template_id; //模板消息ID private String url; //URL置空,则在发送后,点击模板消息会进入一个空白页面(ios),或无法点击(android)。 private String topcolor; //标题颜色 private Map<String,Data> data; //详细内容

最终代码

public void sendWinnerMessage(String drawName, String activityName, String liveTime, String cinemaName, String userName, String openId, String access_token) { String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token; WinnerMessage temp = new WinnerMessage(); temp.setUrl("http://portal.e-wifi.com/douyawechat/douyaPrize/check.html"); temp.setTouser(openId); temp.setTopcolor("#000000"); temp.setTemplate_id("u3Bbw5gZeatsG9_K0h9N8eX1gmrJLNVyBDG2__3zjzA"); Map<String, Data> m = new HashMap<String, Data>(); Data first = new Data(); first.setColor("#000000"); first.setValue("恭喜您获得【" + drawName + "】"); m.put("first", first); Data keyword1 = new Data(); keyword1.setColor("#000000"); keyword1.setValue(activityName); m.put("keyword1", keyword1); Data keyword2 = new Data(); keyword2.setColor("#000000"); keyword2.setValue(liveTime); m.put("keyword2", keyword2); Data keyword3 = new Data(); keyword3.setColor("#000000"); keyword3.setValue(cinemaName); m.put("keyword3", keyword3); Data keyword4 = new Data(); keyword4.setColor("#000000"); keyword4.setValue(userName); m.put("keyword4", keyword4); Data remark = new Data(); remark.setColor("#000000"); remark.setValue("客服电话:400-680-8690\n" + "备注:为方便工作人员将与您联系,请回复您的手机号,随后工作人员将与您联系。"); m.put("Remark", remark); temp.setData(m); String jsonString = net.sf.json.JSONObject.fromObject(temp).toString(); net.sf.json.JSONObject jsonObject = MessageUtil.HttpRequest(url, "POST", jsonString); System.out.println(jsonObject); int result = 0; if (null != jsonObject) { if (0 != jsonObject.getInt("errcode")) { result = jsonObject.getInt("errcode"); logger.error("错误 errcode:{} errmsg:{}", jsonObject.getInt("errcode"), jsonObject.getString("errmsg")); } } logger.info("模板消息发送结果:" + result); } }
转载请注明原文地址: https://www.6miu.com/read-32177.html

最新回复(0)