123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- <?php
- namespace app\index\controller;
- use app\common\controller\Uc;
- use app\common\model\User;
- use app\common\model\UserThird;
- use fast\Random;
- use think\Loader;
- /**
- * Ucenter接口,接收来自Ucenter服务器的请求
- *
- */
- class Ucenter extends Uc
- {
- public function _initialize()
- {
- //导入UC常量
- Loader::import('uc', APP_PATH);
- parent::_initialize();
- }
- /**
- * Ucenter接口接收方法
- */
- public function api()
- {
- $this->response();
- return;
- }
- public function index()
- {
- $this->redirect('/');
- return;
- }
- /**
- * 删除用户
- */
- function deleteuser()
- {
- $uids = $this->get['ids'];
- $uids = is_array($uids) ? $uids : explode(',', $uids);
- !API_DELETEUSER && exit(API_RETURN_FORBIDDEN);
- User::destroy($uids);
- UserThird::destroy($uids);
- $result = TRUE;
- return $result ? API_RETURN_SUCCEED : API_RETURN_FAILED;
- }
- /**
- * 获取标签
- */
- function gettag()
- {
- $name = $this->get['id'];
- if (!API_GETTAG)
- {
- return API_RETURN_FORBIDDEN;
- }
- $datalist = [];
- if ($name == 'get_recently_list')
- {
- for ($i = 0; $i < 9; $i++)
- {
- $datalist[] = array(
- 'name' => 'name' . $i,
- 'uid' => 1,
- 'username' => 'username' . $i,
- 'dateline' => '2021',
- 'url' => 'http://www.yourwebsite.com/thread.php?id=',
- 'image' => 'http://www.yourwebsite.com/threadimage.php?id=',
- );
- }
- }
- return $this->_serialize([$name, $datalist], 1);
- }
- /**
- * 同步注册
- */
- function synregister()
- {
- $uid = $this->get['uid'];
- $username = $this->get['username'];
- $password = $this->get['password'];
- $email = isset($this->get['email']) ? $this->get['email'] : '';
- $mobile = isset($this->get['mobile']) ? $this->get['mobile'] : '';
- if (!API_SYNLOGIN)
- {
- return API_RETURN_FORBIDDEN;
- }
- // 同步注册接口
- header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
- $this->user->register($username, $password, $email, $mobile, [], 0, FALSE);
- echo 'signup ok';
- }
- /**
- * 同步登录
- */
- function synlogin()
- {
- $uid = $this->get['uid'];
- $username = $this->get['username'];
- if (!API_SYNLOGIN)
- {
- return API_RETURN_FORBIDDEN;
- }
- // 同步登录接口
- header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
- $this->user->direct($uid, FALSE);
- echo 'login ok';
- }
- /**
- * 同步退出
- */
- function synlogout()
- {
- if (!API_SYNLOGOUT)
- {
- return API_RETURN_FORBIDDEN;
- }
- //同步登出接口
- header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
- $this->user->logout();
- echo 'logout ok';
- }
- /**
- * 添加用户
- */
- function adduser()
- {
- $uid = $this->get['uid'];
- $username = $this->get['username'];
- $password = $this->get['password'];
- $email = isset($this->get['email']) ? $this->get['email'] : '';
- $mobile = isset($this->get['mobile']) ? $this->get['mobile'] : '';
- if (!API_ADDUSER)
- {
- return API_RETURN_FORBIDDEN;
- }
- $time = time();
- $salt = Random::alnum();
- $password = $this->user->getEncryptPassword($password, $salt);
- $ip = $this->request->ip();
- $userarr = [
- 'id' => $uid,
- 'username' => $username,
- 'password' => $password,
- 'salt' => $salt,
- 'email' => $email,
- 'mobile' => $mobile,
- 'jointime' => $time,
- 'joinip' => $ip
- ];
- User::save($userarr);
- return API_RETURN_SUCCEED;
- }
- /**
- * 更新用户信息,包含用户名,密码,邮箱,手机号和其它扩展信息
- */
- function updateinfo()
- {
- if (!API_UPDATEINFO)
- {
- return API_RETURN_FORBIDDEN;
- }
- $uid = isset($this->get['uid']) ? $this->get['uid'] : 0;
- $username = isset($this->get['username']) ? $this->get['username'] : '';
- $password = isset($this->get['password']) ? $this->get['password'] : '';
- $email = isset($this->get['email']) ? $this->get['email'] : '';
- $mobile = isset($this->get['mobile']) ? $this->get['mobile'] : '';
- print_r($this->get);
- $userinfo = User::get($uid);
- if (!$userinfo)
- {
- return API_RETURN_FAILED;
- }
- $values = [];
- if ($username)
- {
- $values['username'] = $username;
- }
- if ($password)
- {
- $salt = Random::alnum();
- $password = $this->user->getEncryptPassword($password, $salt);
- $values['password'] = $password;
- $values['salt'] = $salt;
- }
- if ($email)
- {
- $values['email'] = $email;
- }
- if ($mobile)
- {
- $values['mobile'] = $mobile;
- }
- $userinfo->save($values);
- return API_RETURN_SUCCEED;
- }
- /**
- * 更新禁言文字
- */
- function updatebadwords()
- {
- if (!API_UPDATEBADWORDS)
- {
- return API_RETURN_FORBIDDEN;
- }
- $cachefile = $this->appdir . './uc_client/data/cache/badwords.php';
- $fp = fopen($cachefile, 'w');
- $data = array();
- if (is_array($this->post))
- {
- foreach ($this->post as $k => $v)
- {
- $data['findpattern'][$k] = $v['findpattern'];
- $data['replace'][$k] = $v['replacement'];
- }
- }
- $s = "<?php\r\n";
- $s .= '$_CACHE[\'badwords\'] = ' . var_export($data, TRUE) . ";\r\n";
- fwrite($fp, $s);
- fclose($fp);
- return API_RETURN_SUCCEED;
- }
- /**
- * 更新HOSTS
- */
- function updatehosts()
- {
- if (!API_UPDATEHOSTS)
- {
- return API_RETURN_FORBIDDEN;
- }
- $cachefile = $this->appdir . './uc_client/data/cache/hosts.php';
- $fp = fopen($cachefile, 'w');
- $s = "<?php\r\n";
- $s .= '$_CACHE[\'hosts\'] = ' . var_export($this->post, TRUE) . ";\r\n";
- fwrite($fp, $s);
- fclose($fp);
- return API_RETURN_SUCCEED;
- }
- /**
- * 更新App信息
- */
- function updateapps()
- {
- if (!API_UPDATEAPPS)
- {
- return API_RETURN_FORBIDDEN;
- }
- $UC_API = $this->post['UC_API'];
- //note 写 app 缓存文件
- $cachefile = $this->appdir . './uc_client/data/cache/apps.php';
- $fp = fopen($cachefile, 'w');
- $s = "<?php\r\n";
- $s .= '$_CACHE[\'apps\'] = ' . var_export($this->post, TRUE) . ";\r\n";
- fwrite($fp, $s);
- fclose($fp);
- //note 写配置文件
- if (is_writeable($this->appdir . './config.inc.php'))
- {
- $configfile = trim(file_get_contents($this->appdir . './config.inc.php'));
- $configfile = substr($configfile, -2) == '?>' ? substr($configfile, 0, -2) : $configfile;
- $configfile = preg_replace("/define\('UC_API',\s*'.*?'\);/i", "define('UC_API', '$UC_API');", $configfile);
- if ($fp = @fopen($this->appdir . './config.inc.php', 'w'))
- {
- @fwrite($fp, trim($configfile));
- @fclose($fp);
- }
- }
- return API_RETURN_SUCCEED;
- }
- /**
- * 更新客户端配置文件
- */
- function updateclient()
- {
- if (!API_UPDATECLIENT)
- {
- return API_RETURN_FORBIDDEN;
- }
- $cachefile = $this->appdir . './uc_client/data/cache/settings.php';
- $fp = fopen($cachefile, 'w');
- $s = "<?php\r\n";
- $s .= '$_CACHE[\'settings\'] = ' . var_export($this->post, TRUE) . ";\r\n";
- fwrite($fp, $s);
- fclose($fp);
- return API_RETURN_SUCCEED;
- }
- /**
- * 更新积分
- */
- function updatecredit()
- {
- if (!API_UPDATECREDIT)
- {
- return API_RETURN_FORBIDDEN;
- }
- $credit = $this->get['credit'];
- $amount = $this->get['amount'];
- $uid = $this->get['uid'];
- return API_RETURN_SUCCEED;
- }
- /**
- * 获取积分
- */
- function getcredit()
- {
- if (!API_GETCREDIT)
- {
- return API_RETURN_FORBIDDEN;
- }
- }
- /**
- * 获取积分配置
- */
- function getcreditsettings()
- {
- if (!API_GETCREDITSETTINGS)
- {
- return API_RETURN_FORBIDDEN;
- }
- $credits = [
- '1' => array('威望', ''),
- '2' => array('金钱', '枚'),
- ];
- return $this->_serialize($credits);
- }
- /**
- * 更新积分配置
- */
- function updatecreditsettings()
- {
- if (!API_UPDATECREDITSETTINGS)
- {
- return API_RETURN_FORBIDDEN;
- }
- return API_RETURN_SUCCEED;
- }
- }
|