首页 微信文章精选 微信文章精选示例代码 获取文章[Java]

获取文章示例代码[Java]

作者:xiezhongpian 阅读数:1606 上传时间:2017-05-09

获取文章

package api.jisuapi.weixinarticle;

import api.util.HttpUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class Get {

	public static final String APPKEY = "your_appkey_here";// 你的appkey
	public static final String URL = "https://api.jisuapi.com/weixinarticle/get";
	public static final String channel = "1";
	public static final String num = "10";
	public static final String start = "0";

	public static void NewGet() {
		String result = null;
		String url = URL + "?channel=" + channel + "&num=" + num + "&start=" + start + "&appkey=" + APPKEY;

		try {
			result = HttpUtil.sendGet(url, "utf-8");
			JSONObject json = JSONObject.fromObject(result);
			if (json.getInt("status") != 0) {
				System.out.println(json.getString("msg"));
			} else {
				JSONObject resultarr = (JSONObject) json.opt("result");
				String channel = resultarr.getString("channel");
				String channelid = resultarr.getString("channelid");
				String total = resultarr.getString("total");
				String num = resultarr.getString("num");
				String start = resultarr.getString("start");
				System.out.println(channel + " " + channelid + " " + total + " " + num + " " + start);
				JSONArray list = resultarr.optJSONArray("list");
				for (int i = 0; i < list.size(); i++) {
					JSONObject obj = (JSONObject) list.opt(i);
					String title = obj.getString("title");
					String time = obj.getString("time");
					String weixinname = obj.getString("weixinname");
					String weixinaccount = obj.getString("weixinaccount");
					String weixinsummary = obj.getString("weixinsummary");
					String channelid1 = obj.getString("channelid");
					String pic = obj.getString("pic");
					String content = obj.getString("content");
					String url1 = obj.getString("url");
					String readnum = obj.getString("readnum");
					String likenum = obj.getString("likenum");
					System.out.println(title + " " + time + " " + weixinname + " " + weixinaccount + " " + weixinsummary
							+ " " + channelid1 + " " + pic + " " + content + " " + url1 + " " + readnum + " "
							+ likenum);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}