apiAction.php 2.1 KB

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