Base.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace addons\cms\controller\wxapp;
  3. use addons\cms\library\IntCode;
  4. use app\common\controller\Api;
  5. use app\common\library\Auth;
  6. use think\Config;
  7. use think\Lang;
  8. class Base extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. //设置返回的会员字段
  13. protected $allowFields = ['id', 'username', 'nickname', 'mobile', 'avatar', 'score', 'vip', 'level', 'bio', 'balance', 'money'];
  14. public function _initialize()
  15. {
  16. parent::_initialize();
  17. Config::set('default_return_type', 'json');
  18. $config = get_addon_config('cms');
  19. Auth::instance()->setAllowFields($this->allowFields);
  20. //判断站点状态
  21. if (isset($config['openedsite']) && !in_array('wxapp', explode(',', $config['openedsite']))) {
  22. $this->error('站点已关闭');
  23. }
  24. //这里手动载入语言包
  25. Lang::load(ROOT_PATH . '/addons/cms/lang/zh-cn.php');
  26. Lang::load(APP_PATH . '/index/lang/zh-cn/user.php');
  27. }
  28. /**
  29. * 判断ID是否加密处理
  30. */
  31. protected function hashids($name = 'id')
  32. {
  33. $config = get_addon_config('cms');
  34. $getValue = $this->request->get($name);
  35. $postValue = $this->request->post($name);
  36. if ($config['archiveshashids'] && ($getValue || $postValue)) {
  37. if ($getValue) {
  38. $getValue = (int)IntCode::decode($getValue);
  39. $this->request->get([$name => $getValue]);
  40. }
  41. if ($postValue) {
  42. $postValue = (int)IntCode::decode($postValue);
  43. $this->request->post([$name => $postValue]);
  44. }
  45. $this->request->param('');
  46. }
  47. }
  48. }