java实现-强智教务系统API文档-全部java封装

项目的目录结构

 

AIP 接口类

package dao;

import net.sf.json.JSONObject;

/**
 * 实现强智API  https://qzapi.github.tlingc.com/api/getKbcxAzc/
 */

public interface Qzapi {
    /**
     * 相当于登录
     * @param xh  学号
     * @param pwd  密码
     * @return
     */
    JSONObject authUser(String xh,String pwd);

    /**
     *获取所提交的日期的时间、周次、学年等信息
     * @param currDate //格式为"YYYY-MM-DD",必填,留空调用成功,但返回值均为null
     * @return
     */
    JSONObject getCurrentTime(String currDate);

    /**
     * 获取一周的课程信息
     * @param xh 必填,使用与获取token时不同的学号,则可以获取到新输入的学号的课表
     * @param xnxqid 格式为"YYYY-YYYY-X",非必填,不包含时返回当前日期所在学期课表
     * @param zc //必填
     * @return
     */
    JSONObject getKbcxAzc(String xh,String xnxqid,String zc);

    /**
     *获取成绩信息
     * @param xh //必填,可以添加非本token学号查询他人成绩
     * @param xnxqid //非必填,不填输出全部成绩
     * @return
     */
    JSONObject getCjcx(String xh,String xnxqid);

    /**
     * 获取考试信息
     * @param xh
     * @return
     */
    JSONObject getKscx(String xh);

    /**
     * 获取某个校区教学楼信息
     * @param xqid //校区ID
     * @return
     */
    JSONObject getJxlcx(String xqid);

    /**
     * 获取空教室信息
     * @param time  //格式"YYYY-MM-DD",非必填,默认返回当前日期空闲教室
     * @param idleTime //有allday,am,pm,night四种取值,非必填,默认值疑似allday
     * @param xqid  //校区ID,非必填
     * @param jxlid //教学楼ID,非必填
     * @param classroomNumber  //可选项 30,30-40,40-50,60(分别意为30人以下,30-40人,···,60人以上)
     * @return
     */
    JSONObject getKxJscx(String time,String idleTime,String xqid,String jxlid,String classroomNumber);

    /**
     *  获取当前token的用户信息 注意:此API测试与参考文档不同,待修改/补充
     * @param xh 疑似非必填,添加或不添加本参数返回相同值
     * @return
     */
    JSONObject getStudentIdInfo(String xh);

    /**
     *
     * @param xh 学号
     * @return
     */
    JSONObject getUserInfo(String xh);

    /**
     * 获取学年学期信息
     * @param xh 2017xxxxxx'  //非必填
     * @return
     */
    JSONObject getXnxq(String xh);

    /**
     * 获取校区信息
     * @return
     */
    JSONObject getXqcx();

}

实现接口

package dao;

import net.sf.json.JSONObject;
import org.apache.http.message.BasicNameValuePair;
import utils.Util;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

public class QzapiImpl implements Qzapi {
    private String xh = "20158553";
    private String pwd = "55557575";
    private List<BasicNameValuePair> list;

    private String token;
    private Util util = null;

