|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void handle(String consumerTag, Delivery message) throws IOException { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String messages = new String(message.getBody(), "UTF-8"); | 
|---|
|  |  |  | JSONObject messageJsonParam=JSONObject.parseObject(messages); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | bulderParam.put("gzhAppid", gzhAppid.getParamValue()); | 
|---|
|  |  |  | bulderParam.put("template_id", template.getUuid()); | 
|---|
|  |  |  | bulderParam.put("messageJsonParam", messageJsonParam); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //调用模板计算出消息体 | 
|---|
|  |  |  | Map msgResult = templateMessageBulder.buildMsg(bulderParam); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(msgResult.containsKey("error")){ | 
|---|
|  |  |  | //错误消息处理 | 
|---|
|  |  |  | LogUtil.error("模板消息发送失败:"+msgResult.get("error")); | 
|---|
|  |  |  | LogUtil.error("模板消息发送内容:"+msgResult.get("error")); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | //正常返回消息 | 
|---|
|  |  |  | 
|---|
|  |  |  | String url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=ACCESS_TOKEN".replaceAll("ACCESS_TOKEN", ACCESS_TOKEN); | 
|---|
|  |  |  | for (Object msg : msgList) { | 
|---|
|  |  |  | UniformMsgPojo uniformMsgPojo = (UniformMsgPojo) msg; | 
|---|
|  |  |  | LogUtil.debug("微信小程序模板消息推送:" + JSONObject.toJSON(uniformMsgPojo).toString()); | 
|---|
|  |  |  | //推送消息到微信 | 
|---|
|  |  |  | JSONObject result = HttpClientUtil.sendPostWithJson(url, JSONObject.toJSON(uniformMsgPojo).toString()); | 
|---|
|  |  |  | //微信返回值 | 
|---|
|  |  |  | LogUtil.debug("微信小程序模板消息推送结果:" + result.toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | LogUtil.error("消费者执行异常", e); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|