| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- /**
- * 接口文件
- * createname:雨中磐石
- * homeurl:http://www.rockoa.com/
- * Copyright (c) 2016 rainrock (www.rockoa.com)
- * Date:2016-01-01
- * explain:返回200为正常
- */
- //设置允许跨域,用于最新版本APP
- $origin = getheader('Origin');
- if(!isempt($origin) && !contain($origin, HOST)){
- header('Access-Control-Allow-Origin:*');
- header('Access-Control-Allow-Headers:X-Requested-With');
- header('Access-Control-Allow-Credentials:true');
- if(arrvalue($_SERVER,'REQUEST_METHOD')=='OPTIONS'){
- showreturn('ok');
- }
- }
- class apiAction extends ActionNot
- {
- public $userrs = array();
- public $cfrom = '';
- public $token = '';
-
- public function initAction()
- {
- $this->display= false;
- $time = time();
- $this->cfrom= $this->request('cfrom');
- $this->token= $this->request('token', $this->admintoken);
- $nadminid = $this->adminid;
- $this->adminid = (int)$this->request('adminid', $nadminid);
- $this->adminname = '';
- $boss = (M == 'login|api');
- if(!$boss){
- if(isempt($this->token))$this->showreturn('','token invalid', 199);
- $lodb = m('login');
- $onto = $lodb->getone("`uid`='$this->adminid' and `token`='$this->token' and `online`=1");
- if(!$onto)$this->showreturn('','登录失效,请重新登录', 199);
- $lodb->update("`moddt`='{$this->rock->now}'", $onto['id']);
- }
- $this->userrs = m('admin')->getone("`id`='$this->adminid' and `status`=1", '`name`,`user`,`id`,`ranking`,`deptname`,`deptid`');
- if(!$this->userrs && !$boss){
- $this->showreturn('', '用户已经不存在了,请重新登录', 199);
- }
- $this->adminname = arrvalue($this->userrs, 'name');
- $this->rock->adminid = $this->adminid;
- $this->rock->adminname = $this->adminname;
- $this->admintoken = $this->token;
- if(!$boss && $nadminid != $this->adminid)m('login')->setsession($this->adminid, $this->adminname, $this->token, $this->userrs['user']);
- }
-
- public function getvals($nae, $dev='')
- {
- $sv = $this->rock->jm->base64decode($this->post($nae));
- if($this->isempt($sv))$sv=$dev;
- return $sv;
- }
-
- public function getpostdata()
- {
- $postdata = '';
- if(isset($GLOBALS['HTTP_RAW_POST_DATA']))$postdata = $GLOBALS['HTTP_RAW_POST_DATA'];
- if($postdata=='')$postdata = trim(file_get_contents('php://input'));
- return $postdata;
- }
- }
|