apiAction.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * 接口文件
  4. * createname:雨中磐石
  5. * homeurl:http://www.rockoa.com/
  6. * Copyright (c) 2016 rainrock (www.rockoa.com)
  7. * Date:2016-01-01
  8. * explain:返回200为正常
  9. */
  10. //设置允许跨域,用于最新版本APP
  11. $origin = getheader('Origin');
  12. if(!isempt($origin) && !contain($origin, HOST)){
  13. header('Access-Control-Allow-Origin:*');
  14. header('Access-Control-Allow-Headers:X-Requested-With');
  15. header('Access-Control-Allow-Credentials:true');
  16. if(arrvalue($_SERVER,'REQUEST_METHOD')=='OPTIONS'){
  17. showreturn('ok');
  18. }
  19. }
  20. class apiAction extends ActionNot
  21. {
  22. public $userrs = array();
  23. public $cfrom = '';
  24. public $token = '';
  25. public function initApiCheck(){return false;}
  26. public function initAction()
  27. {
  28. $this->display= false;
  29. $time = time();
  30. $this->cfrom= $this->request('cfrom');
  31. $this->token= $this->request('token', $this->admintoken);
  32. $nadminid = $this->adminid;
  33. $this->adminid = (int)$this->request('adminid', $nadminid);
  34. $this->adminname = '';
  35. $boss = (M == 'login|api'); //true就是不需要验证登录
  36. $bossv= $this->initApiCheck();
  37. if($bossv)$boss = true;
  38. if(!$boss){
  39. if(isempt($this->token))$this->showreturn('','token invalid', 199);
  40. $lodb = m('login');
  41. $onto = $lodb->getone("`uid`='$this->adminid' and `token`='$this->token' and `online`=1");
  42. if(!$onto)$this->showreturn('','登录失效,请重新登录', 199);
  43. $lodb->update("`moddt`='{$this->rock->now}'", $onto['id']);
  44. }
  45. if(!$boss){
  46. $this->userrs = m('admin')->getone("`id`='$this->adminid' and `status`=1", '`name`,`user`,`id`,`ranking`,`deptname`,`deptid`');
  47. if(!$this->userrs){
  48. $this->showreturn('', '用户已经不存在了,请重新登录', 199);
  49. }
  50. }
  51. $this->adminname = arrvalue($this->userrs, 'name');
  52. $this->rock->adminid = $this->adminid;
  53. $this->rock->adminname = $this->adminname;
  54. $this->admintoken = $this->token;
  55. if(!$boss && $nadminid != $this->adminid)m('login')->setsession($this->adminid, $this->adminname, $this->token, $this->userrs['user']);
  56. }
  57. public function getvals($nae, $dev='')
  58. {
  59. $sv = $this->rock->jm->base64decode($this->post($nae));
  60. if($this->isempt($sv))$sv=$dev;
  61. return $sv;
  62. }
  63. public function getpostdata()
  64. {
  65. $postdata = '';
  66. if(isset($GLOBALS['HTTP_RAW_POST_DATA']))$postdata = $GLOBALS['HTTP_RAW_POST_DATA'];
  67. if($postdata=='')$postdata = trim(file_get_contents('php://input'));
  68. return $postdata;
  69. }
  70. }
粤ICP备19079148号