掘金是稀土上面的一个板块,次要是技术博客网站,每日的主动签到能够拿到矿石,矿石能干嘛呢,当然是换实在的物品啊,如下,小卷感觉switch必定是遥遥无期了,只想攒点矿石换个睡枕,让小卷在卷他人的时候还能美美地睡个午觉。
然而小卷常常忙的不可开交,以至于想起来到掘金签到的时候,曾经过了十多天了,于是筹备写个脚本自行签到。看上图的成果,小卷曾经间断签到了16天
Cookie的获取
通过上一篇京东主动签到脚本的阐明[[奶奶看了都会]教你用脚本薅京东签到羊毛](https://blog.csdn.net/qq_3662...),签到接口调用都须要用cookie,掘金网页版上获取Cookie非常简单,登录后,轻易试几个点击,间接copy对应的Cookie就行
脚本编写
编写之前须要获取签到接口,和抽奖接口,这里就间接给大家了,不必再本人找了,而后写一个HTTP申请,并设置定时工作,每天定时执行一遍工作就OK了,具体细节看上面的代码
HTTP工具类POST办法
@Slf4jpublic class OkHttpUtils { //post申请的工具类办法 public static String post(String url, String cookie, RequestBody requestBody, Map<String, String> header) throws Exception { String userAgent = "okhttp/3.12.1;jdmall;android;version/10.3.4;build/92451;"; OkHttpClient client = new OkHttpClient().newBuilder() .build(); Request request = new Request.Builder() .url(url) .post(requestBody) .headers(Headers.of(header)) .addHeader("Cookie", cookie) .addHeader("User-Agent", userAgent) .addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") .addHeader("Cache-Control", "no-cache") .addHeader("connection", "Keep-Alive") .addHeader("accept", "*/*") .build(); Response response = client.newCall(request).execute(); String result = response.body().string(); log.info("post申请,result:{}", result); return result; }}
主动执行工作脚本,须要的2个接口曾经在代码里标注
/** * 掘金主动签到 * * @return */ @Scheduled(cron = "0 0 9 1/1 * ?") public String juejinSign() throws Exception { log.info("掘金主动签到开始"); Map<String, String> header = Maps.newHashMap(); //签到工作接口 String url = "https://api.juejin.cn/growth_api/v1/check_in"; String juejinCookie = "你的cookie"; RequestBody requestBody = new FormBody.Builder().build(); String response = OkHttpUtils.post(url, juejinCookie, requestBody, header); return response; } /** * 掘金主动抽奖 * * @return */ @Scheduled(cron = "0 0 9 1/1 * ?") public String juejinDraw() throws Exception { log.info("掘金主动抽奖开始"); Map<String, String> header = Maps.newHashMap(); //抽奖接口 String drawUrl = "https://api.juejin.cn/growth_api/v1/lottery/draw"; String juejinCookie = "你的cookie"; RequestBody requestBody = new FormBody.Builder().build(); String response = OkHttpUtils.post(drawUrl, juejinCookie, requestBody, header); return response; }
到此脚本就写好了,最初成果就留给大家本人去尝试了哦~