吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2574|回复: 37
收起左侧

[其他原创] PHP阿里云签到脚本

  [复制链接]
moyefu 发表于 2023-12-14 15:25
本帖最后由 moyefu 于 2023-12-15 09:38 编辑

声明:本文的代码都是仿照大佬门的脚本 播此内容是基于学术研究和学习目的。
最近看到很多小伙伴要一个php的签到脚本 今天他来了
[PHP] 纯文本查看 复制代码
<?php

/**
 * 阿里云盘自动签到
 */
class AlyPanAutoSign
{
    protected $refresh_token = '';
    protected $access_token  = '';
    protected $user_name     = '';
    protected $user          = [];

    public function __construct($refresh_token = '')
    {
        if ($refresh_token) $this->setRefreshToken($refresh_token);
    }

    /**
     * CURL发送Request请求,含POST和REQUEST
     * @Param string $url    请求的链接
     * @param mixed  $params 传递的参数
     * @param string $method 请求的方法
     * @param array  $header 请求头
     * @Return array
     */
    protected function sendRequest($url, $params = [], $method = 'POST', $header = [])
    {
        $method = strtoupper($method);
        $protocol = substr($url, 0, 5);
        $query_string = is_array($params) ? http_build_query($params) : $params;

        $ch = curl_init();
        $defaults = [];
        if ('GET' == $method) {
            $geturl = $query_string ? $url . (stripos($url, "?") !== false ? "&" : "?") . $query_string : $url;
            $defaults[CURLOPT_URL] = $geturl;
        } else {
            $defaults[CURLOPT_URL] = $url;
            if ($method == 'POST') {
                $defaults[CURLOPT_POST] = 1;
            } else {
                $defaults[CURLOPT_CUSTOMREQUEST] = $method;
            }
            $defaults[CURLOPT_POSTFIELDS] = $params;
        }

        $defaults[CURLOPT_HEADER] = false;
        $defaults[CURLOPT_USERAGENT] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.98 Safari/537.36";
        $defaults[CURLOPT_FOLLOWLOCATION] = true;
        $defaults[CURLOPT_RETURNTRANSFER] = true;
        $defaults[CURLOPT_CONNECTTIMEOUT] = 3;
        $defaults[CURLOPT_TIMEOUT] = 3;

        // disable 100-continue
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

        if ('https' == $protocol) {
            $defaults[CURLOPT_SSL_VERIFYPEER] = false;
            $defaults[CURLOPT_SSL_VERIFYHOST] = false;
        }

        curl_setopt_array($ch, $defaults);

        $ret = curl_exec($ch);
        $err = curl_error($ch);

        if (false === $ret || !empty($err)) {
            $errno = curl_errno($ch);
            $info = curl_getinfo($ch);
            curl_close($ch);
            return [
                'ret'   => false,
                'errno' => $errno,
                'msg'   => $err,
                'info'  => $info,
            ];
        }
        curl_close($ch);
        return [
            'ret' => true,
            'msg' => $ret,
        ];
    }

    protected function writeln($msg)
    {

        if (PHP_SAPI == 'cli') {
            echo "$msg\n";
        } else {
            echo "$msg </br>";
        }
    }

    protected function error($msg)
    {
        if (PHP_SAPI == 'cli') {
            echo "<error>$msg</error>\n";
        } else {
            echo "<span style='color: red'>$msg</span><br>";
        }
        die;
    }

    protected function success($msg)
    {
        if (PHP_SAPI == 'cli') {
            echo "<success>$msg</success>\n";
        } else {
            echo "<span style='color: green'>$msg</span><br>";
        }
        die;
    }

    public function setRefreshToken($refresh_token = '')
    {
        $this->refresh_token = $refresh_token;
        return $this;
    }

    /**
     * 获取用户信息
     */
    protected function getAccessToken()
    {
        try {
            $res = $this->sendRequest("https://auth.aliyundrive.com/v2/account/token", json_encode([
                'grant_type'    => 'refresh_token',
                'refresh_token' => $this->refresh_token,
            ]), 'POST', ['Content-Type: application/json',]);
            if (!$res['ret']) $this->error("获取access_token失败");
            $data = json_decode($res['msg'], true);
            if (isset($data['message'])) $this->writeln($data['message']);
            if (!isset($data['access_token'])) $this->error("refresh_token异常,获取access_token失败 可能是refresh_token过期");
            $this->access_token = $data['access_token'];
            $this->user_name = $data['nick_name'] . ":" . $data['user_name'];
            $this->user = $data;
            $this->writeln($this->user_name . " ---登录成功---");
        } catch (Exception $e) {
            $this->error("程序错误:" . $e->getMessage());
        }
    }

