直接使用这个接口即可。
public class HttpUtils {
public static final String ROBOT_URL = "http://openapi.tuling123.com/openapi/api/v2";
public static final String QINGYUN_URL= "http://api.qingyunke.com/api.php?key=free&appid=0&msg={1}";
public static final String DEFAULT_REPLY = "没时间理你,鸡鸡玩去~";
public static String qingyunReply(String msg){
RestTemplate client = new RestTemplate();
String replyContent = client.getForObject(QINGYUN_URL, String.class,msg);
JsonNode tree = null;
try {
ObjectMapper om = new ObjectMapper();
tree = om.readTree(JSONObject.parseObject(replyContent).toString());
} catch (IOException e) {
e.printStackTrace();
}
List<JsonNode> code = tree.findValues("result");
List<JsonNode> content = tree.findValues("content");
String resultCode = code.get(0).toString();
if(Integer.valueOf(resultCode) > 0){
return DEFAULT_REPLY;
}
log.info("qingyunReply response:{}",content.get(0).toString());
String responseContent = content.get(0).toString().replace("{br}","\n");
responseContent = responseContent.replace("\"","");
return responseContent;
}
public static void main(String[] args) {
System.out.println(qingyunReply("天气广州"));
}
}