@Override public WxMsg testwhitelist(White white) { String jsonString = JSON.toJSONString(white); String url = String.format(CARD_TESTWHITELIST_URL, this.weixinProxy.httpToken().getAccessToken()); byte[] bytes = HttpClientUtil.httpPost(url, jsonString); return JSON.parseObject(bytes, WxMsg.class); }
@Override public Card batchCard(ReqBatchCatch reqBatchCatch) { Utils.validate(reqBatchCatch); String jsonString = JSON.toJSONString(reqBatchCatch); String token = this.weixinProxy.httpToken().getAccessToken(); String url = String.format(BATCH_CARD_URL, token); byte[] bytes = HttpClientUtil.httpPost(url, jsonString); return JSON.parseObject(bytes, Card.class); }
@Override public UserCard getUserCardList(ReqUserCard userCard) { Utils.validate(userCard); String jsonString = JSON.toJSONString(userCard); String token = this.weixinProxy.httpToken().getAccessToken(); String url = String.format(USER_CARD_LIST_URL, token); byte[] bytes = HttpClientUtil.httpPost(url, jsonString); return JSON.parseObject(bytes, UserCard.class); }
@Override public Card getCard(JSONObject params) throws IOException { Object cardId = params.get("card_id"); Assert.notNull(cardId, "卡券ID不能为空"); String jsonString = params.toString(); String token = this.weixinProxy.httpToken().getAccessToken(); String url = String.format(CARD_URL, token); byte[] bytes = HttpClientUtil.httpPost(url, jsonString); return JSON.parseObject(bytes, Card.class); }
@Override public WxMsg createMenu(List<Button> buttons) { Map<String, List<Button>> btns = new HashMap<>(); btns.put("button", buttons); String jsonString = JSON.toJSONString(btns); String token = this.weixinProxy.httpToken().getAccessToken(); String url = String.format(CREATE_MENU_URL, token); byte[] bytes = HttpClientUtil.httpPost(url, jsonString); return JSON.parseObject(bytes, WxMsg.class); }
@Override public Message httpTemplateMsg(TemplateMsg templateMsg) { Token token = this.weixinProxy.httpToken(); String templateUrl = String.format(TEMPLATE_URL, token.getAccessToken()); String req = JSON.toJSONString(templateMsg); byte[] bytes = HttpClientUtil.httpPost(templateUrl, req); Message message = JSON.parseObject(bytes, Message.class); if (log.isInfoEnabled()) { log.info( "返回模板消息信息:{}", JSON.toJSONString( message, SerializerFeature.PrettyFormat, SerializerFeature.WriteClassName)); } return message; }
@Override public Poi httpPoi(String poiId) { Assert.notNull(poiId, "获取门店的poi_id不能为空"); JSONObject jsonObject = new JSONObject(); jsonObject.put("poi_id", poiId); String req = jsonObject.toJSONString(); String url = String.format(POI_URL, this.weixinProxy.httpToken().getAccessToken()); byte[] bytes = HttpClientUtil.httpPost(url, req); Poi poi = JSON.parseObject(bytes, Poi.class); if (log.isInfoEnabled()) { log.info( "返回门店信息:{}", JSON.toJSONString(poi, SerializerFeature.PrettyFormat, SerializerFeature.WriteClassName)); } return poi; }
@Override public Ticket httpTicket(ReqTicket reqTicket) { if (log.isInfoEnabled()) { log.info( JSON.toJSONString( reqTicket, SerializerFeature.PrettyFormat, SerializerFeature.WriteClassName)); } Token token = weixinProxy.httpToken(); String ticketUrl = null; TicketType ticketType = null; if (reqTicket.getActionName() == QrcodeType.QR_CARD) { ticketUrl = String.format(CARD_QRCODE_URL, token.getAccessToken()); // 卡券投放的二维码ticket路径 ticketType = TicketType.QR_CARD_TICKET; } else { ticketUrl = String.format(TICKET_URL, token.getAccessToken()); // 二维码ticket路径 ticketType = TicketType.QR_TICKET; } Assert.notNull(ticketUrl, "ticket url 不能为空"); String jsonParam = JSON.toJSONString(reqTicket, SerializerFeature.WriteNonStringKeyAsString); byte[] results = HttpClientUtil.httpPost(ticketUrl, jsonParam); Ticket ticket = JSON.parseObject(results, Ticket.class); ticket.setType(ticketType); ticket.setCreateTime(System.currentTimeMillis()); if (reqTicket.getActionName() == QrcodeType.QR_CARD) { ticket.setCode(reqTicket.getCode()); ticket.setCardId(reqTicket.getCardId()); ticket.setOpenid(reqTicket.getOpenid()); ticket.setUniqueCode(reqTicket.getUniqueCode()); ticket.setOuterId(reqTicket.getOuterId()); } if (reqTicket.getActionName() == QrcodeType.QR_CARD) {} return ticket; }