(.*?)<\/a>/', $data, $matches);
31 | if (isset($matches[2])) {
32 | return $matches[2];
33 | }
34 | return false;
35 | }
36 |
37 | private $data;
38 |
39 | public function VerifyAction($action) {
40 | // TODO: Implement VerifyAction() method.
41 | switch ($action) {
42 | case 'SignV2EX':
43 | $this->httpRequest->setCookie($this->cookie);
44 | $this->httpRequest->setRedirection(4);
45 | $this->data = $this->httpRequest->get('https://www.v2ex.com/mission/daily');
46 | if (strpos($this->data, '你要查看的页面需要先登录') !== false) {
47 | return false;
48 | }
49 | break;
50 | }
51 | return true;
52 | }
53 |
54 | public function VerifyActionResult($actionRet) {
55 | // TODO: Implement VerifyActionResult() method.
56 | return $actionRet;
57 | }
58 |
59 | public function SignV2EX($actMsg) {
60 | if ($signUrl = getStrMid($this->data, 'value="领取 X 铜币" onclick="location.href = \'', '\';"')) {
61 | $signUrl = 'https://www.v2ex.com' . $signUrl;
62 | } else {
63 | return 1;
64 | }
65 | $data = $this->httpRequest->get($signUrl);
66 | if (strpos($data, '已成功领取每日登录奖励') >= 0) {
67 | return 0;
68 | }
69 | return 1;
70 | }
71 | }
--------------------------------------------------------------------------------
/app/common/api/WangyiPlatform.php:
--------------------------------------------------------------------------------
1 | httpRequest = new http();
22 | $this->httpRequest->setHeader([
23 | 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36',
24 | 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'
25 | ]);
26 | }
27 |
28 | public function VerifyAccount() {
29 | // TODO: Implement VerifyAccount() method.
30 | $this->httpRequest->setCookie($this->cookie);
31 | $data = $this->httpRequest->get('http://music.163.com/');
32 | return getStrMid($data, 'nickname:"', '",');
33 | }
34 |
35 | public function VerifyAction($action) {
36 | // TODO: Implement VerifyAction() method.
37 | return true;
38 | }
39 |
40 | public function VerifyActionResult($actionRet) {
41 | // TODO: Implement VerifyActionResult() method.
42 | if (isset($actionRet['code'])) {
43 | if ($actionRet['code'] != 200) {
44 | if ($actionRet['code'] == 301) {
45 | return 2;
46 | }
47 | return 1;
48 | }
49 | return 0;
50 | }
51 | return 1;
52 | }
53 |
54 | public function SignMusic($actMsg) {
55 | $cookie = $actMsg['pu_cookie'];
56 | $this->httpRequest->setCookie($cookie);
57 | $csrf_token = getStrMid($cookie, '__csrf=', ';');
58 | $this->httpRequest->setUrl('http://music.163.com/weapi/login/token/refresh?csrf_token=' . $csrf_token);
59 | $this->httpRequest->setCookie($cookie);
60 | $this->httpRequest->setopt(CURLOPT_HEADER, true);
61 | $post = 'params=' .
62 | urlencode(Encrypt::wy_encrypt(Encrypt::wy_encrypt('{"csrf_token":"' . $csrf_token . '"}',
63 | '0CoJUm6Qyw8W8jud'), 'OKZSxCIegROmuPzk')) . '&encSecKey=596a4853ee7618edb0192bc26b8ff9c88992b4e455c16585be0c41125f56f8dd7eeb9394e0bffc412801bf3ef2d86d52c50e5f19d3aab8e3cca724f9a2b0ac98718b961021e0d488fc1d63772a975841593f4094aa187989eae7f59fe68d3b7077393150b2f529f305fb89068f9ea35d2eacab9188ac8891e911e5513c098b3e';
64 | $data = $this->httpRequest->post($post);
65 | $data = str_replace('__csrf=""', 'error', $data);
66 | $new_csrf_token = getStrMid($data, '__csrf=', ';');
67 | $cookie = str_replace('__csrf=' . $csrf_token, '__csrf=' . $new_csrf_token, $cookie);
68 | $this->httpRequest->setCookie($cookie);
69 | $csrf_token = $new_csrf_token;
70 | $encText = Encrypt::wy_encrypt('{"type":1,"csrf_token":"' . $csrf_token . '"}',
71 | '0CoJUm6Qyw8W8jud');
72 | $encText = Encrypt::wy_encrypt($encText, 'OKZSxCIegROmuPzk');
73 | $this->httpRequest->setHeader(['Referer: http://music.163.com/discover']);
74 | $this->httpRequest->setopt(CURLOPT_HEADER, 0);
75 | $post = 'params=' . urlencode($encText) . '&encSecKey=596a4853ee7618edb0192bc26b8ff9c88992b4e455c16585be0c41125f56f8dd7eeb9394e0bffc412801bf3ef2d86d52c50e5f19d3aab8e3cca724f9a2b0ac98718b961021e0d488fc1d63772a975841593f4094aa187989eae7f59fe68d3b7077393150b2f529f305fb89068f9ea35d2eacab9188ac8891e911e5513c098b3e';
76 | $msgJson = $this->httpRequest->post('http://music.163.com/weapi/point/dailyTask?csrf_token=' . $csrf_token, $post);
77 | return json_decode($msgJson, true);
78 | }
79 |
80 | }
--------------------------------------------------------------------------------
/app/common/ctrl/authCtrl.php:
--------------------------------------------------------------------------------
1 | userMsg = db::table('users')->where('uid', _cookie('uid'))->find();
26 | $this->uid = _cookie('uid');
27 | }
28 | }
--------------------------------------------------------------------------------
/app/common/model/log.php:
--------------------------------------------------------------------------------
1 | uid = $uid;
22 | $this->data['log_time'] = time();
23 | }
24 |
25 | public function action($log, $status) {
26 | $this->data = array_merge(['uid' => $this->uid, 'log_content' => $log, 'log_type' => $status + 10], $this->data);
27 | return $this->add();
28 | }
29 |
30 | public function system($log, $status) {
31 | $this->data = array_merge(['uid' => 0, 'log_content' => $log, 'log_type' => $status + 20], $this->data);
32 | return $this->add();
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/app/common/model/platform.php:
--------------------------------------------------------------------------------
1 | $pid]);
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/app/common/model/user.php:
--------------------------------------------------------------------------------
1 | $uid]);
19 | }
20 | }
21 |
22 | /**
23 | * 验证用户名
24 | * @author Farmer
25 | * @param $user
26 | * @return bool|string
27 | */
28 | public static function isUser($user, $my = null) {
29 | if ($um = self::getUser($user)) {
30 | if (is_null($my)) {
31 | return '用户名已经被注册';
32 | }
33 | return ($um['user'] == $my ?: '用户名已经被注册');
34 | } else {
35 | return true;
36 | }
37 | }
38 |
39 | /**
40 | * 通过 邮箱/用户名/uid 获取用户数据
41 | * @param $user
42 | * @return mixed
43 | */
44 | public static function getUser($user) {
45 | return db::table('users')->where('uid', $user)->_or()->where('username', $user)->_or()->where('email', $user)->find();
46 | }
47 |
48 | public static function register($u, $p, $email) {
49 | db::table()->begin();
50 | db::table('users')->insert([
51 | 'username' => $u,
52 | 'password' => 'tmp',
53 | 'email' => $email,
54 | 'avatar' => 'default.png',
55 | 'reg_time' => time()
56 | ]);
57 | $uid = db::lastinsertid();
58 | db::table('users')->where('uid', $uid)->update(['password' => self::encodePwd($uid, $p)]);
59 | db::table()->commit();
60 | return $uid;
61 | }
62 |
63 | /**
64 | * 通过uid获取用户数据
65 | * @param $uid
66 | * @return mixed
67 | */
68 | public static function uidUser($uid) {
69 | return db::table('users')->where(['uid' => $uid])->find();
70 | }
71 |
72 | /**
73 | * 申请一个账号
74 | * @param $postData
75 | * @return bool
76 | */
77 | public static function applyUser($postData) {
78 | $ret = verify($postData, [
79 | 'act' => ['func' => [
80 | function ($act, $email) {
81 | if (user::verifyToken($act, $email, 1)) {
82 | return true;
83 | }
84 | return '错误的令牌';
85 | }, 'email'], 'msg' => '错误的令牌'],
86 | 'username' => ['func' => ['\app\common\model\user::isUser'], 'regex' => ['/^[\x{4e00}-\x{9fa5}\w\@\.]{2,16}$/u', '用户名格式错误'], 'msg' => '用户名不能为空', 'sql' => 'username'],
87 | 'password' => ['regex' => ['/^[\\~!@#$%^&*()-_=+|{}\[\], .?\/:;\'\"\d\w]{6,16}$/', '密码不符合规范'], 'msg' => '请输入密码', 'sql' => 'password'],
88 | 'email' => ['func' => ['\app\common\model\user::isEmail'], 'regex' => ['/^[\w\.]{1,16}@(qq\.com|foxmail.com|163\.com|outlook\.com)$/', '邮箱格式错误'], 'msg' => '邮箱不能为空', 'sql' => 'email'],
89 | ], $data);
90 | if ($ret === true) {
91 | //添加用户
92 | $data['avatar'] = 'default.png';
93 | $data['reg_time'] = time();
94 | db::table('users')->insert($data);
95 | $uid = db::table()->lastinsertid();
96 | user::deleteToken($postData['act']);
97 | return true;
98 | }
99 | return $ret;
100 | }
101 |
102 | /**
103 | * 创建一个验证令牌
104 | * @param $val
105 | * @param int $type
106 | * @return string
107 | */
108 | public static function createToken($val, $type = 0) {
109 | $len = 16;
110 | if ($type == 1) {
111 | $len = 64;
112 | \icf\lib\db::table('token')->where(['type' => 1, 'value' => $val])->delete();
113 | }
114 | $token = '';
115 | do {
116 | $token = getRandString($len, 2);
117 | } while (\icf\lib\db::table('token')->where('token', $token)->count());
118 | \icf\lib\db::table('token')->insert(['token' => $token, 'value' => $val, 'time' => time(), 'type' => $type]);
119 | return $token;
120 | }
121 |
122 | /**
123 | * 验证token是否有效,返回token数量
124 | * @param $token
125 | * @param $val
126 | * @param int $type
127 | * @return mixed
128 | */
129 | public static function verifyToken($token, $val, $type = 0) {
130 | $db = \icf\lib\db::table('token');
131 | $db->where(['token' => $token, 'value' => $val]);
132 | if ($type == 1) {
133 | $db->where('time', time() - 1800, '>');//30分钟有效期
134 | } else {
135 | $db->where('time', time() - 432000, '>');//5天有效期
136 | }
137 | return $db->count();
138 | }
139 |
140 | /**
141 | * 删除令牌
142 | * @param $token
143 | */
144 | public static function deleteToken($token) {
145 | \icf\lib\db::table('token')->where('token', $token)->delete();
146 | }
147 |
148 | /**
149 | * 验证邮箱
150 | * @author Farmer
151 | * @param $user
152 | * @return bool|string
153 | */
154 | public static function isEmail($email) {
155 | if (self::getUser($email)) {
156 | return '邮箱已经被注册';
157 | } else {
158 | return true;
159 | }
160 | }
161 |
162 | /**
163 | * 判断是否登陆
164 | * @return bool|mixed
165 | */
166 | public static function isLogin() {
167 | if ($uid = _cookie('uid') && $token = _cookie('token')) {
168 | return self::verifyToken(_cookie('token'), _cookie('uid'));
169 | }
170 | return false;
171 | }
172 |
173 | /**
174 | * 编码密码
175 | * @author Farmer
176 | * @param $uid
177 | * @param $pwd
178 | * @return string
179 | */
180 | public static function encodePwd($uid, $pwd) {
181 | $str = hash('sha256', $uid . $pwd . config('pwd_encode_salt'));
182 | return $str;
183 | }
184 | }
--------------------------------------------------------------------------------
/app/index/common.php:
--------------------------------------------------------------------------------
1 | true,
13 | ];
--------------------------------------------------------------------------------
/app/index/ctrl/index.php:
--------------------------------------------------------------------------------
1 | display();
21 | }
22 |
23 | protected function errorCode($code, $error = '') {
24 | //方便前端通过错误代码提示错误
25 | $errorCode = [
26 | '登录成功' => 0,
27 | '注册成功' => 0,
28 | '用户名已经被注册' => 10001,
29 | '用户名不能为空' => 10002,
30 | '用户名格式错误' => 10003,
31 | '用户不存在' => 10003,
32 | '密码不符合规范' => 10004,
33 | '密码错误' => 10005,
34 | '请输入密码' => 10006,
35 | '邮箱格式不正确' => 10007,
36 | '错误的令牌' => 10020
37 | ];
38 | if (empty($error)) {
39 | $error = $code;
40 | $code = -1;
41 | }
42 | if (isset($errorCode[$error])) $code = $errorCode[$error];
43 | return ['code' => $code, 'msg' => $error];
44 | }
45 |
46 | public function login() {
47 | $ret = verify($_POST, [
48 | 'u' => ['msg' => '用户名不能为空', 'sql' => 'username'],
49 | 'p' => ['regex' => ['/^[\\~!@#$%^&*()-_=+|{}\[\], .?\/:;\'\"\d\w]{6,16}$/', '密码不符合规范'], 'msg' => '请输入密码', 'sql' => 'password']
50 | ], $data);
51 | if ($ret === true) {
52 | if ($userMsg = user::getUser($data['username'])) {
53 | if (user::encodePwd($userMsg['uid'], $data['password']) == $userMsg['password']) {
54 | setcookie('token', user::createToken($userMsg['uid']), time() + 432000, getUrlRoot());
55 | setcookie('uid', $userMsg['uid'], time() + 432000, getUrlRoot());
56 | $ret = '登录成功';
57 | } else {
58 | $ret = '密码错误';
59 | }
60 | } else {
61 | $ret = '用户不存在';
62 | }
63 | }
64 | return self::errorCode($ret);
65 | }
66 |
67 | public function register() {
68 | view()->display();
69 | }
70 |
71 | public function postRegister() {
72 | $ret = verify($_POST, [
73 | 'u' => ['msg' => '用户名不能为空', 'sql' => 'username'],
74 | 'p' => ['regex' => ['/^[\x20-\x7e]{6,16}$/', '密码不符合规范'], 'msg' => '请输入密码', 'sql' => 'password'],
75 | 'email' => [
76 | 'regex' => ['/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/', '邮箱格式不正确'],
77 | 'msg' => '请输入邮箱',
78 | 'sql' => 'email'
79 | ]
80 | ], $data);
81 | if ($ret === true) {
82 | if ($userMsg = user::getUser($data['username'])) {
83 | $ret = '用户名已经被注册';
84 | } else {
85 | if ($uid = user::register($data['username'], $data['password'], $data['email'])) {
86 | setcookie('token', user::createToken($uid), time() + 432000, getUrlRoot());
87 | setcookie('uid', $userMsg['uid'], time() + 432000, getUrlRoot());
88 | $ret = '注册成功';
89 | } else {
90 | $ret = '注册失败';
91 | }
92 | }
93 | }
94 | return self::errorCode($ret);
95 | }
96 | }
--------------------------------------------------------------------------------
/app/index/ctrl/user.php:
--------------------------------------------------------------------------------
1 | assign('task', task::getUserAllTaskMsg($this->uid));
25 | view()->assign('platform', db::table('platform')->select()->fetchAll());
26 | view()->assign('account', db::table('platform_account as a')
27 | ->join(':platform as b', 'a.pid=b.pid')
28 | ->where('uid', $this->uid)
29 | ->select()->fetchAll());
30 | view()->display();
31 | }
32 |
33 | public function run($tid) {
34 | $task = new task($tid);
35 | $ret = $task->run();
36 | if (isset($ret['ret']['error_msg'])) {
37 | unset($ret['ret']['error_msg']);
38 | }
39 | return $ret;
40 | }
41 |
42 | public function update_cookie() {
43 | $actDb = db::table('platform_account')->where('uid', $this->uid)
44 | ->where('puid', input('post.puid'));
45 | $ret = $actDb->find();
46 | if (!$ret) {
47 | return new Error(-1, '没有找到相应的修改记录');
48 | }
49 | if (input('post.cookie')) {
50 | $pid = $ret['pid'];
51 | $retUser = $this->verify_account($pid);
52 | if (is_array($retUser)) {
53 | $actDb->update(['pu_status' => 1, 'pu_time' => time(),
54 | 'pu_u' => $retUser['u'], 'pu_cookie' => input('post.cookie')]);
55 | db::table('action_task')
56 | ->where('puid', input('post.puid'))->update(['task_status' => 1]);
57 | $ret = new Error(0, '修改成功');
58 | } else {
59 | $ret = new Error(-1, '错误的账号Cookie');
60 | }
61 | } else {
62 | $actDb->delete();
63 | $ret = new Error(1, '删除成功');
64 | }
65 | return $ret;
66 | }
67 |
68 | public function postAccount() {
69 | $pid = _post('pid');
70 | if (db::table('platform_account')->where('uid', _cookie('uid'))->where('pid', $pid)->count()) {
71 | return new Error(-1, '已经添加过一个账号');
72 | }
73 | $ret = $this->verify_account($pid);
74 | if (is_array($ret)) {
75 | db::table('platform_account')
76 | ->insert(['pid' => $pid, 'pu_time' => time(), 'uid' => _cookie('uid'), 'pu_u' => $ret['u'],
77 | 'pu_status' => 1, 'pu_cookie' => _post('cookie')]);
78 | return new Error(0, '添加成功');
79 | } else {
80 | return new Error(-1, $ret);
81 | }
82 | }
83 |
84 | public function getAction($pid) {
85 | return db::table('action')->where('pid', $pid)->select()->fetchAll();
86 | }
87 |
88 | public function plogin($pid) {
89 | $plat = new platform($pid);
90 | if ($plat->getData()) {
91 | $platApi = 'app\\common\\api\\' . $plat->_api;
92 | $platApi = new $platApi('') ?: new BaiduPlatform('');
93 | if ($platApi instanceof PlatformLogin) {
94 | return new Error(0, 'success', ['is_login' => 1]);
95 | }
96 | return new Error(-1, '没有账号登录的接口');
97 | }
98 | return new Error(-1, '不存在的平台');
99 | }
100 |
101 | public function postPlogin() {
102 | $plat = new platform(input('post.pid'));
103 | if ($plat->getData()) {
104 | $platApi = 'app\\common\\api\\' . $plat->_api;
105 | $platApi = new $platApi('') ?: new BaiduPlatform('');
106 | if ($platApi instanceof PlatformLogin) {
107 | $ret = $platApi->Login(input('post.u'), input('post.p'), $cookie);
108 | if ($ret === true) {
109 | return new Error(0, '登录成功', ['cookie' => $cookie]);
110 | }
111 | return new Error(-2, '登录失败', ['status' => $ret]);
112 | }
113 | return new Error(-1, '没有账号登录的接口');
114 | }
115 | return new Error(-1, '不存在的平台');
116 | }
117 |
118 | public function postAction() {
119 | $pid = _post('pid');
120 | $aid = _post('aid');
121 | if (db::table('action_task')->where('uid', _cookie('uid'))->where('aid', $aid)->count()) {
122 | return new Error(-1, '已经添加过一次');
123 | }
124 | if (!($accountRow = db::table('platform_account')->where(['pid' => $pid, 'uid' => _cookie('uid')])->find())) {
125 | return new Error(-1, '找不到账号');
126 | }
127 | $ret = $this->verify_action($pid, $aid);
128 | if (is_array($ret)) {
129 | db::table('action_task')
130 | ->insert(['uid' => _cookie('uid'), 'puid' => $accountRow['puid'], 'aid' => $aid,
131 | 'task_param' => json($ret['param']), 'task_last_time' => 0, 'task_status' => 1]);
132 | return new Error(0, '添加成功');
133 | } else {
134 | return new Error(-1, $ret);
135 | }
136 |
137 | }
138 |
139 | private function verify_action($pid, $aid) {
140 | $plat = new platform($pid);
141 | if ($plat->getData()) {
142 | if ($actionRow = db::table('action')->where(['aid' => $aid, 'pid' => $pid])->find()) {
143 | $platApi = 'app\\common\\api\\' . $plat->_api;
144 | /** @var BasePlatform $platApi */
145 | $platApi = new $platApi(['uid' => _cookie('uid'), 'pid' => $pid]);
146 | if ($platData = $platApi->VerifyAction($actionRow['action_api'])) {
147 | return ['param' => $platData];
148 | } else {
149 | return '操作错误';
150 | }
151 | } else {
152 | return '操作不存在';
153 | }
154 | } else {
155 | return '平台不存在';
156 | }
157 | }
158 |
159 | private function verify_account($pid) {
160 | $plat = new platform($pid);
161 | if ($plat->getData()) {
162 | $platApi = 'app\\common\\api\\' . $plat->_api;
163 | $platApi = new $platApi(_post('cookie')) ?: new BaiduPlatform(_post('cookie'));
164 | if ($platData = $platApi->VerifyAccount()) {
165 | return ['u' => $platData];
166 | } else {
167 | return '账号错误';
168 | }
169 | } else {
170 | return '平台不存在';
171 | }
172 | }
173 | }
--------------------------------------------------------------------------------
/app/index/model/task.php:
--------------------------------------------------------------------------------
1 | tid = $tid;
24 | $this->data = db::table('action_task as a')
25 | ->join(':action as b', 'a.aid=b.aid')
26 | ->join(':platform as c', 'b.pid=c.pid')
27 | ->join(':platform_account as d', 'd.puid=a.puid')
28 | ->where('tid', $tid)->find();
29 | }
30 |
31 | /**
32 | * @param int $uid
33 | * @param array $limit
34 | * @return array
35 | */
36 | public static function getUserAllTaskMsg($uid, $limit = []) {
37 | return db::table('action_task as a')->join(':action as b', 'a.aid=b.aid')
38 | ->where('uid', $uid)->select()->fetchAll();
39 | }
40 |
41 | public function getTaskActionApi() {
42 | return $this->data['action_api'];
43 | }
44 |
45 | public function getTaskPlatformApi() {
46 | return $this->data['platform_api'];
47 | }
48 |
49 | public function getCookie() {
50 | return $this->data['pu_cookie'];
51 | }
52 |
53 | public function run() {
54 | $platApi = 'app\\common\\api\\' . $this->getTaskPlatformApi();
55 | $platApi = new $platApi(['puid' => $this->data['puid']]) ?: new BaiduPlatform(['puid' => $this->data['puid']]);
56 | $param = $platApi->VerifyAction($this->getTaskActionApi());
57 | if ($param) {
58 | $row = $this->data;
59 | $row['param'] = $param;
60 | $param = json($param);
61 | db::table('action_task')->where('tid', $this->tid)->update(['task_param' => $param]);
62 | $row['task_param'] = $param;
63 | $ret = call_user_func([
64 | $platApi, $this->getTaskActionApi()
65 | ], $row);
66 | $result = $platApi->VerifyActionResult($ret);
67 | $status = ['成功', '签过到了|错误', '账号失效'];
68 | return ['code' => $result, 'aid' => $this->data['aid'], 'msg' => $status[$result], 'ret' => $ret];
69 | } else {
70 | return ['code' => 2, 'aid' => $this->data['aid'], 'msg' => '账号失效'];
71 | }
72 | }
73 | }
--------------------------------------------------------------------------------
/app/index/tpl/index/bottom.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | 主要是利用php来设置一个定时任务,实现每日签到
4 | 然后就是签到的封包了
5 | 不过php是单线程的,效率挺低,后面可以改成多进程的模式提高效率
6 | 监控文件:app\admin\ctrl\monitor.php
7 | 总之现在是一个很不完善的玩意=_=
8 | 详细内容请看github上的说明
9 |
10 |