    public QzapiImpl() {
        list = new ArrayList<BasicNameValuePair>();
        util = new Util();
        try {
            token = util.getToken(xh, pwd);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public JSONObject authUser(String xh, String pwd) {
        list.clear();  //从列表中删除所有元素。
        list.add(new BasicNameValuePair("method","authUser"));
        list.add(new BasicNameValuePair("xh",xh));
        list.add(new BasicNameValuePair("pwd",pwd));
        return util.execute(list,token);
    }

    public JSONObject getCurrentTime(String currDate) {
        list.clear();  //从列表中删除所有元素。
        list.add(new BasicNameValuePair("method","authUser"));
        list.add(new BasicNameValuePair("currDate",currDate));
        return util.execute(list,token);
    }

    public JSONObject getKbcxAzc(String xh, String xnxqid, String zc) {
        list.clear();  //从列表中删除所有元素。
        list.add(new BasicNameValuePair("method","getKbcxAzc"));
        list.add(new BasicNameValuePair("xh",xh));
        list.add(new BasicNameValuePair("xnxqid",xnxqid));
        list.add(new BasicNameValuePair("zc",zc));
        return util.execute(list,token);
    }

    public JSONObject getCjcx(String xh, String xnxqid) {
        list.clear();  //从列表中删除所有元素。
        list.add(new BasicNameValuePair("method","getCjcx"));
        list.add(new BasicNameValuePair("xh",xh));
        list.add(new BasicNameValuePair("xnxqid",xnxqid));
        return util.execute(list,token);
    }

    public JSONObject getKscx(String xh) {
        list.clear();  //从列表中删除所有元素。
        list.add(new BasicNameValuePair("method","getKscx"));
        list.add(new BasicNameValuePair("xh",xh));
        return util.execute(list,token);
    }

    public JSONObject getJxlcx(String xqid) {
        list.clear();  //从列表中删除所有元素。
        list.add(new BasicNameValuePair("method","getJxlcx"));
        list.add(new BasicNameValuePair("xqid",xqid));
        return util.execute(list,token);
    }

    public JSONObject getKxJscx(String time, String idleTime, String xqid, String jxlid, String classroomNumber) {
        list.clear();  //从列表中删除所有元素。
        list.add(new BasicNameValuePair("method","getKxJscx"));
        list.add(new BasicNameValuePair("time",time));
        list.add(new BasicNameValuePair("idleTime",idleTime));
        list.add(new BasicNameValuePair("xqid",xqid));
        list.add(new BasicNameValuePair("jxlid",jxlid));
        list.add(new BasicNameValuePair("classroomNumber",classroomNumber));
        return util.execute(list,token);
    }

    public JSONObject getStudentIdInfo(String xh) {
        list.clear();  //从列表中删除所有元素。
        list.add(new BasicNameValuePair("method","getStudentIdInfo"));
        list.add(new BasicNameValuePair("xh",xh));
        return util.execute(list,token);
    }

    public JSONObject getUserInfo(String xh) {
        list.clear();  //从列表中删除所有元素。
        list.add(new BasicNameValuePair("method","getUserInfo"));
        list.add(new BasicNameValuePair("xh",xh));
        return util.execute(list,token);
    }

    public JSONObject getXnxq(String xh) {
        list.clear();  //从列表中删除所有元素。
        list.add(new BasicNameValuePair("method","getXnxq"));
        list.add(new BasicNameValuePair("xh",xh));
        return util.execute(list,token);
    }

    public JSONObject getXqcx() {
        list.clear();  //从列表中删除所有元素。
        list.add(new BasicNameValuePair("method","getXqcx"));
        return  util.execute(list,token);
    }
}

 

调用的工具类

 

package utils;
import net.sf.json.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;

public class Util {

    public String getToken(String xh, String pwd) throws URISyntaxException, IOException {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        URIBuilder uriBuilder = new URIBuilder("http://zswxyjw.minghuaetc.com/znlykjdxswxy/app.do");
        uriBuilder.setParameter("method", "authUser").setParameter("xh", xh).setParameter("pwd", pwd);
        HttpGet httpGet = new HttpGet(uriBuilder.build());
        CloseableHttpResponse response = httpClient.execute(httpGet);
        String s = null;
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            s = EntityUtils.toString(entity, "utf-8");
        }
        JSONObject obj = new JSONObject();
        obj = obj.fromObject(s);
        Object token = obj.get("token");
        return token.toString();
    }

    public JSONObject execute(List<BasicNameValuePair> list,String token)    {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        URIBuilder uriBuilder = null;
        try {
            uriBuilder = new URIBuilder("http:*****app.do");
        } catch (URISyntaxException e) {
            e.printStackTrace();
            System.out.println("URL错误!");
        }
        //添加参数
        for (BasicNameValuePair i:list) {
            uriBuilder.setParameter(i.getName(),i.getValue());
        }

        HttpGet httpGet = null;
        try {
            //创建get请求
            httpGet = new HttpGet(uriBuilder.build());
        } catch (URISyntaxException e) {
            e.printStackTrace();
            System.out.println("util中httpget错误");
        }
        httpGet.setHeader("token",token);
        CloseableHttpResponse response = null;
        try {
            response = httpClient.execute(httpGet);
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("util中execute错误");
        }

        HttpEntity entity = response.getEntity();
        String s = null;
        try {
            s = EntityUtils.toString(entity, "utf-8");
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("字符串转换失败!");
        }

        JSONObject obj = new JSONObject();

        try {
            return obj.fromObject(s);
        }catch (Exception e) {
            s = "{\"result\":"+s+"}";
            return obj.fromObject(s);
        }
    }

}

 

测试类

 

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package cn.com.edu.view.frame; import java.awt.AWTException; import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Dimension; import java.awt.GridBagLayout; import java.awt.MenuItem; import java.awt.PopupMenu; import java.awt.SystemTray; import java.awt.Toolkit; import java.awt.TrayIcon; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JSplitPane; import javax.swing.JToolBar; import org.jvnet.substance.SubstanceLookAndFeel; import org.jvnet.substance.skin.FindingNemoSkin; import cn.com.edu.action.JMenuItemAction; import cn.com.edu.action.MainFrameAction; import cn.com.edu.util.GBC; import cn.com.edu.view.panel.AddStudentInfoPanel; import cn.com.edu.view.panel.FindStudentInfoPanel; /** * 教务管理系统主界面 * * @author Administrator * */ public class MainFrame extends JFrame { private static MainFrame instance; private JMenuBar bar;// 菜单条 private JMenu studentJMenu;// 菜单 private JMenu teacherJMenu;// 菜单 private JPanel center = new JPanel();// 中心面板用来放置卡片 private CardLayout card = new CardLayout();// 卡片布局 private JPanel west;// 西边面板 private JSplitPane split;// 分割面板 private JToolBar tool;// 工具条 private MainFrameAction action = new MainFrameAction(this);// 按钮事件对象 private JMenuItemAction menuItemAction = new JMenuItemAction(this);// 菜单事件对象 private SystemTray tray;// 系统托盘 private TrayIcon trayIcon;// 设置系统托盘的图片 /** * 使用单子设计模式主界面对象 * */ private MainFrame() { init(); } public static MainFrame getInstance() { if (instance == null) { instance = new MainFrame(); } return instance; } /** * 初始化主界面 * */ public void init() { // 设置标题 this.setTitle("教务管理系统"); // 设置标题图片 ImageIcon icon = new ImageIcon("img/switchuser.png"); this.setIconImage(icon.getImage()); // 得到屏幕对象 Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); // 设置主界面大小 this.setSize(size.width, size.height - 20); // 设置居中 this.setLocationRelativeTo(null); // 添加工具条 this.add(createTool(), BorderLayout.NORTH); // 将菜单添加到主界面 this.setJMenuBar(createJMenuBar()); // 将卡片添加到主界面 center.setLayout(card); addCardPanel(center); this.add(createSplit()); // 设置关闭主界面 this.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE); //创建系统托盘 createSystemTray(); //关闭窗口事件 closeWindow(this); // 设置显示主界面 this.setVisible(true); } public JMenuBar createJMenuBar() { if (bar == null) { bar = new JMenuBar(); studentJMenu = createJMenu("学生管理"); teacherJMenu = createJMenu("老师管理"); addJMenuItem(studentJMenu, "添加学生信息"); addJMenuItem(studentJMenu, "查询学生信息"); addJMenuItem(studentJMenu, "修改学生信息"); addJMenuItem(studentJMenu, "删除学生信息"); studentJMenu.addSeparator(); addJMenuItem(studentJMenu, "退出"); bar.add(studentJMenu); bar.add(teacherJMenu); } return bar; } /** * 创建菜单 * * @param name * @return */ private JMenu createJMenu(String name) { JMenu menu = new JMenu(name); return menu; } /** * 将创建的菜单项添加到菜单 * * @param menu * @param name */ private void addJMenuItem(JMenu menu, String name) { JMenuItem item = new JMenuItem(name); item.addActionListener(menuItemAction); menu.add(item); } /** * 用于添加卡片 * * @param center */ public void addCardPanel(JPanel center) { JPanel jp2 = new JPanel(); JPanel jp3 = new JPanel(); JPanel jp4 = new JPanel(); jp2.add(new JButton("卡片2")); jp3.add(new JButton("卡片3")); jp4.add(new JButton("卡片4")); center.add(new AddStudentInfoPanel(), "添加学生信息"); center.add(new FindStudentInfoPanel(), "查询学生信息"); center.add(jp3, "修改学生信息"); center.add(jp4, "删除学生信息"); } /** * 创建西边面板,用添加选项按钮 * * @return */ public JPanel createWestPanel() { if (west == null) { west = new JPanel(); west.setLayout(new GridBagLayout()); west.add(createButton("添加学生信息", "img/switchuser.png"), new GBC(0, 0).setInset(10)); west.add(createButton("查询学生信息", "img/switchuser.png"), new GBC(0, 1).setInset(10)); west.add(createButton("修改学生信息", "img/switchuser.png"), new GBC(0, 2).setInset(10)); west.add(createButton("删除学生信息", "img/switchuser.png"), new GBC(0, 3).setInset(10)); } return west; } /** * 创建按钮方法 * * @param name * @return */ public JButton createButton(String name, String icon) { JButton button = new JButton(name); button.setIcon(new ImageIcon(icon)); button.addActionListener(action); return button; } public CardLayout getCard() { return card; } public JPanel getCenter() { return center; } /** * 分割面板 * * @return */ public JSplitPane createSplit() { if (split == null) { split = new JSplitPane(); split.setOneTouchExpandable(true); split.setLeftComponent(createWestPanel()); split.setRightComponent(center); } return split; } /** * 创建工具条 * * @return */ public JToolBar createTool() { if (tool == null) { tool = new JToolBar(); tool.add("添加学生信息", createButton("添加学生信息", "img/switchuser.png")); tool.add("查询学生信息", createButton("查询学生信息", "img/switchuser.png")); tool.add("修改学生信息", createButton("修改学生信息", "img/switchuser.png")); tool.add("删除学生信息", createButton("删除学生信息", "img/switchuser.png")); tool.add("帮助", createButton("帮助", "img/syssetup.png")); } return tool; } ///////////////////////////系统托盘设置///////////////////////////////////// /** * 窗口事件 * * @param jframe */ public void closeWindow(MainFrame jframe) { jframe.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { int show = JOptionPane.showConfirmDialog(null, "是否确定关闭?", "确认关闭系统", JOptionPane.YES_NO_OPTION); if (show == JOptionPane.YES_OPTION) { System.exit(0); } } public void windowIconified(WindowEvent e) { if (getState() == 1) {// 最小化 try { tray.add(trayIcon); } catch (AWTException e1) { e1.printStackTrace(); } setVisible(false); } } }); } /** * 创建系统托盘 * */ public void createSystemTray() { // 得到当前系统的托盘对象 tray = SystemTray.getSystemTray(); ImageIcon icon = new ImageIcon("img/2.png"); // 添加鼠标右键 弹出菜单 PopupMenu menu = new PopupMenu(); MenuItem show = new MenuItem("显示窗体"); MenuItem exit = new MenuItem("退出窗体"); trayIcon = new TrayIcon(icon.getImage(), "学生管理系统", menu); trayIcon.addMouseListener(new MouseAdapter() { /** * 鼠标点击事件 */ public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) {// 鼠标双击 tray.remove(trayIcon); setVisible(true); // 设置窗口全屏 setExtendedState(JFrame.MAXIMIZED_BOTH); } } }); /** *鼠标右键显示窗体 */ show.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tray.remove(trayIcon); setVisible(true); // 设置窗口全屏 setExtendedState(JFrame.MAXIMIZED_BOTH); } }); /** * 鼠标右键关闭窗体 */ exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int show = JOptionPane.showConfirmDialog(null, "是否确定关闭?", "确认关闭系统", JOptionPane.YES_NO_OPTION); if (show == JOptionPane.YES_OPTION) { System.exit(0); } } }); menu.add(show); menu.add(exit); } /** * @param args */ public static void main(String[] args) { SubstanceLookAndFeel.setSkin(new FindingNemoSkin()); // 蓝色幽灵 // SubstanceLookAndFeel.setSkin(new OfficeBlue2007Skin()); // 麦田风光 // SubstanceLookAndFeel.setSkin(new FieldOfWheatSkin()); // 默认皮肤 // SubstanceLookAndFeel.setSkin(new BusinessSkin()); // 朦胧风格 // SubstanceLookAndFeel.setSkin(new MistAquaSkin()); MainFrame.getInstance(); } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值