宝塔实现阿里云盘自动每日签到领取奖品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();

懒人一键下载脚本:https://www.123pan.com/s/8pFiVv-pTbUh.html

使用方法

1.获取阿里云refresh_token自己帐号登录网页版云盘,按照下面方法获取。

宝塔实现阿里云盘自动每日签到领取奖品PHP脚本插图

2.在脚本代码最后(new AlyPanAutoSign)->setRefreshToken("你的refresh_token")->run(); 这里填入你的refresh_token

3.在宝塔计划任务设置每日定时访问脚本即可。

宝塔实现阿里云盘自动每日签到领取奖品PHP脚本插图1

4.签到成功示例。

宝塔实现阿里云盘自动每日签到领取奖品PHP脚本插图2

常见问题

如遇签到失败,绝大部分原因是因为refresh_token失效(一般有效期一个月),只要按上面方法重新获取refresh_token并更新即可。

本站代码模板仅供学习交流使用请勿商业运营,严禁从事违法,侵权等任何非法活动,否则后果自负!
温馨提示:本文最后更新于2024-03-01 10:03:45已超过143天没有更新,某些文章具有时效性,若有错误或已失效,请在下方留言或联系官方客服
文章版权声明 1 本网站名称: 谷酷资源网
2 本站永久网址:https://www.zuitx.com
3 本网站资源全部来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
4 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5 本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报。
6 本站资源大多存储在云盘,如发现链接失效,请联系我们更新。
7 购买或使用本站资源均默认同意《免责声明》以及《使用条款》

ZUITX.COM
喜欢就支持一下吧
点赞8赞赏 分享打赏
评论 抢沙发

请登录后发表评论

    暂无评论内容