BuildingApiController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * 建筑接口控制器
  4. *
  5. * @author EllisRan
  6. */
  7. class BuildingApiController extends DooController {
  8. public $staff;
  9. public $authApp = 'scConstruct';
  10. public $authToken = 'sc@ConS!tru@ct*88';
  11. function __construct() {
  12. }
  13. public function categoryStaff() {
  14. Doo::loadModel('staff');
  15. $staff = new staff();
  16. $stafflist = $staff->getStaffByCidOnBuilding($this->params['cid']);
  17. echo json_encode($stafflist);
  18. exit;
  19. }
  20. /**
  21. * 员工列表
  22. */
  23. public function StaffList() {
  24. Doo::loadModel('staff');
  25. $staff = new staff();
  26. $staffList = $staff->find(array('select' => 'sid,username,nature,cid,departmentID,category,qq,phone,telephone', 'where' => 'sid!=1 and nature!=4', 'asArray' => TRUE));
  27. Doo::loadModel('department');
  28. $department = new department();
  29. foreach($staffList as $k => $v) {
  30. $staffList[$k]['departmentName'] = $v['departmentID'] != 0 ? $department->getDepartmentByDid($v['departmentID'])['departmentName'] : '';
  31. }
  32. echo json_encode($staffList,true);
  33. exit;
  34. }
  35. /**
  36. * 计量支付后台登录
  37. */
  38. public function auth() {
  39. if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['app']) && isset($_POST['time']) && isset($_POST['token'])) {
  40. // 先判断token和time的加密是是否一致,防止被其它接口调用
  41. $token = $this->getSignature($this->authToken.$_POST['time'], $this->authToken);
  42. if ($_POST['app'] == $this->authApp && $_POST['token'] == $token) {
  43. Doo::loadModel('staff');
  44. $staff = new staff();
  45. $staffInfo = $staff->getStaffByName($_POST['username']);
  46. if (!empty($staffInfo) && $staffInfo['passwork'] == md5($_POST['password'])) {
  47. echo json_encode(array('err' => 0, 'data' => array(
  48. 'username' => $staffInfo['username'],
  49. 'office' => $staffInfo['cid'],
  50. 'category' => $staffInfo['category'],
  51. 'email' => $staffInfo['email'],
  52. 'telephone' => $staffInfo['telephone'],
  53. 'qq' => $staffInfo['qq'],
  54. 'fixedphone' => $staffInfo['phone'],
  55. 'position' => $staffInfo['position']
  56. )
  57. ));
  58. exit;
  59. }
  60. }
  61. }
  62. echo json_encode(array('err' => '参数有误'));
  63. exit;
  64. }
  65. // HMAC-SHA1+base64 加密方法
  66. function getSignature($str, $key) {
  67. $signature = "";
  68. if (function_exists('hash_hmac')) {
  69. $signature = base64_encode(hash_hmac("sha1", $str, $key, true));
  70. } else {
  71. $blocksize = 64;
  72. $hashfunc = 'sha1';
  73. if (strlen($key) > $blocksize) {
  74. $key = pack('H*', $hashfunc($key));
  75. }
  76. $key = str_pad($key, $blocksize, chr(0x00));
  77. $ipad = str_repeat(chr(0x36), $blocksize);
  78. $opad = str_repeat(chr(0x5c), $blocksize);
  79. $hmac = pack(
  80. 'H*', $hashfunc(
  81. ($key ^ $opad) . pack(
  82. 'H*', $hashfunc(
  83. ($key ^ $ipad) . $str
  84. )
  85. )
  86. )
  87. );
  88. $signature = base64_encode($hmac);
  89. }
  90. return $signature;
  91. }
  92. }
  93. ?>