掘金签到和抽奖

掘金签到和抽奖

GitHub版本和下面不一样:GitHub - 247913018/juejin at master

接口文档:掘金

掘金签到和抽奖,搞个服务器,然后写个定时任务挂在服务上,每天自动签到和抽奖,如果想不看抽奖轮盘你也可以写逻辑,核心功能已经写好了 cookie获取方式

image.png


    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;
    }
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值