@Test(invocationCount = 5, threadPoolSize = 3) public void testSendTemplateMsg() throws WxErrorException { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); TestConfig config = (TestConfig) this.wxService.getWxMaConfig(); WxMaTemplateMessage templateMessage = WxMaTemplateMessage.builder() .toUser(config.getOpenid()) .formId("FORMID") .page("index") .data(Lists.newArrayList( new WxMaTemplateMessage.Data("keyword1", "339208499", "#173177"), new WxMaTemplateMessage.Data("keyword2", dateFormat.format(new Date()), "#173177"), new WxMaTemplateMessage.Data("keyword3", "粤海喜来登酒店", "#173177"), new WxMaTemplateMessage.Data("keyword4", "广州市天河区天河路208号", "#173177"))) .templateId(config.getTemplateId()) .emphasisKeyword("keyword1.DATA") .build(); this.wxService.getMsgService().sendTemplateMsg(templateMessage); }
@Override public void sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException { String responseContent = this.wxMaService.post(TEMPLATE_MSG_SEND_URL, templateMessage.toJson()); JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject(); if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) { throw new WxErrorException(WxError.fromJson(responseContent)); } }
WxMaMsgServiceImpl implements WxMaMsgService { @Override public void sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException { String responseContent = this.wxMaService.post(TEMPLATE_MSG_SEND_URL, templateMessage.toJson()); JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject(); if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) { throw new WxErrorException(WxError.fromJson(responseContent)); } } }
WxMaMsgServiceImpl implements WxMaMsgService { @Override public void sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException { String responseContent = this.wxMaService.post(TEMPLATE_MSG_SEND_URL, templateMessage.toJson()); JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject(); if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) { throw new WxErrorException(WxError.fromJson(responseContent)); } } WxMaMsgServiceImpl(WxMaService wxMaService); }
WxMaMsgServiceImpl implements WxMaMsgService { @Override public void sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException { String responseContent = this.wxMaService.post(TEMPLATE_MSG_SEND_URL, templateMessage.toJson()); JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject(); if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) { throw new WxErrorException(WxError.fromJson(responseContent)); } } WxMaMsgServiceImpl(WxMaService wxMaService); @Override boolean sendKefuMsg(WxMaKefuMessage message); @Override void sendTemplateMsg(WxMaTemplateMessage templateMessage); }
WxMaMsgServiceImpl implements WxMaMsgService { @Override public void sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException { String responseContent = this.wxMaService.post(TEMPLATE_MSG_SEND_URL, templateMessage.toJson()); JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject(); if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) { throw new WxErrorException(WxError.fromJson(responseContent)); } } WxMaMsgServiceImpl(WxMaService wxMaService); @Override boolean sendKefuMsg(WxMaKefuMessage message); @Override void sendTemplateMsg(WxMaTemplateMessage templateMessage);  }