微信公众号发送消息模板(java)

1 public static JSONObject sendModelMessage(ServletContext context,JSONObject jsonMsg) { 2 System.out.println("消息内容:"+jsonMsg); 3 boolean result = false; 4 try { 5 getWX_AccessToken(context); 6 } catch (Exception e) { 7 // TODO Auto-generated catch block 8 e.printStackTrace(); 9 } 10 // 拼接请求地址 11 String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN"; 12 requestUrl = requestUrl.replace("ACCESS_TOKEN", context.getAttribute(ContextTokenName).toString()); 1314 // 发送客服消息 15 JSONObject jsonObject = getJsonByWX(requestUrl, context, "POST",jsonMsg, false); 16 17 if (null != jsonObject) { 18 int errorCode = jsonObject.getInt("errcode"); 19 String errorMsg = jsonObject.getString("errmsg"); 20 if (0 == errorCode) { 21 result = true; 22 System.out.println("模板消息发送成功 errcode:{} "+errorCode+"----"+errorMsg); 23 } else { 24 System.out.println("模板消息发送失败 errcode:{} "+errorCode+"----"+errorMsg); 25 } 26 } 27 28 return null; 29 }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zgzgpf.html