掘金签到和抽奖,搞个服务器,然后写个定时任务挂在服务上,每天自动签到和抽奖,如果想不看抽奖轮盘你也可以写逻辑,核心功能已经写好了 cookie获取方式
static String cookie = "放入你的cookie";
static String baseUrl = "https://api.juejin.cn";
static String todayStatus = "/growth_api/v1/get_today_status";
static String checkIn = "/growth_api/v1/check_in";
static String lotteryConfig = "/growth_api/v1/lottery_config/get";
static String drawLottery = "/growth_api/v1/lottery/draw";
public static void main(String[] args) throws IOException {
//查询是否签到
getTodayCheck();
if (!getTodayCheck()){
//签到
if (getTodayCheckStatus()){
//抽奖
getTodayDrawStatus();
}
}
}
/**
* 查询今日是否已经签到
*
* @return
* @throws IOException
*/
public static Boolean getTodayCheck() throws IOException {
JSONObject jsonObject = HttpGet(todayStatus);
return jsonObject.getString("err_no").equals("0") ? true : false;
}
/**
* 签到
*
* @return
* @throws IOException
*/
public static Boolean getTodayCheckStatus() throws IOException {
JSONObject jsonObject = HttpPost(checkIn);
return jsonObject.getString("err_no").equals("0") ? true : false;
}
/**
* 获取免费抽奖次数
*
* @return
* @throws IOException
*/
public static Integer getLotteryConfig() throws IOException {
JSONObject jsonObject = HttpGet(lotteryConfig);
return jsonObject.getJSONObject("dara").getInteger("free_count");
}
/**
* 抽奖
*
* @return
* @throws IOException
*/
public static Boolean getTodayDrawStatus() throws IOException {
JSONObject jsonObject = HttpPost(drawLottery);
return jsonObject.getString("err_no").equals("0") ? true : false;
}
/**
* 掘金get请求
*
* @param urls
* @return
* @throws IOException
*/
public static JSONObject HttpGet(String urls) throws IOException {
URL url = new URL(baseUrl + urls);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
httpURLConnection.setRequestMethod("GET");
httpURLConnection.setRequestProperty("cookie", cookie);
InputStream inputStream = httpURLConnection.getInputStream();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int len = 0;
while (true) {
len = inputStream.read(b);
if (len == -1) {
break;
}
byteArrayOutputStream.write(b, 0, len);
}
String s = byteArrayOutputStream.toString();
JSONObject jsonObject = JSONObject.parseObject(s);
// System.out.println(jsonObject);
return jsonObject;
}
/**
* 掘金post请求
*
* @param urls
* @return
* @throws IOException
*/
public static JSONObject HttpPost(String urls) throws IOException {
URL url = new URL(baseUrl + urls);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("cookie", cookie);
InputStream inputStream = httpURLConnection.getInputStream();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int len = 0;
while (true) {
len = inputStream.read(b);
if (len == -1) {
break;
}
byteArrayOutputStream.write(b, 0, len);
}
String s = byteArrayOutputStream.toString();
JSONObject jsonObject = JSONObject.parseObject(s);
// System.out.println(jsonObject);
return jsonObject;
}