package org.example;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Main {
public static void main(String[] args) {
//需要设置全局cookie
Map<String, String> header = new HashMap<>();
header.put("cookie","自己的cookie");
header.put("Content-Type", "application/json");
String userUrl = "
https://*********/account/info";
JSONObject userInfo = JSONUtil.parseObj(HttpUtil.createGet(userUrl).addHeaders(header).execute().body()).getJSONObject("data");
if (ObjectUtil.isEmpty(userInfo.getStr("nickname"))) {
System.out.println("登录失败,cookie错误。");
return;
}
System.out.println("hello,"+userInfo.getStr("nickname")+"! 登录成功。" );
//查看当前签到状态,如果签到过不再执行。
String stateUrl = "
https://drive-m.*********/1/clouddrive/capacity/growth/info?pr=ucpro&fr=pc&uc_param_str=";
JSONObject sign = getDataResponse(HttpUtil.createGet(stateUrl).addHeaders(header).execute().body()).getJSONObject("cap_sign");
if (sign.getBool("sign_daily")) {
int number = sign.getInt("sign_daily_reward") / 1024/1024;
BigDecimal progress = new BigDecimal(sign.getStr("sign_progress")).divide(new BigDecimal(sign.getStr("sign_target")), BigDecimal.ROUND_CEILING);
System.out.println("今日已签到获取"+number+"MB,进度"+progress+"%");
return;
}
//执行签到
String signUrl = "
https://drive-m.*********/1/clouddrive/capacity/growth/sign?pr=ucpro&fr=pc&uc_param_str=";
Map<String, Object> params = new HashMap<>();
params.put("sign_cyclic", true);
JSONObject dataResponse = getDataResponse(HttpUtil.createPost(signUrl).addHeaders(header).body(JSONUtil.toJsonStr(params)).execute().body());
int mb = dataResponse.getInt("sign_daily_reward") / 2048;
System.out.println("签到成功,获取到"+mb+"MB!");
}
private static JSONObject getDataResponse(String response) {
JSONObject responseStatus = JSONUtil.parseObj(response);
if (ObjectUtil.notEqual(responseStatus.getInt("status"), 200)) {
String message = "夸克平台接口异常," + responseStatus.getStr("message");
System.out.println(message);
return responseStatus;
}
return responseStatus.getJSONObject("data");
}
}