openapiAction.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * 对外开发接口文件
  4. * createname:信呼
  5. * homeurl:http://www.rockoa.com/
  6. * Copyright (c) 2016 rainrock (www.rockoa.com)
  7. * Date:2016-11-01
  8. * explain:返回200为正常
  9. * post需开启:always_populate_raw_post_data = On
  10. */
  11. header('Access-Control-Allow-Origin:*'); //允许的请求头信息
  12. header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization"); //允许的请求类型
  13. header('Access-Control-Allow-Methods: GET, POST, PUT,DELETE,OPTIONS,PATCH'); //允许携带证书式访问(携带cookie)
  14. header('Access-Control-Allow-Credentials:true');
  15. class openapiAction extends ActionNot
  16. {
  17. private $openkey = '';
  18. public $postdata= '';
  19. //是否验证openkey
  20. protected $keycheck= true;
  21. public function initAction()
  22. {
  23. $this->display= false;
  24. $openkey = $this->post('openkey');
  25. $this->openkey = getconfig('openkey');
  26. if($this->keycheck && HOST != '127.0.0.1' && !contain(HOST,'192.168') && $this->openkey != ''){
  27. if($openkey != md5($this->openkey))$this->showreturn('', 'openkey not access', 201);
  28. }
  29. $this->getpostdata();
  30. }
  31. public function getpostdata()
  32. {
  33. if(isset($GLOBALS['HTTP_RAW_POST_DATA']))$this->postdata = $GLOBALS['HTTP_RAW_POST_DATA'];
  34. if($this->postdata=='')$this->postdata = trim(file_get_contents('php://input'));
  35. }
  36. public function getvals($nae, $dev='')
  37. {
  38. $sv = $this->rock->jm->base64decode($this->post($nae));
  39. if($this->isempt($sv))$sv=$dev;
  40. return $sv;
  41. }
  42. /**
  43. * 获取提交的数据
  44. */
  45. public function getpostarr()
  46. {
  47. $str = $this->postdata;
  48. if(isempt($str))return false;
  49. $arr = json_decode($str, true);
  50. return $arr;
  51. }
  52. /**
  53. * 根据关键字获取用户
  54. */
  55. public function getuserid($id, $sur=true)
  56. {
  57. if(isempt($id))return 0;
  58. $where = "`user`='$id'";
  59. $check = c('check');
  60. if($check->iscnmobile($id)){
  61. $where = "`mobile`='$id'";
  62. }elseif($check->isemail($id)){
  63. $where = "`email`='$id'";
  64. }elseif($check->isincn($id)){
  65. $where = "`name`='$id'";
  66. }elseif($check->isnumber($id)){
  67. $where = "`id`='$id'";
  68. }
  69. $urs = $this->db->getall("select `id`,`name` from `[Q]admin` where $where and `status`=1");
  70. if($this->db->count!=1)return 0;
  71. $urs = $urs[0];
  72. $uid = (int)$urs['id'];
  73. if($sur){
  74. $this->adminid = $uid;
  75. $this->adminname = $urs['name'];
  76. $this->rock->adminid = $uid; //用户Id
  77. $this->rock->adminname = $urs['name'];
  78. }
  79. return $uid;
  80. }
  81. }