Ucenter.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <?php
  2. namespace app\index\controller;
  3. use app\common\controller\Uc;
  4. use app\common\model\User;
  5. use app\common\model\UserThird;
  6. use fast\Random;
  7. use think\Loader;
  8. /**
  9. * Ucenter接口,接收来自Ucenter服务器的请求
  10. *
  11. */
  12. class Ucenter extends Uc
  13. {
  14. public function _initialize()
  15. {
  16. //导入UC常量
  17. Loader::import('uc', APP_PATH);
  18. parent::_initialize();
  19. }
  20. /**
  21. * Ucenter接口接收方法
  22. */
  23. public function api()
  24. {
  25. $this->response();
  26. return;
  27. }
  28. public function index()
  29. {
  30. $this->redirect('/');
  31. return;
  32. }
  33. /**
  34. * 删除用户
  35. */
  36. function deleteuser()
  37. {
  38. $uids = $this->get['ids'];
  39. $uids = is_array($uids) ? $uids : explode(',', $uids);
  40. !API_DELETEUSER && exit(API_RETURN_FORBIDDEN);
  41. User::destroy($uids);
  42. UserThird::destroy($uids);
  43. $result = TRUE;
  44. return $result ? API_RETURN_SUCCEED : API_RETURN_FAILED;
  45. }
  46. /**
  47. * 获取标签
  48. */
  49. function gettag()
  50. {
  51. $name = $this->get['id'];
  52. if (!API_GETTAG)
  53. {
  54. return API_RETURN_FORBIDDEN;
  55. }
  56. $datalist = [];
  57. if ($name == 'get_recently_list')
  58. {
  59. for ($i = 0; $i < 9; $i++)
  60. {
  61. $datalist[] = array(
  62. 'name' => 'name' . $i,
  63. 'uid' => 1,
  64. 'username' => 'username' . $i,
  65. 'dateline' => '2021',
  66. 'url' => 'http://www.yourwebsite.com/thread.php?id=',
  67. 'image' => 'http://www.yourwebsite.com/threadimage.php?id=',
  68. );
  69. }
  70. }
  71. return $this->_serialize([$name, $datalist], 1);
  72. }
  73. /**
  74. * 同步注册
  75. */
  76. function synregister()
  77. {
  78. $uid = $this->get['uid'];
  79. $username = $this->get['username'];
  80. $password = $this->get['password'];
  81. $email = isset($this->get['email']) ? $this->get['email'] : '';
  82. $mobile = isset($this->get['mobile']) ? $this->get['mobile'] : '';
  83. if (!API_SYNLOGIN)
  84. {
  85. return API_RETURN_FORBIDDEN;
  86. }
  87. // 同步注册接口
  88. header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
  89. $this->user->register($username, $password, $email, $mobile, [], 0, FALSE);
  90. echo 'signup ok';
  91. }
  92. /**
  93. * 同步登录
  94. */
  95. function synlogin()
  96. {
  97. $uid = $this->get['uid'];
  98. $username = $this->get['username'];
  99. if (!API_SYNLOGIN)
  100. {
  101. return API_RETURN_FORBIDDEN;
  102. }
  103. // 同步登录接口
  104. header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
  105. $this->user->direct($uid, FALSE);
  106. echo 'login ok';
  107. }
  108. /**
  109. * 同步退出
  110. */
  111. function synlogout()
  112. {
  113. if (!API_SYNLOGOUT)
  114. {
  115. return API_RETURN_FORBIDDEN;
  116. }
  117. //同步登出接口
  118. header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
  119. $this->user->logout();
  120. echo 'logout ok';
  121. }
  122. /**
  123. * 添加用户
  124. */
  125. function adduser()
  126. {
  127. $uid = $this->get['uid'];
  128. $username = $this->get['username'];
  129. $password = $this->get['password'];
  130. $email = isset($this->get['email']) ? $this->get['email'] : '';
  131. $mobile = isset($this->get['mobile']) ? $this->get['mobile'] : '';
  132. if (!API_ADDUSER)
  133. {
  134. return API_RETURN_FORBIDDEN;
  135. }
  136. $time = time();
  137. $salt = Random::alnum();
  138. $password = $this->user->getEncryptPassword($password, $salt);
  139. $ip = $this->request->ip();
  140. $userarr = [
  141. 'id' => $uid,
  142. 'username' => $username,
  143. 'password' => $password,
  144. 'salt' => $salt,
  145. 'email' => $email,
  146. 'mobile' => $mobile,
  147. 'jointime' => $time,
  148. 'joinip' => $ip
  149. ];
  150. User::save($userarr);
  151. return API_RETURN_SUCCEED;
  152. }
  153. /**
  154. * 更新用户信息,包含用户名,密码,邮箱,手机号和其它扩展信息
  155. */
  156. function updateinfo()
  157. {
  158. if (!API_UPDATEINFO)
  159. {
  160. return API_RETURN_FORBIDDEN;
  161. }
  162. $uid = isset($this->get['uid']) ? $this->get['uid'] : 0;
  163. $username = isset($this->get['username']) ? $this->get['username'] : '';
  164. $password = isset($this->get['password']) ? $this->get['password'] : '';
  165. $email = isset($this->get['email']) ? $this->get['email'] : '';
  166. $mobile = isset($this->get['mobile']) ? $this->get['mobile'] : '';
  167. print_r($this->get);
  168. $userinfo = User::get($uid);
  169. if (!$userinfo)
  170. {
  171. return API_RETURN_FAILED;
  172. }
  173. $values = [];
  174. if ($username)
  175. {
  176. $values['username'] = $username;
  177. }
  178. if ($password)
  179. {
  180. $salt = Random::alnum();
  181. $password = $this->user->getEncryptPassword($password, $salt);
  182. $values['password'] = $password;
  183. $values['salt'] = $salt;
  184. }
  185. if ($email)
  186. {
  187. $values['email'] = $email;
  188. }
  189. if ($mobile)
  190. {
  191. $values['mobile'] = $mobile;
  192. }
  193. $userinfo->save($values);
  194. return API_RETURN_SUCCEED;
  195. }
  196. /**
  197. * 更新禁言文字
  198. */
  199. function updatebadwords()
  200. {
  201. if (!API_UPDATEBADWORDS)
  202. {
  203. return API_RETURN_FORBIDDEN;
  204. }
  205. $cachefile = $this->appdir . './uc_client/data/cache/badwords.php';
  206. $fp = fopen($cachefile, 'w');
  207. $data = array();
  208. if (is_array($this->post))
  209. {
  210. foreach ($this->post as $k => $v)
  211. {
  212. $data['findpattern'][$k] = $v['findpattern'];
  213. $data['replace'][$k] = $v['replacement'];
  214. }
  215. }
  216. $s = "<?php\r\n";
  217. $s .= '$_CACHE[\'badwords\'] = ' . var_export($data, TRUE) . ";\r\n";
  218. fwrite($fp, $s);
  219. fclose($fp);
  220. return API_RETURN_SUCCEED;
  221. }
  222. /**
  223. * 更新HOSTS
  224. */
  225. function updatehosts()
  226. {
  227. if (!API_UPDATEHOSTS)
  228. {
  229. return API_RETURN_FORBIDDEN;
  230. }
  231. $cachefile = $this->appdir . './uc_client/data/cache/hosts.php';
  232. $fp = fopen($cachefile, 'w');
  233. $s = "<?php\r\n";
  234. $s .= '$_CACHE[\'hosts\'] = ' . var_export($this->post, TRUE) . ";\r\n";
  235. fwrite($fp, $s);
  236. fclose($fp);
  237. return API_RETURN_SUCCEED;
  238. }
  239. /**
  240. * 更新App信息
  241. */
  242. function updateapps()
  243. {
  244. if (!API_UPDATEAPPS)
  245. {
  246. return API_RETURN_FORBIDDEN;
  247. }
  248. $UC_API = $this->post['UC_API'];
  249. //note 写 app 缓存文件
  250. $cachefile = $this->appdir . './uc_client/data/cache/apps.php';
  251. $fp = fopen($cachefile, 'w');
  252. $s = "<?php\r\n";
  253. $s .= '$_CACHE[\'apps\'] = ' . var_export($this->post, TRUE) . ";\r\n";
  254. fwrite($fp, $s);
  255. fclose($fp);
  256. //note 写配置文件
  257. if (is_writeable($this->appdir . './config.inc.php'))
  258. {
  259. $configfile = trim(file_get_contents($this->appdir . './config.inc.php'));
  260. $configfile = substr($configfile, -2) == '?>' ? substr($configfile, 0, -2) : $configfile;
  261. $configfile = preg_replace("/define\('UC_API',\s*'.*?'\);/i", "define('UC_API', '$UC_API');", $configfile);
  262. if ($fp = @fopen($this->appdir . './config.inc.php', 'w'))
  263. {
  264. @fwrite($fp, trim($configfile));
  265. @fclose($fp);
  266. }
  267. }
  268. return API_RETURN_SUCCEED;
  269. }
  270. /**
  271. * 更新客户端配置文件
  272. */
  273. function updateclient()
  274. {
  275. if (!API_UPDATECLIENT)
  276. {
  277. return API_RETURN_FORBIDDEN;
  278. }
  279. $cachefile = $this->appdir . './uc_client/data/cache/settings.php';
  280. $fp = fopen($cachefile, 'w');
  281. $s = "<?php\r\n";
  282. $s .= '$_CACHE[\'settings\'] = ' . var_export($this->post, TRUE) . ";\r\n";
  283. fwrite($fp, $s);
  284. fclose($fp);
  285. return API_RETURN_SUCCEED;
  286. }
  287. /**
  288. * 更新积分
  289. */
  290. function updatecredit()
  291. {
  292. if (!API_UPDATECREDIT)
  293. {
  294. return API_RETURN_FORBIDDEN;
  295. }
  296. $credit = $this->get['credit'];
  297. $amount = $this->get['amount'];
  298. $uid = $this->get['uid'];
  299. return API_RETURN_SUCCEED;
  300. }
  301. /**
  302. * 获取积分
  303. */
  304. function getcredit()
  305. {
  306. if (!API_GETCREDIT)
  307. {
  308. return API_RETURN_FORBIDDEN;
  309. }
  310. }
  311. /**
  312. * 获取积分配置
  313. */
  314. function getcreditsettings()
  315. {
  316. if (!API_GETCREDITSETTINGS)
  317. {
  318. return API_RETURN_FORBIDDEN;
  319. }
  320. $credits = [
  321. '1' => array('威望', ''),
  322. '2' => array('金钱', '枚'),
  323. ];
  324. return $this->_serialize($credits);
  325. }
  326. /**
  327. * 更新积分配置
  328. */
  329. function updatecreditsettings()
  330. {
  331. if (!API_UPDATECREDITSETTINGS)
  332. {
  333. return API_RETURN_FORBIDDEN;
  334. }
  335. return API_RETURN_SUCCEED;
  336. }
  337. }