自动审核工具

本脚本依赖 jodd http工具箱,流程为登录、查询、解析、审核

 

package jodd.http;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AutoApply {

    String username = "";
    String password = "";

    String machineInfo = "2YOcO6I0x6XXGNfPd5SxS30E%2F26nW7Wd%2FJCZo5%2F0guOo7cjy0DiJVgTio2eNwb0QVroN2sKIzjhumjgQpkLBoghi6zjes2WiEt2D9YhqiZYGWyFRrQOdXUi58SjU9GSapcOUjBSZK61NGkYd0zRdte9fAZbRl3FuU0k22JyrI9APQ%2FbD1RKfKkh4mocLlZD6IAgQBv0k9syWQz%2B60AYwZaQccgFItPuL";

    String loginUrl = "http://172.18.138.35:8888/sign/login/login.do?";

    String jsessionid = "";

    public static void main(String[] args) throws IOException {

        new AutoApply().process();

    }

    public void process() throws IOException {

        login();

        List<String> list = getIds();

        while (list != null && list.size() > 0) {

            apply(list);

            list = getIds();
        }

    }

    private void login() throws IOException {

        String url = loginUrl + "username=" + username + "&password=" + password + "&machineInfo" + machineInfo;

        String body = HttpRequest.post(url).send().toString();

        BufferedReader reader = new BufferedReader(new StringReader(body));

        String line = reader.readLine();
        while (line != null) {
            if (line.contains("Set-Cookie")) {
                jsessionid = line.substring(line.indexOf("JSESSIONID="), line.indexOf("; Path")).replace("JSESSIONID=", "");
                break;
            }

            line = reader.readLine();
        }

    }

    public List<String> getIds() throws IOException {

        Map<String, String> para = new HashMap<String, String>();
        para.put("pageNo", "1");
        para.put("query_beginDate", "20121101");
        para.put("query_endDate", "20131206");
        para.put("role", "2");
        para.put("userId", "209");
        para.put("query_chekSt", "01");

        String body = HttpRequest.get("http://172.18.138.35:8888/sign/workReport/workReport!list.do").query(para).header("Cookie",
                "JSESSIONID=" + jsessionid).send().bodyText();

        BufferedReader reader = new BufferedReader(new StringReader(body));

        List<String> list = new ArrayList<String>();
        String line = reader.readLine();
        while (line != null) {
            if (line.contains("通过审核") && line.contains("/sign/workReport/workReport!checkReport.do")) {
                String id = line.substring(line.indexOf("workId="), line.indexOf("&workStatus")).replace("workId=", "");

                list.add(id);
            }

            line = reader.readLine();
        }
        return list;
    }

    public void apply(List<String> list) {

        for (String id : list) {
            Map<String, String> para = new HashMap<String, String>();
            para.put("workId", id);
            para.put("workStatus", "02");
            HttpRequest.get("http://172.18.138.35:8888/sign/workReport/workReport!checkReport.do").query(para).header("Cookie",
                    "JSESSIONID=" + jsessionid).send();

            System.out.println(id + " success");

        }

    }

}

 

 

 

posted @ 2013-12-06 19:06  benx621  阅读(467)  评论(0编辑  收藏  举报