首页 八字排盘 八字排盘示例代码 八字排盘[Java]

八字排盘示例代码[Java]

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

八字排盘

package api.jisuapi.bazi;

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

public class Paipan {

	public static final String APPKEY = "your_appkey_here";// 你的appkey
	public static final String URL = "https://api.jisuapi.com/bazi/paipan";
	public static final String year = "2009";
	public static final String month = "10";
	public static final String day = "18";
	public static final String hour = "2";
	public static final String minute = "5";
	public static final String sex = "1";
	public static final String city = "";// utf8
	public static final int istaiyang = 0;
	public static final int islunar = 0;

	public static void Get() {
		String result = null;
		String url = URL + "?year=" + year + "&month=" + month + "&day=" + day + "&hour=" + hour + "&minute=" + minute
				+ "&sex=" + sex + "&city=" + city + "&istaiyang=" + istaiyang + "&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 = json.optJSONObject("result");
				String year = resultarr.getString("year");
				String month = resultarr.getString("month");
				String day = resultarr.getString("day");
				String hour = resultarr.getString("hour");
				String minute = resultarr.getString("minute");
				String name = resultarr.getString("name");
				String city = resultarr.getString("city");
				String istaiyang = resultarr.getString("istaiyang");
				String lunaryear = resultarr.getString("lunaryear");
				String lunarmonth = resultarr.getString("lunarmonth");
				String lunarday = resultarr.getString("lunarday");
				String lunarhour = resultarr.getString("lunarhour");
				String animal = resultarr.getString("animal");
				String yearganzhi = resultarr.getString("yearganzhi");
				System.out.println(year + " " + month + " " + day + " " + hour + " " + minute + " " + name + " " + city
						+ " " + istaiyang + " " + lunaryear + " " + lunarmonth + " " + lunarday + " " + lunarhour + " "
						+ lunarday + " " + animal + " " + yearganzhi);
				if (resultarr.opt("jieqiprev") != null) {
					JSONObject jieqiprev = resultarr.optJSONObject("jieqiprev");
					String jieqiname = jieqiprev.getString("jieqiname");
					String date = jieqiprev.getString("date");
					System.out.println(jieqiname + " " + date);
				}
				if (resultarr.opt("jieqinext") != null) {
					JSONObject jieqinext = resultarr.optJSONObject("jieqinext");
					String jieqiname = jieqinext.getString("jieqiname");
					String date = jieqinext.getString("date");
					System.out.println(jieqiname + " " + date);
				}
				JSONArray bazi = resultarr.optJSONArray("bazi");
				for (int i = 0; i < bazi.size(); i++) {
					System.out.print(bazi.get(i) + " ");
				}
				String taiyuan = resultarr.getString("taiyuan");
				String minggong = resultarr.getString("minggong");
				JSONArray xunkong = resultarr.optJSONArray("xunkong");
				for (int i = 0; i < xunkong.size(); i++) {
					System.out.print(xunkong.get(i) + " ");
				}
				System.out.println(taiyuan + " " + minggong);
				if (resultarr.opt("qiyun") != null) {
					JSONObject qiyun = resultarr.optJSONObject("qiyun");
					String year1 = qiyun.getString("year");
					String month1 = qiyun.getString("month");
					String day1 = qiyun.getString("day");
					String hour1 = qiyun.getString("hour");
					System.out.println(year1 + " " + month1 + " " + day1 + " " + hour1);
				}
				if (resultarr.opt("jiaoyun") != null) {
					JSONObject jiaoyun = resultarr.optJSONObject("jiaoyun");
					String year1 = jiaoyun.getString("year");
					String month1 = jiaoyun.getString("month");
					String day1 = jiaoyun.getString("day");
					String hour1 = jiaoyun.getString("hour");
					System.out.println(year1 + " " + month1 + " " + day1 + " " + hour1);
				}
				if (resultarr.opt("qiankunzao") != null) {
					JSONArray qiankunzao = resultarr.optJSONArray("qiankunzao");
					for (int i = 0; i < qiankunzao.size(); i++) {
						JSONArray arr = (JSONArray) qiankunzao.getJSONArray(i);
						for (int j = 0; j < arr.size(); j++) {
							System.out.print(arr.get(j) + " ");
						}
						System.out.println();
					}
				}
				JSONArray nayin = resultarr.optJSONArray("nayin");
				for (int i = 0; i < nayin.size(); i++) {
					System.out.print(nayin.get(i) + " ");
				}
				if (resultarr.opt("shensha") != null) {
					JSONArray shensha = resultarr.optJSONArray("shensha");
					for (int i = 0; i < shensha.size(); i++) {
						JSONArray arr = (JSONArray) shensha.getJSONArray(i);
						for (int j = 0; j < arr.size(); j++) {
							System.out.print(arr.get(j) + " ");
						}
						System.out.println();
					}
				}
				if (resultarr.opt("dayun") != null) {
					JSONObject dayun = resultarr.optJSONObject("dayun");
					JSONArray nayin1 = (JSONArray) dayun.opt("nayin");
					for (int i = 0; i < nayin1.size(); i++) {
						System.out.print(nayin1.get(i) + " ");
					}
					JSONArray shishen = (JSONArray) dayun.opt("shishen");
					for (int i = 0; i < shishen.size(); i++) {
						System.out.print(shishen.get(i) + " ");
					}
					JSONArray ganzhi = (JSONArray) dayun.opt("ganzhi");
					for (int i = 0; i < ganzhi.size(); i++) {
						System.out.print(ganzhi.get(i) + " ");
					}
					JSONArray sui = (JSONArray) dayun.opt("sui");
					for (int i = 0; i < sui.size(); i++) {
						System.out.print(sui.get(i) + " ");
					}
					JSONArray year1 = (JSONArray) dayun.opt("year");
					for (int i = 0; i < year1.size(); i++) {
						System.out.print(year1.get(i) + " ");
					}
				}
				System.out.println();
				if (resultarr.opt("liunian") != null) {
					JSONArray liunian = resultarr.optJSONArray("liunian");
					for (int i = 0; i < liunian.size(); i++) {
						JSONArray arr = (JSONArray) liunian.getJSONArray(i);
						for (int j = 0; j < arr.size(); j++) {
							System.out.print(arr.get(j) + " ");
						}
						System.out.println();
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}