openapiAction.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. class openapiAction extends ActionNot
  12. {
  13. private $openkey = '';
  14. public $postdata= '';
  15. //是否验证openkey
  16. protected $keycheck= true;
  17. public function initAction()
  18. {
  19. $this->display= false;
  20. $openkey = $this->post('openkey');
  21. $this->openkey = getconfig('openkey');
  22. if($this->keycheck && $this->openkey != ''){
  23. if($openkey != md5($this->openkey))$this->showreturn('', 'openkey not access', 201);
  24. }
  25. $this->getpostdata();
  26. }
  27. public function getpostdata()
  28. {
  29. if(isset($GLOBALS['HTTP_RAW_POST_DATA']))$this->postdata = $GLOBALS['HTTP_RAW_POST_DATA'];
  30. if($this->postdata=='')$this->postdata = trim(file_get_contents('php://input'));
  31. }
  32. public function getvals($nae, $dev='')
  33. {
  34. $sv = $this->rock->jm->base64decode($this->post($nae));
  35. if($this->isempt($sv))$sv=$dev;
  36. return $sv;
  37. }
  38. /**
  39. * 获取提交的数据
  40. */
  41. public function getpostarr()
  42. {
  43. $str = $this->postdata;
  44. if(isempt($str))return false;
  45. $arr = json_decode($str, true);
  46. return $arr;
  47. }
  48. /**
  49. * 根据关键字获取用户
  50. */
  51. public function getuserid($id, $sur=true)
  52. {
  53. if(isempt($id))return 0;
  54. $where = "`user`='$id'";
  55. $check = c('check');
  56. if($check->iscnmobile($id)){
  57. $where = "`mobile`='$id'";
  58. }elseif($check->isemail($id)){
  59. $where = "`email`='$id'";
  60. }elseif($check->isincn($id)){
  61. $where = "`name`='$id'";
  62. }elseif($check->isnumber($id)){
  63. $where = "`id`='$id'";
  64. }
  65. $urs = $this->db->getall("select `id`,`name` from `[Q]admin` where $where and `status`=1");
  66. if($this->db->count!=1)return 0;
  67. $urs = $urs[0];
  68. $uid = (int)$urs['id'];
  69. if($sur){
  70. $this->adminid = $uid;
  71. $this->adminname = $urs['name'];
  72. $this->rock->adminid = $uid; //用户Id
  73. $this->rock->adminname = $urs['name'];
  74. }
  75. return $uid;
  76. }
  77. }
粤ICP备19079148号