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

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);
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

haibo8023

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值