zoukankan      html  css  js  c++  java
  • 公众号发送模板消息

    场景: 当用户在公众号中发起了一笔支付,后台给用户发送一个消息。

    微信配置:用的个人公众号测试,访问地址  https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login&token=1212530455&lang=zh_CN

    (1) 配置域名:

    (2) 配置模板消息

    (3) 修改网页授权

    (4) 测试

    public static void sendTemplateMsg(String openId, String templateId, String navigateUrl, JSONObject json){
        JSONObject data = new JSONObject();
        data.put("template_id", templateId);  //消息模板
        data.put("touser", openId);    //接收消息的清洗工
        
        if( !StringUtils.isEmpty(navigateUrl) ){
            data.put("url", navigateUrl); 
        }
        
        data.put("data", json);  //模板的数据
        String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + getAccessToken();
        String result = connect(url, data.toJSONString());
        log.info("======== 发送模板消息. 请求参数:" + data.toJSONString() + ", 返回结果:" + result);
    }
    
    public static void main(String[] args) {
        JSONObject json = new JSONObject();
        JSONObject msg = new JSONObject();
        msg.put("value", "您好,您有一笔新订单,请注意查收。");
        msg.put("color", "#173177");    
        json.put("msg", msg);   //模板配置了一个参数 msg。 参数发送的格式为 msg : { value: '', color: ''  }, value为msg的值,color为msg的字体颜色
        
        String templateId = "Bk7r6eStfcWtv1GemYiPnzN6HWFg2YI6ywlbjFLzhs8";  //模板消息
        String navigateUrl = "www.baidu.com";  //消息跳转的详情页
        WeixinLoginUtil.sendTemplateMsg(openId, templateId, navigateUrl, json);
    }
  • 相关阅读:
    Kakuro Extension HDU
    CodeForces
    HDU
    2019牛客暑期多校训练营(第二场)F.Partition problem
    UVA
    团队冲刺6
    团队冲刺4
    团队冲刺3
    团队冲刺2
    团队冲刺1
  • 原文地址:https://www.cnblogs.com/greys/p/10731329.html
Copyright © 2011-2022 走看看