首先,ArcTime 是使用 Java 编写的免费跨平台字幕软件, 是一款全新概念的可视化字幕编辑器, 独创字幕块概念, 在时间线上拖动、调整字幕块即可轻松完成字幕创建工作。每天签到可以兑换一些小功能,于是用 okHttp 写了个签到脚本,只需要填入账号跟密码再运行即可,可以设置循环定时运行,放在服务器上就能自动签到了。
package HttpTools; import okhttp3.*; import java.io.IOException; import java.util.*; import java.util.concurrent.TimeUnit; import static HttpTools.OkHttpRequestClient.CONTENTTYPE; public class OkHttpArctime { public static void main(String[] args) throws Exception { Map<String, String> users = new HashMap<>(); // arcTime 账号 users.put("15555555555", "123456"); users.put("17777777777", "123456"); arcSign(users); } /** * arcTime 签到 * * @param users 保存用户名密码的 map 集合 * @throws Exception */ private static void arcSign(Map<String, String> users) throws Exception { String cookieStr; Set<Map.Entry<String, String>> entries = users.entrySet(); for (Map.Entry<String, String> entry : entries) { Response response = postMan("http://m.arctime.cn/home/user/login_save.html", "", "form", "application/x-www-form-urlencoded; charset=UTF-8", "username=" + entry.getKey() + "&password=" + entry.getValue() + "&login_type=2"); // 获取 cookie List<String> headers = response.headers("Set-Cookie"); cookieStr = cookieHeader(headers); System.out.println("cookie:" + cookieStr); if (response.isSuccessful()) { System.out.println(response.body().string()); Response form = postMan("http://m.arctime.cn/home/ucenter/attendance.html", cookieStr, "json", "", ""); System.out.println(entry.getKey() + ":" + form.body().string()); } else { System.out.println(entry.getKey() + ":" + response.body().string()); throw new IOException(); } } } /** * 拼接 cookie * * @param cookies * @return */ private static String cookieHeader(List<String> cookies) { StringBuilder cookieHeader = new StringBuilder(); for (String cookie : cookies) { cookieHeader.append(cookie); } return cookieHeader.toString(); } /** * post 访问 * * @param url 请求地址 * @param cookieStr cookie * @param submitType 提交方式 from 表单跟 json 方式 一般 from 表单 * @param contentType 可为空字符串 * @param params 提交的参数 例如:name=zhangsan&pass=mima * @return * @throws Exception */ private static Response postMan(String url, String cookieStr, String submitType, String contentType, String params) throws Exception { String[] paramses; if (params.contains("=") && params.contains("&")) { paramses = params.split("&"); } else if (params.contains("=") && !params.contains("&")) { paramses = new String[1]; paramses[0] = params; } else { paramses = null; } Map<String, String> map = new HashMap<>(); FormBody.Builder builder = new FormBody.Builder(); RequestBody requestBody = null; FormBody formBody = null; Request requests = null; final OkHttpClient CLIENT = new OkHttpClient.Builder() .connectTimeout(60, TimeUnit.SECONDS) .readTimeout(60, TimeUnit.SECONDS) .build(); if ("json".equals(submitType)) { requestBody = RequestBody.create(CONTENTTYPE, params); requests = new Request.Builder().url(url) .post(requestBody) .header("Content-Type", contentType) .header("Cookie", cookieStr) .build(); } else if ("form".equals(submitType)) { if (paramses != null) { for (String s : paramses) { String[] ss = s.split("="); map.put(ss[0], ss[1]); } Set<Map.Entry<String, String>> entries = map.entrySet(); for (Map.Entry<String, String> entry : entries) { builder.add(entry.getKey(), entry.getValue()); } } formBody = builder.build(); requests = new Request.Builder().url(url) .post(formBody) .header("Content-Type", contentType) .header("Cookie", cookieStr) .build(); } Response responses = CLIENT.newCall(requests).execute(); return responses; } /** * get 请求方式 * * @param url * @param cookieStr * @param contentType * @return * @throws IOException */ private static Response getMan(String url, String cookieStr, String contentType) throws IOException { final OkHttpClient CLIENT = new OkHttpClient.Builder() .connectTimeout(60, TimeUnit.SECONDS) .readTimeout(60, TimeUnit.SECONDS) .build(); Request requests = new Request.Builder().url(url) .get() .header("Content-Type", contentType) .header("Cookie", cookieStr) .build(); Response responses = CLIENT.newCall(requests).execute(); return responses; } }