Building a micro front-end framework from scratch: actual "automobile information platform" project

mb610a482299d2d 2021-08-07 00:35:52 阅读数:244

本文一共[544]字,预计阅读时长:1分钟~
building micro front-end end framework

Build a micro front-end framework from scratch : actual combat “ Automotive Information Platform ” project

Chaoqing original painting Complete and unclassified Share online Download address :  Network disk link
Why learn micro front-end Architecture ? When your project becomes more and more complex , The project is getting bigger and bigger , Code conflicts are becoming more and more frequent , As packing slows down , It's time to study the micro front-end Architecture . This course will take you to build a micro front-end framework from scratch , And actually fight an automobile information platform , Let your system master the micro front-end architecture design and landing ability , Easily deconstruct giant applications .

Suits the crowd
2~5 Front end developers
Junior and intermediate architecture designers
Technology reserve
Have 2 Necessary foundation and framework technology for front-end engineers in , Such as :Nodejs Basics 、Vue/React/ Angular Basics .
Environmental parameters
front end vue2/3、react15/16
Back end koa
Publishing platform express

for (int i = 0; i < 7; i++) {
System.out.println(eleGrade.get(i).text());
}
for (int i = 11; i < eleGrade.size(); i = i + 10) {
if (i + 15 < eleGrade.size()) {
System.out.print(eleGrade.get(i).text() + " “);
i = i + 5;
System.out.print(eleGrade.get(i).text());
System.out.println();
}
client.close();
}
}
/**
* How to query personal Timetable
*
* @param xnd
* @param xqd
* @throws ClientProtocolException
* @throws IOException
/
public void queryStuCourse(String xnd, String xqd)
throws ClientProtocolException, IOException {
CloseableHttpClient client = HttpClients.createDefault();
String newQueryStuCourseUrl = queryStuCourseUrl + stuNumber + “&xm=”
+ stuName + queryStuCourseGnmkd;
String viewState = IOUtils.getViewState(newQueryStuCourseUrl, Cookie,
mainUrl + stuNumber);
HttpPost queryStuCoursePost = new HttpPost(newQueryStuCourseUrl);
List stuCoursePair = new ArrayList();
stuCoursePair.add(new BasicNameValuePair(“__EVENTTARGET”, “xqd”));
stuCoursePair.add(new BasicNameValuePair(“__EVENTARGUMENT”, “”));
stuCoursePair.add(new BasicNameValuePair(“__VIEWSTATE”, viewState));
stuCoursePair.add(new BasicNameValuePair(“xnd”, xnd));
stuCoursePair.add(new BasicNameValuePair(“xqd”, xqd));
UrlEncodedFormEntity entitySource = new UrlEncodedFormEntity(
stuCoursePair);
queryStuCoursePost.setEntity(entitySource);
queryStuCoursePost.setHeader(“Cookie”, Cookie);
queryStuCoursePost.setHeader(“Referer”, mainUrl + stuNumber);
HttpResponse responseStuCourse = client.execute(queryStuCoursePost);
String html = IOUtils.getHtml(responseStuCourse.getEntity()
.getContent(), “GB2312”);
Document docCourse = Jsoup.parse(html);
Elements eleCourse = docCourse.select(“td”);
for (int i = 2; i < eleCourse.size(); i++) {
System.out.print(eleCourse.get(i).text() + " ");
if (i % 9 == 0) {
System.out.println();
}
}
}
public static void main(String[] args) {
Jwgl jw = new Jwgl();
try {
jw.login(“ This is the student number ”, “ Here's the code ”);
System.out.println(“ Query result test -------”);
jw.queryStuGrade(“2015-2016”, “1”);
// Query the west campus , Monday , The first 12 Empty classroom test .
// jw.queryCla
oom(“1”, “1”, “2”);
System.out.println(“ Query empty classroom test ------”);
jw.queryCla
oom();
System.out.println(“ Query personal timetable test -------”);
jw.queryStuCourse(“2014-2015”, “1”);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
//QQ:451209214
}
}
package com.ican.yueban.jwgl;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import com.ican.yueban.utils.DateUtils;
import com.ican.yueban.utils.GlobalConstant;
import com.ican.yueban.utils.IOUtils;
import com.ican.yueban.utils.ParseUtils;
public class Jwgl {
private static String stuNumber = “”;
private static String stuName = “”;
private static String Cookie = “”;
private String indexUrl = GlobalConstant.INDEX_URL;
private String secretCodeUrl = GlobalConstant.SECRETCODE_URL;
private String loginUrl = GlobalConstant.LOGIN_URL;
private String mainUrl = GlobalConstant.MAIN_URL;
private String queryCla
oomUrl = GlobalConstant.QUERY_CLAOOM_URL;
private String queryCla
oomGnmkdm = GlobalConstant.QUERY_CLAOOM_GNMKDM;
private String queryStuGradeUrl = GlobalConstant.QUERY_STU_GRADE_URL;
private String queryStuGradeGnmkd = GlobalConstant.QUERY_STU_GRADE_GNMKDM;
private String queryStuCourseUrl = GlobalConstant.QUERY_STU_COURSE_URL;
private String queryStuCourseGnmkd = GlobalConstant.QUERY_STU_COURSE_GNMKDM;
private String xixiaoqu = GlobalConstant.XIXIAOQU;
private String identityStu = GlobalConstant.IDENTITY_STU;
/
*
* Login function
*
* @param stuNumber
* @param password
* @return
* @throws Exception
* @throws UnsupportedOperationException
/
public boolean login(String stuNumber, String password)
throws UnsupportedOperationException, Exception {
this.stuNumber = stuNumber;
// Get the research code
HttpGet secretCodeGet = new HttpGet(secretCodeUrl);
CloseableHttpClient client = HttpClients.createDefault();
CloseableHttpResponse responseSecret = client.execute(secretCodeGet);
// Get the returned Cookie
Cookie = responseSecret.getFirstHeader(“Set-Cookie”).getValue();
String viewState = IOUtils.getViewState(indexUrl, “”, “”);
// Download the research code to C disc
IOUtils.getSecret(responseSecret.getEntity().getContent(),
“secretCode.png”, “c://”);
Scanner sc = new Scanner(System.in);
System.out.println(“ Please enter the research code :”);
// Manually fill in the value of the just obtained research code
String secret = sc.next().trim();
HttpPost loginPost = new HttpPost(loginUrl);// Create a login Post entreat
loginPost.setHeader(“Cookie”, Cookie);// Take your first plea Cookie
List nameValuePairLogin = new ArrayList();// encapsulation Post Submit parameters
nameValuePairLogin
.add(new BasicNameValuePair(“__VIEWSTATE”, viewState));// Hide form values
nameValuePairLogin
.add(new BasicNameValuePair(“txtUserName”, stuNumber));// Student number
nameValuePairLogin.add(new BasicNameValuePair(“TextBox2”, password));// password
nameValuePairLogin.add(new BasicNameValuePair(“txtSecretCode”, secret));// Research code
nameValuePairLogin.add(new BasicNameValuePair(“RadioButtonList1”,
identityStu));// identity , Acquiesce in students
nameValuePairLogin.add(new BasicNameValuePair(“Button1”, “”));
nameValuePairLogin.add(new BasicNameValuePair(“lbLanguage”, “”));
nameValuePairLogin.add(new BasicNameValuePair(“hidPdrs”, “”));
nameValuePairLogin.add(new BasicNameValuePair(“hidsc”, “”));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(
nameValuePairLogin, “GB2312”);
loginPost.setEntity(entity);
HttpResponse responseLogin = client.execute(loginPost);
// client1.close();
// The third step : Judge whether the submitted data can win , Return victoriously 302
if (responseLogin.getStatusLine().getStatusCode() == 302) {
// If you win , With Cookie Requesting redirection main page , And get the student's name
HttpGet mainGet = new HttpGet(mainUrl + stuNumber);
mainGet.setHeader(“Cookie”, Cookie);
mainGet.setHeader(“Referer”, loginUrl);
HttpResponse responseMain = client.execute(mainGet);
InputStream is = responseMain.getEntity().getContent();
String html = “”;
try {
html = IOUtils.getHtml(is, “GB2312”);
} catch (Exception e) {
System.out.println(“ analysis html Failure !”);
e.printStackTrace();
}
stuName = Jsoup.parse(html).getElementById(“xhxm”).text();
System.out.println(“ Login to victory ! Welcome to you :” + stuName);
client.close();
return true;
} else {
System.out.println(“ Login failed !”);
client.close();
return false;
}
}
/
*
* Query empty classroom
*
* @throws Exception
*
* @throws Exception
/
public void queryCla
oom(String xiaoqu, String xqj, String sjd)
throws Exception {
CloseableHttpClient client = HttpClients.createDefault();
String newQueryCla
ommUrl = queryClaoomUrl + stuNumber + “&xm=”
+ stuName + queryCla
oomGnmkdm;// I beg Url
String parseSjd = ParseUtils.parseWeek(sjd);// Parse the string corresponding to the current section
String nowWeek = DateUtils.getWeek() + “”;// Get what week the current time is
String viewState = IOUtils.getViewState(newQueryCla
ommUrl, Cookie,
mainUrl + stuNumber);
// Encapsulate and query empty parameters
List queryCla
oomPair = new ArrayList();
queryCla
oomPair.add(new BasicNameValuePair(“__EVENTTARGET”, “”));
queryCla
oomPair.add(new BasicNameValuePair(“__EVENTARGUMENT”, “”));
queryCla
oomPair
.add(new BasicNameValuePair(“__VIEWSTATE”, viewState));
queryCla
oomPair.add(new BasicNameValuePair(“xiaoq”, xiaoqu));// Campus type , Acquiescence in the West Campus
queryCla
oomPair.add(new BasicNameValuePair(“jslb”, “”));// Classroom category , Acquiescence is empty
queryCla
oomPair.add(new BasicNameValuePair(“min_zws”, “0”));// Minimum number of seats , Acquiescence as 0
queryCla
oomPair.add(new BasicNameValuePair(“max_zws”, “”));// Maximum number of seats , Acquiescence is empty
queryCla
oomPair.add(new BasicNameValuePair(“ddlKsz”, nowWeek));// Start week , Acquiesce in the current week
queryCla
oomPair.add(new BasicNameValuePair(“ddlJsz”, nowWeek));// Over a week , Acquiesce in the current week
queryCla
oomPair.add(new BasicNameValuePair(“xqj”, xqj));// What day , Acquiesce in the day
queryCla
oomPair.add(new BasicNameValuePair(“ddlDsz”, “”));// One or two weeks , acquiescence
queryCla
oomPair.add(new BasicNameValuePair(“sjd”, parseSjd));// Section two
queryCla
oomPair.add(new BasicNameValuePair(“Button2”, “ Empty classroom query ”));
queryCla
oomPair.add(new BasicNameValuePair(“xn”, “2015-2016”));
queryCla
oomPair.add(new BasicNameValuePair(“xq”, “2”));
queryCla
oomPair.add(new BasicNameValuePair(“ddlSyXn”, “2015-2016”));
queryCla
oomPair.add(new BasicNameValuePair(“ddlSyxq”, “2”));
UrlEncodedFormEntity entityCla
oom = new UrlEncodedFormEntity(
queryCla
oomPair);
HttpPost queryCla
oomPost = new HttpPost(newQueryClaommUrl);
// newQueryCla
ommUrl Example : http://jwgl2.ujn.edu.cn/xxjsjy.aspx?xh=20121214104&xm=XXX&gnmkdm=N121611
queryCla
oomPost.setEntity(entityClaoom);
queryCla
oomPost.setHeader(“Referer”, mainUrl + stuNumber);// Set header information
queryCla
oomPost.setHeader(“Cookie”, Cookie);
HttpResponse responseCla
oom = client.execute(queryClaoomPost);
InputStream is = responseCla
oom.getEntity().getContent();
String html = IOUtils.getHtml(is, “GB2312”);
Document doc = Jsoup.parse(html);
Elements eleCla
oom = doc.select(“td”);
Elements eleInfo = doc.select(“#lblbt”);
System.out.println(eleInfo.get(0).text());
for (int i = 0; i < eleCla
oom.size(); i++) {
// Print only the classroom title
if (i % 8 == 1) {
System.out.println(eleCla
oom.get(i).text());
}
}
client.close();
}
/
*
* Overload query empty classroom method , Acquiescence in time , Nonparametric query method for course sections
*
* @throws IOException
* @throws ClientProtocolException
/
public void queryCla
oom() throws ClientProtocolException, IOException,
Exception {
String weekDay = DateUtils.getWeekDay() + “”;// Gets the day of the week the current time is
String sdj = DateUtils.getNowCourse() + “”;// Get which class the current time is
new Jwgl().queryCla
oom(xixiaoqu, weekDay, sdj);
}
/
*
* How to query personal results
*
* @throws ClientProtocolException
* @throws IOException
*/
public void queryStuGrade(String xn, String xq)
throws ClientProtocolException, IOException {
CloseableHttpClient client = HttpClients.createDefault();
String newQueryStuGradeUrl = queryStuGradeUrl + stuNumber + “&xm=”
+ stuName + queryStuGradeGnmkd;
HttpPost queryGradePost = new HttpPost(newQueryStuGradeUrl);
String viewState = IOUtils.getViewState(newQueryStuGradeUrl, Cookie,
mainUrl + stuNumber);
// Encapsulate request parameters
List queryGradePair = new ArrayList();
queryGradePair.add(new BasicNameValuePair(”__EVENTTARGET", “”));
queryGradePair.add(new BasicNameValuePair(“__EVENTARGUMENT”, “”));
queryGradePair.add(new BasicNameValuePair(“__VIEWSTATE”, viewState));
queryGradePair.add(new BasicNameValuePair(“hidLanguage”, “”));
queryGradePair.add(new BasicNameValuePair(“ddlXN”, xn));// school year
queryGradePair.add(new BasicNameValuePair(“ddlXQ”, xq));// semester
queryGradePair.add(new BasicNameValuePair(“ddl_kcxz”, “”));
queryGradePair.add(new BasicNameValuePair(“btn_xq”, “ Term results ”));
queryGradePost.setHeader(“Cookie”, Cookie);
queryGradePost.setHeader(“Referer”, mainUrl + stuNumber);
UrlEncodedFormEntity entityGrade = new UrlEncodedFormEntity(
queryGradePair);
queryGradePost.setEntity(entityGrade);
HttpResponse responQueryGradePost = client.execute(queryGradePost);
String gradeHtml = IOUtils.getHtml(responQueryGradePost.getEntity()
.getContent(), “GB2312”);
// System.out.println(gradeHtml);
Document gradeDoc = Jsoup.parse(gradeHtml);
Elements eleGrade = gradeDoc.select(“td”);
// Analyze according to requirements html
Label content and output

package com.ican.yueban.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class DateUtils {
private static String startDay = GlobalConstant.START_DAY;// Opening date
private static String endDay = GlobalConstant.END_DAY;// Holiday date
/**
* Get which class the current time is , be limited to 8-16 Between points , Other times acquiesce 1,2 lesson .
*
* @return
/
public static int getNowCourse() {
SimpleDateFormat df = new SimpleDateFormat(“HH:mm:ss”);// Set the date format
String nowDate = df.format(new Date());
if (nowDate.startsWith(“08”) || nowDate.startsWith(“09”)) {
return 1;// 12 lesson .
} else if (nowDate.startsWith(“10”) || nowDate.startsWith(“11”)) {
return 2;// 34 lesson , And so on .
} else if (nowDate.startsWith(“12”) || nowDate.startsWith(“13”)
|| nowDate.startsWith(“14”)) {
return 3;
} else if (nowDate.startsWith(“15”) || nowDate.startsWith(“16”)) {
return 4;
} else {
return 1;
}
}
/
*
* Get what week the current time is
*
* @return
/
public static int getWeek() {
int days = 0;
int nowWeek = 0;
try {
SimpleDateFormat df = new SimpleDateFormat(“yyyy-MM-dd”);// Set the date format
String nowDate = df.format(new Date());
int nowDaysBetween = daysBetween(startDay, nowDate) + 1;
days = daysBetween(startDay, endDay);
int x = nowDaysBetween % 7;
if (x == 0) {
nowWeek = nowDaysBetween / 7;
} else {
nowWeek = nowDaysBetween / 7 + 1;
}
} catch (ParseException e) {
System.out.println(“ The date entered is illegal , Failed to parse date ”);
e.printStackTrace();
}
return nowWeek;
}
/
*
* Gets the day of the week the current time is
*
* @return
/
public static int getWeekDay() {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
if (cal.get(Calendar.DAY_OF_WEEK) - 1 == 0) {
return 7;
}
return cal.get(Calendar.DAY_OF_WEEK) - 1;
}
/
*
* Calculate two String Number of days between type dates
*
* @param startDay
* @param endDay
* @return
* @throws ParseException
/
public static int daysBetween(String startDay, String endDay)
throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”);
Calendar cal = Calendar.getInstance();
cal.setTime(sdf.parse(startDay));
long time1 = cal.getTimeInMillis();
cal.setTime(sdf.parse(endDay));
long time2 = cal.getTimeInMillis();
long between_days = (time2 - time1) / (1000 * 3600 * 24);
return Integer.parseInt(String.valueOf(between_days));
}
/
*
* With yyyy-MM-dd HH:mm:ss Format return String Type system time
*
* @return
*/
public static String getNowDate() {
SimpleDateFormat df = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);// Set the date format
return df.format(new Date());
}
}

package com.ican.yueban.utils;
/**

  • All constants in this system are defined
  • @author Song Kaizong

/
public interface GlobalConstant {
public static final String START_DAY = “2016-02-29”;
public static final String END_DAY = “2016-07-10”;
public static final String INDEX_URL = “ http://jwgl2.ujn.edu.cn”;// Home page of educational administration system of Jinan University
public static final String SECRETCODE_URL = “ http://jwgl2.ujn.edu.cn/CheckCode.aspx”;// Research code page
public static final String LOGIN_URL = “ http://jwgl2.ujn.edu.cn/default2.aspx”;// Jinan university educational administration system login page
public static final String MAIN_URL = “ http://jwgl2.ujn.edu.cn/xs_main.aspx?xh=”;// The homepage of the educational administration system of Jinan University , Menu page
public static final String QUERY_CLA
OOM_URL = “ http://jwgl2.ujn.edu.cn/xxjsjy.aspx?xh=”;// Jida query empty classroom link
public static final String QUERY_CLA
*OOM_GNMKDM = “&gnmkdm=N121611”;// Jida inquires about the empty classroom gnmkdm
public static final String QUERY_STU_COURSE_URL = “ http://jwgl2.ujn.edu.cn/xskbcx.aspx?xh=”;// Link to Jida's personal timetable query
public static final String QUERY_STU_COURSE_GNMKDM = “&gnmkdm=N121603”;// Jida inquires about personal Timetable gnmkdm
public static final String QUERY_STU_GRADE_URL = “ http://jwgl2.ujn.edu.cn/xscjcx.aspx?xh=”;// Jida query personal achievement link
public static final String QUERY_STU_GRADE_GNMKDM = “&gnmkdm=N121605”;// Jida inquires about personal achievements gnmkdm
public static final String IDENTITY_STU = “ Student ”;// identity : Student
public static final String XIXIAOQU = “1”;// Logo of Jida West Campus
public static final String DONGXIAOQU = “2”;// Logo of jidadong Campus
public static final String ZHANGQIUXIAOQU = “3”;// Logo of Zhangqiu campus of Jinan University
public static final String CLASS1 = “‘1’|‘1’,‘0’,‘0’,‘0’,‘0’,‘0’,‘0’,‘0’,‘0’”;// 1,2 section
public static final String CLASS2 = “‘2’|‘0’,‘3’,‘0’,‘0’,‘0’,‘0’,‘0’,‘0’,‘0’”;// 3,4 section
public static final String CLASS3 = “‘3’|‘0’,‘0’,‘5’,‘0’,‘0’,‘0’,‘0’,‘0’,‘0’”;// 5,6 section
public static final String CLASS4 = “‘4’|‘0’,‘0’,‘0’,‘7’,‘0’,‘0’,‘0’,‘0’,‘0’”;// 7,8 section
public static final String CLASS5 = “‘5’|‘0’,‘0’,‘0’,‘0’,‘9’,‘0’,‘0’,‘0’,‘0’”;// 8,10 section
public static final String CLASS6 = “‘6’|‘0’,‘0’,‘0’,‘0’,‘0’,‘11’,‘0’,‘0’,‘0’”;// 11,12 section
public static final String CLASS7 = “‘7’|‘1’,‘3’,‘0’,‘0’,‘0’,‘0’,‘0’,‘0’,‘0’”;// In the morning
public static final String CLASS8 = “‘8’|‘0’,‘0’,‘5’,‘7’,‘0’,‘0’,‘0’,‘0’,‘0’”;// Afternoon
public static final String CLASS9 = “‘9’|‘1’,‘3’,‘5’,‘7’,‘0’,‘0’,‘0’,‘0’,‘0’”;// In the daytime
public static final String CLASS10 = “‘10’|‘0’,‘0’,‘0’,‘0’,‘9’,‘11’,‘0’,‘0’,‘0’”;// evening
public static final String CLASS11 = “‘11’|‘1’,‘3’,‘5’,‘7’,‘9’,‘11’,‘0’,‘0’,‘0’”;// all day
public static final String BTN_XUEQI = “btn_xq”;// Term results
public static final String BTN_XUENIAN = “btn_xn”;// Academic year results
public static final String BTN_LINIAN = “btn_zcj”;// Achievements over the years
public static final String UNIVERSITY_CODE_UJN = “00001”;// Jinan University identification code
public static final String USER_STATE_N = “1”;// Uncertified
public static final String USER_STATE_Y = “2”;// Certified
public static final String COMMENT_TYPE_NEWTHINGS = “1”;// Comment type 1: Something new
public static final String COMMENT_TYPE_INTEREST = “2”;// Comment type 2: Fun activities
}

package com.ican.yueban.utils;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.jsoup.Jsoup;
public class IOUtils {
/**
* Specify the encoding format , Convert the input stream to a string
*
* @param is
* @return
* @throws IOException
/
public static String getHtml(InputStream is, String encoding)
throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = is.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
is.close();
return new String(bos.toByteArray(), encoding);
}
/
*
* Download the pictures
*
* @param urlString
* @param filename
* @param savePath
* @throws Exception
/
public static void download(String urlString, String filename,
String savePath) throws Exception {
// structure URL
URL url = new URL(urlString);
// Open the connection
URLConnection con = url.openConnection();
// Set the request timeout to 5s
con.setConnectTimeout(5 * 1000);
// Input stream
InputStream is = con.getInputStream();
// 1K Data buffer for
byte[] bs = new byte[1024];
// Length of data read
int len;
// Output file stream
File sf = new File(savePath);
if (!sf.exists()) {
sf.mkdirs();
}
OutputStream os = new FileOutputStream(sf.getPath() + “\” + filename);
// Start reading
while ((len = is.read(bs)) != -1) {
os.write(bs, 0, len);
}
// end , Close all links
os.close();
is.close();
}
/
*
* Picture clipping tool class
*
* @param src
* @param dest
* @param x
* @param y
* @param w
* @param h
* @throws IOException
/
public static void cutImage(String src, String dest, int x, int y, int w,
int h) throws IOException {
Iterator iterator = ImageIO.getImageReadersByFormatName(“jpg”);
ImageReader reader = (ImageReader) iterator.next();
InputStream in = new FileInputStream(src);
ImageInputStream iis = ImageIO.createImageInputStream(in);
reader.setInput(iis, true);
ImageReadParam param = reader.getDefaultReadParam();
Rectangle rect = new Rectangle(x, y, w, h);
param.setSourceRegion(rect);
BufferedImage bi = reader.read(0, param);
ImageIO.write(bi, “jpg”, new File(dest));
in.close();
}
/
*
* Discriminant character coding set
*
* @param str
* @return
/
public static String getEncoding(String str) {
String encode = “GB2312”;
try {
if (str.equals(new String(str.getBytes(encode), encode))) {
String s = encode;
return s;
}
} catch (Exception exception) {
}
encode = “ISO-8859-1”;
try {
if (str.equals(new String(str.getBytes(encode), encode))) {
String s1 = encode;
return s1;
}
} catch (Exception exception1) {
}
encode = “UTF-8”;
try {
if (str.equals(new String(str.getBytes(encode), encode))) {
String s2 = encode;
return s2;
}
} catch (Exception exception2) {
}
encode = “GBK”;
try {
if (str.equals(new String(str.getBytes(encode), encode))) {
String s3 = encode;
return s3;
}
} catch (Exception exception3) {
}
return “ Unknown ”;
}
/
*
* Convert the input stream into pictures —》 Get the research code
*
* @param is
* @param filename
* @param savePath
* @throws Exception
/
public static void getSecret(InputStream is, String filename,
String savePath) throws Exception {
// 1K Data buffer for
byte[] bs = new byte[1024];
// Length of data read
int len;
// Output file stream
File sf = new File(savePath);
if (!sf.exists()) {
sf.mkdirs();
}
OutputStream os = new FileOutputStream(sf.getPath() + “\” + filename);
// Start reading
while ((len = is.read(bs)) != -1) {
os.write(bs, 0, len);
}
// end , Close all links
os.close();
is.close();
}
/
*
* Get the of the hidden field __VIEWSTATE value
*
* @param url
* @param cookie
* @param referer
* @return
* @throws UnsupportedOperationException
* @throws ClientProtocolException
* @throws IOException
*/
public static String getViewState(String url, String cookie, String referer)
throws UnsupportedOperationException, ClientProtocolException,
IOException {
CloseableHttpClient client = HttpClients.createDefault();
HttpGet getViewState = new HttpGet(url);
getViewState.setHeader(“Cookie”, cookie);
getViewState.setHeader(“Referer”, referer);// Set header information
String s = IOUtils.getHtml(client.execute(getViewState).getEntity()
.getContent(), “GB2312”);
String viewstate = Jsoup.parse(s).select(“input[name=__VIEWSTATE]”)
.val();
client.close();
return viewstate;
}
}

package com.ican.yueban.utils;
public class ParseUtils {
/**
* Get the string corresponding to the course section
* @param course
* @return
*/
public static String parseWeek(String course) {
String sjd=“”;
int nowCourse = Integer.parseInt(course);
switch (nowCourse) {
case 1:
sjd=GlobalConstant.CLASS1;
break;
case 2:
sjd=GlobalConstant.CLASS2;
break;
case 3:
sjd=GlobalConstant.CLASS3;
break;
case 4:
sjd=GlobalConstant.CLASS4;
break;
case 5:
sjd=GlobalConstant.CLASS5;
break;
case 6:
sjd=GlobalConstant.CLASS6;
break;
case 7:
sjd=GlobalConstant.CLASS7;
break;
case 8:
sjd=GlobalConstant.CLASS8;
break;
case 9:
sjd=GlobalConstant.CLASS9;
break;
case 10:
sjd=GlobalConstant.CLASS10;
break;
case 11:
sjd=GlobalConstant.CLASS11;
break;
default:
sjd=GlobalConstant.CLASS1;
break;
}
return sjd;
}
}

版权声明:本文为[mb610a482299d2d]所创,转载请带上原文链接,感谢。 https://car.inotgo.com/2021/08/20210807003449226x.html