java微信公众号发送消息模板-创新互联

本文实例为大家分享了java微信公众号发送消息模板的具体代码,供大家参考,具体内容如下

网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、微信小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了吉县免费建站欢迎大家使用!

这段时间接触公众号开发,写下向用户发送消息模板的接口调用

先上接口代码

public static JSONObject sendModelMessage(ServletContext context,JSONObject jsonMsg) {
    System.out.println("消息内容:"+jsonMsg);
    boolean result = false;
    try {
      getWX_AccessToken(context);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    // 拼接请求地址
    String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN";
    requestUrl = requestUrl.replace("ACCESS_TOKEN", context.getAttribute(ContextTokenName).toString());
    // 发送客服消息
    JSONObject jsonObject = getJsonByWX(requestUrl, context, "POST",jsonMsg, false);
 
    if (null != jsonObject) {
      int errorCode = jsonObject.getInt("errcode");
      String errorMsg = jsonObject.getString("errmsg");
      if (0 == errorCode) {
        result = true;
        System.out.println("模板消息发送成功 errcode:{} "+errorCode+"----"+errorMsg);
      } else {
        System.out.println("模板消息发送失败 errcode:{} "+errorCode+"----"+errorMsg);
      }
    }
 
    return null;
  }

标题名称:java微信公众号发送消息模板-创新互联
本文网址:http://myzitong.com/article/dioidh.html