本文整理汇总了Java中me.chanjar.weixin.mp.bean.WxMpCustomMessage.WxArticle方法的典型用法代码示例。如果您正苦于以下问题:Java WxMpCustomMessage.WxArticle方法的具体用法?Java WxMpCustomMessage.WxArticle怎么用?Java WxMpCustomMessage.WxArticle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类me.chanjar.weixin.mp.bean.WxMpCustomMessage
的用法示例。
在下文中一共展示了WxMpCustomMessage.WxArticle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onResult
import me.chanjar.weixin.mp.bean.WxMpCustomMessage; //导入方法依赖的package包/类
public void onResult(UnderstanderResult result) {
String resultString = result.getResultString();
LOGGER.info("onResult = " + resultString);
ObjectMapper objectMapper = new ObjectMapper();
try {
SemanticResponse response = objectMapper.readValue(resultString, SemanticResponse.class);
if (response.getRc() == 0) {
Semantic sematic = response.getSemantic();
Slots slots = sematic.getSlots();
if(slots.getStartLoc()!=null && slots.getEndLoc()!=null && slots.getStartDate()!=null) {
String fromCity = CityToAirportCode.toCode(slots.getStartLoc().getCityAddr());
String toCity = CityToAirportCode.toCode(slots.getEndLoc().getCityAddr());
LOGGER.info("fromCity = {}, toCity = {}",fromCity,toCity);
if(fromCity == null) {
fromCity = "SHA";
}
if(toCity == null) {
toCity = "BJS";
}
String fromDate = slots.getStartDate().getDate();
String request = "{ \"fromCity\": \""+fromCity+"\", \"toCity\": \""+toCity+"\", \"fromDate\": \"" + fromDate +"\", \"sort\": \"date\", \"spName\":\"tdx\", \"orderRule\":\"asc\", \"userToken\":\""
+ this.flight_user_token+"\", \"operation\": \"SEARCHLOWEST\" } ";
RestTemplate rt = new RestTemplate();
// 机票搜索服务
String stringResponse = rt.postForObject(this.flight_search_url, request, String.class);
stringResponse = new String(stringResponse.getBytes("ISO-8859-1"), "UTF-8");
FlightSearchResponse flightSearchResponse = objectMapper.readValue(stringResponse, FlightSearchResponse.class);
if(flightSearchResponse.getRescode().equals("0")) {
List<FlightSchedule> schedules = flightSearchResponse.getFlightSchedules();
WxMpCustomMessage.WxArticle article1 = new WxMpCustomMessage.WxArticle();
article1.setUrl("#");
article1.setPicUrl("http://pngimg.com/upload/plane_PNG5249.png");
article1.setDescription("总共"+schedules.size()+"条航班");
article1.setTitle(slots.getStartLoc().getCityAddr()+"到"+slots.getEndLoc().getCityAddr()+"的前5条航班");
List<WxMpCustomMessage.WxArticle> articles = new ArrayList<>();
articles.add(article1);
for (int i = 0; i < schedules.size() && i < 5; i++) {
FlightSchedule flightSchedule = schedules.get(i);
String line = flightSchedule.getAirlineCompany() +" - " +flightSchedule.getFlightNo() +" - ¥:"+ flightSchedule.getLowestPrice()
+" - 起飞:"+ flightSchedule.getFromDate().substring(0,flightSchedule.getFromDate().indexOf("."))
+" - 到达:"+ flightSchedule.getToDate().substring(0,flightSchedule.getToDate().indexOf(".")) ;
WxMpCustomMessage.WxArticle article2 = new WxMpCustomMessage.WxArticle();
article2.setUrl("#");
article2.setPicUrl("http://pngimg.com/upload/plane_PNG5249.png");
article2.setDescription("确认订票?");
article2.setTitle(line);
articles.add(article2);
}
NewsBuilder builder = WxMpCustomMessage.NEWS().toUser(wxMessage.getFromUserName());
for (WxMpCustomMessage.WxArticle wxArticle : articles) {
builder.addArticle(wxArticle);
}
WxMpCustomMessage message = builder.build();
// 设置消息的内容等信息
wxMpService.customMessageSend(message);
} else {
LOGGER.error(flightSearchResponse.toString());
}
} else {
LOGGER.equals(slots.toString());
}
}
} catch (WxErrorException e) {
LOGGER.error("Failed to send custom message", e);
}catch (Exception e1) {
LOGGER.error("Unexpected exception", e1);
}
}
示例2: addArticle
import me.chanjar.weixin.mp.bean.WxMpCustomMessage; //导入方法依赖的package包/类
public NewsBuilder addArticle(WxMpCustomMessage.WxArticle article) {
this.articles.add(article);
return this;
}