1
0

apiAction.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 initAction()
  26. {
  27. $this->display= false;
  28. $time = time();
  29. $this->cfrom= $this->request('cfrom');
  30. $this->token= $this->request('token', $this->admintoken);
  31. $nadminid = $this->adminid;
  32. $this->adminid = (int)$this->request('adminid', $nadminid);
  33. $this->adminname = '';
  34. $boss = (M == 'login|api');
  35. if(!$boss){
  36. if(isempt($this->token))$this->showreturn('','token invalid', 199);
  37. $lodb = m('login');
  38. $onto = $lodb->getone("`uid`='$this->adminid' and `token`='$this->token' and `online`=1");
  39. if(!$onto)$this->showreturn('','登录失效,请重新登录', 199);
  40. $lodb->update("`moddt`='{$this->rock->now}'", $onto['id']);
  41. }
  42. $this->userrs = m('admin')->getone("`id`='$this->adminid' and `status`=1", '`name`,`user`,`id`,`ranking`,`deptname`,`deptid`');
  43. if(!$this->userrs && !$boss){
  44. $this->showreturn('', '用户已经不存在了,请重新登录', 199);
  45. }
  46. $this->adminname = arrvalue($this->userrs, 'name');
  47. $this->rock->adminid = $this->adminid;
  48. $this->rock->adminname = $this->adminname;
  49. $this->admintoken = $this->token;
  50. if(!$boss && $nadminid != $this->adminid)m('login')->setsession($this->adminid, $this->adminname, $this->token, $this->userrs['user']);
  51. }
  52. public function getvals($nae, $dev='')
  53. {
  54. $sv = $this->rock->jm->base64decode($this->post($nae));
  55. if($this->isempt($sv))$sv=$dev;
  56. return $sv;
  57. }
  58. public function getpostdata()
  59. {
  60. $postdata = '';
  61. if(isset($GLOBALS['HTTP_RAW_POST_DATA']))$postdata = $GLOBALS['HTTP_RAW_POST_DATA'];
  62. if($postdata=='')$postdata = trim(file_get_contents('php://input'));
  63. return $postdata;
  64. }
  65. }
粤ICP备19079148号