    /**
     * 签到
     */
    protected function signIn()
    {
        if (!$this->user) $this->error("请登录!!!");
        try {
            $res = $this->sendRequest("https://member.aliyundrive.com/v1/activity/sign_in_list", json_encode([
                "_rx-s" => "mobile",
            ]), 'POST', ['Content-Type: application/json', "Authorization: Bearer $this->access_token"]);
            if (!$res['ret']) $this->error("请求签到失败");
            $data = json_decode($res['msg'], true);
            if (isset($data['message'])) $this->writeln($data['message']);
            if (!isset($data['result']['signInCount'])) $this->error("签到失败");
            $this->writeln("---$this->user_name 签到成功,本月累计签到{$data['result']['signInCount']}次---");
            $this->user['signInCount'] = $data['result']['signInCount'];
        } catch (Exception $e) {
            $this->error("程序错误:" . $e->getMessage());
        }
    }

    /**
     * 领取签到奖励
     */
    protected function receiveSignInReward()
    {
        if (!$this->user) $this->error("请登录!!!");
        try {
            $res = $this->sendRequest("https://member.aliyundrive.com/v1/activity/sign_in_reward?_rx-s=mobile'", json_encode([
                'signInDay' => $this->user['signInCount'],
            ]), 'POST', ['Content-Type: application/json', "Authorization: Bearer $this->access_token"]);
            if (!$res['ret']) $this->error("请求获取奖励失败");
            $data = json_decode($res['msg'], true);
            if (isset($data['message'])) $this->writeln($data['message']);
            if (!isset($data['result']['notice'])) $this->error("签到失败");
            $this->writeln("---$this->user_name 领取奖励成功,{$data['result']['name']}-{$data['result']['description']}-{$data['result']['notice']}---");
        } catch (Exception $e) {
            $this->error("程序错误:" . $e->getMessage());
        }
    }

    public function run($refresh_token = '')
    {
        if ($refresh_token) $this->refresh_token = $refresh_token;
        $this->getAccessToken();
        $this->signIn();
        $this->receiveSignInReward();
    }
}

(new AlyPanAutoSign)->setRefreshToken("你的refresh_token")->run();


PHP版本亲测7.2可用 其它版本按理都是通用的

实测图

实测图

RefreshToken获取方法网上一堆我就不重复了
(本人php小白 大佬们轻点 温柔点 那里不可以!!! 也不是不行 就一次哦)

------------------------------------------------------------------------------------
问:refresh_token填哪?
答:在脚本的最后(new AlyPanAutoSign)->setRefreshToken("你的refresh_token")->run(); 这里填入你的refresh_token。

免费评分

参与人数 7吾爱币 +13 热心值 +7 收起 理由
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
timeni + 1 + 1 用心讨论,共获提升!
ppszxc + 2 + 1 谢谢@Thanks!
傲雪不傲霜 + 1 + 1 我很赞同!
只为改变世界 + 1 可否加入签到提醒。
antclt + 1 + 1 谢谢@Thanks!
schm168 + 1 + 1 谢谢@Thanks!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

坐久落花多 发表于 2023-12-14 17:13
赞!要是wps那个不行了,我就换这个
 楼主| moyefu 发表于 2023-12-15 09:19
1997mtnh 发表于 2023-12-14 19:11
The input parameter refresh_token is not valid.
refresh_token异常,获取access_token失败 可能是refre ...

在脚本最后一行
(new AlyPanAutoSign)->setRefreshToken("你的Token")->run();
把你的refresh_token填到你的Token里面就行
 楼主| moyefu 发表于 2024-6-5 13:21
openJQ 发表于 2024-6-2 00:31
代码好像过期了,,运行提示需要更新最新APP
hmymy2 发表于 2024-3-25 09:24
学习下学习下
 楼主| moyefu 发表于 2024-3-25 09:05
openJQ 发表于 2024-3-17 11:27
refresh_token是永久有效的吗?

不是 一般一个月左右 时间不固定
openJQ 发表于 2024-3-17 11:27
refresh_token是永久有效的吗?
hh258123 发表于 2024-3-16 15:25
评论会升级吗
shihao2002 发表于 2024-3-15 21:20
不会用啊&#128550;&#128550;
yeyuanxinyi 发表于 2024-3-15 21:03
学到了,让我一个懒人又更懒了
anyway001 发表于 2024-3-14 09:21
学习学习 感谢大佬分享
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-24 16:28

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表