获取个站签到列表 - 松风闲云

/ 23 views🌹 / 永远热泪盈眶💬 / 3🧡

个站最常用到的就是签到模块了, 所以我就做了个获取当天签到网站列表的cmd小工具。

核心代码就是模拟请求它的签到列表API

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $_memberId = Cache::get('memberId');
        if (!$_memberId) {
            $_memberId = $this->ask('What is your memberId ?');
            if ($_memberId) {
                Cache::put('memberId', $_memberId);
            }
        }
        if ($this->option('f')) {
            $response = false;
        } else {
            $response =  Cache::get('sw_cw');
        }

        //dd();
        if (empty($response)) {
            $response = $this->reqAPI('api/index/signInList');
            if (0 != $response['code']) {
                $this->error('请求失败');
            }
            $this->info($response['msg']);

            /*
        ^ array:3 [
  "code" => 0
  "msg" => "获取签到列表成功"
  "data" => array:20 [
    0 => array:3 [
      "memberId" => 646
      "member" => array:5 [
        "memberId" => 646
        "name" => "JoiT"
        "intro" => "养了一只名叫米崽的 15 斤狸花小猫,天天军训它,所以又名:警猫训练虱"
        "avatarUrl" => "https://upload.storeweb.cn/upload/member/avatar/646/061daaf751db3d2a5dba6c8274d0a272.jpg"
        "sexName" => "男"
      ]
      "createAt" => "2022-05-31 00:03:29"
    ]
    1 => array:3 [
      "memberId" => 1195
      "member" => array:5 [
        "memberId" => 1195
        "name" => "土拨许"
        "intro" => "喂~在吗?在吗?这里是土拨许~"
        "avatarUrl" => "https://upload.storeweb.cn/upload/member/avatar/1195/90e617effb3e0ba2442dc14b745bf384.jpg"
        "sexName" => "男"
      ]
      "createAt" => "2022-05-31 00:17:39"
    ]
        */
            //$this->info($response);
            Cache::put('sw_cw', $response, 3600);
            $this->line('更新缓存...');
        } else {
            $this->line('获取缓存...');
        }
        //行间插入空行
        $columns = [];

        //dd(Arr::pluck($response['data'], 'memberId'));
        $mySignLog = Arr::first($response['data'], function ($value) use ($_memberId) {
            return  $_memberId == $value['memberId'];
        });
        if (empty($mySignLog)) {
            $sessionId = Cache::get('sessionId'); // a string 32 chars
            if (!$sessionId) {
                $sessionId = $this->ask('What is your session-id ?');
            }

            $this->signIn($sessionId);
        } else {
            $this->info('你在' . $mySignLog['createAt'] . '签到了,喵');
        }

        $turn = -1;
        foreach ($response['data'] as $key => $item) {
            $_item = [];
            // Arr::only($item['member'], ['name', 'intro', 'sexName', 'memberId']) + [$item['createAt']];
            $_item['at'] = explode(' ', $item['createAt'])[1];
            $_item['url'] = '<info>https://storeweb.cn/member/o/' . $item['memberId'] . '</info>';
            if ($_memberId == $item['memberId']) {
                $_item['name'] = '⭐' . $item['member']['name'];
                $turn = $key;
            } else {
                $_item['name'] = $item['member']['name'];
            }
            $_item['sex'] = $item['member']['sexName'] == '小猫(保密)' ? '' : $item['member']['sexName'];
            $_item['intro'] = Str::limit($item['member']['intro'], 72);

            $columns[] = $_item;
            //$columns[] = ['', '', '', '', ''];
        }

        $headers = ['⏰ ', '🔗', '😀', '♀♂', 'o(=•ェ•=)m'];
        $this->table($headers, $columns); //borderless, 'compact'
        $this->line('一共有' . count($response['data']) . '个人勤快的签到啦' . (($turn > 0) ? ',你是第' . (++$turn) . '个' : ''));
    }

完整的代码见:Github

顺带加入了没签到的情况下自动签到功能(需要通过浏览器控制台获取到session-id)

运行结果示例

zero_tool demo

最后更新于 2月 前 by mouc

  1. FGHWETT说道:

    学习到了

发表回复

您的电子邮箱地址不会被公开。