浩晨众云网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
本文实例为大家分享了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; }