Common.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\model\Area;
  4. use app\common\controller\Api;
  5. use app\common\library\Ip;
  6. use fast\Version;
  7. use think\Config;
  8. /**
  9. * 公共接口
  10. */
  11. class Common extends Api
  12. {
  13. protected $noNeedLogin = '*';
  14. protected $noNeedRight = '*';
  15. public function _initialize()
  16. {
  17. parent::_initialize();
  18. }
  19. /**
  20. * 加载初始化
  21. *
  22. * 必选参数:version<br>
  23. * 可选参数:lng,lat
  24. */
  25. public function init()
  26. {
  27. if ($version = $this->request->request('version'))
  28. {
  29. $lng = $this->request->request('lng');
  30. $lat = $this->request->request('lat');
  31. $content = [
  32. 'citydata' => Area::getCityFromLngLat($lng, $lat),
  33. 'versiondata' => Version::check($version),
  34. 'uploaddata' => Config::get('upload'),
  35. 'coverdata' => Config::get("cover"),
  36. ];
  37. $this->success('', $content);
  38. }
  39. else
  40. {
  41. $this->error(__('Invalid parameters'));
  42. }
  43. }
  44. /**
  45. * 获取IP及地域信息
  46. */
  47. public function ip()
  48. {
  49. $format = $this->request->param('format', 'json');
  50. if ($format == 'json') {
  51. $this->success('', ['ip' => Ip::ip(), 'city' => Ip::city(), 'province' => Ip::province(), 'country' => Ip::country(), 'info'=>Ip::str()]);
  52. }
  53. }
  54. }