OaController.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace api\oa\controller;
  3. use think\Controller;
  4. class OaController extends Controller {
  5. protected $param;
  6. protected $oa_class;
  7. protected function _initialize() {
  8. $this->param = $this->request->param();
  9. $_Arr = $this->request->param();
  10. \think\Log::write($_Arr, 'error');
  11. $this->oa_class = new \huolib\oa\Oa();
  12. $this->checkParam();
  13. }
  14. public function hs_api_json($code = 200, $msg = '', $data = array()) {
  15. $this->oa_class->hs_api_json($code, $msg, $data);
  16. }
  17. /**
  18. * 校验参数 仅做合法性验证
  19. *
  20. * @return bool
  21. */
  22. protected function checkParam() {
  23. $this->checkPlatId();
  24. $this->checkSign();
  25. $this->checkSignType();
  26. // $this->checkTimestamp();
  27. }
  28. /** 验证平台id
  29. *
  30. * @return $this|bool
  31. */
  32. public function checkPlatId() {
  33. if (!isset($this->param['plat_id']) || empty($this->param['plat_id'])) {
  34. return $this->oa_class->hs_api_responce('408', '平台id错误');
  35. }
  36. if ($this->oa_class->getPlatId() != $this->param['plat_id']
  37. ) {
  38. return $this->oa_class->hs_api_responce('408', '平台id错误!');
  39. }
  40. return true;
  41. }
  42. /**
  43. * 验签
  44. *
  45. * @return $this|bool
  46. */
  47. public function checkSign() {
  48. return $this->oa_class->checkSign($this->param);
  49. }
  50. /**
  51. * 验证加密方式
  52. *
  53. * @return $this|bool
  54. */
  55. public function checkSignType() {
  56. if (!isset($this->param['sign_type']) || empty($this->param['sign_type'])) {
  57. return $this->oa_class->hs_api_responce('403', '签名方式错误');
  58. }
  59. if ($this->oa_class->getSignType() == $this->param['sign_type']) {
  60. return true;
  61. }
  62. }
  63. /**
  64. * 时间簇验证
  65. *
  66. * @return $this|bool
  67. */
  68. public function checkTimestamp() {
  69. if (!isset($this->param['timestamp']) || empty($this->param['timestamp'])) {
  70. return $this->oa_class->hs_api_responce('402', '请求时间错误');
  71. }
  72. if ($this->param['timestamp'] + 10 < time()) {
  73. return $this->oa_class->hs_api_responce('402', '请求时间超时');
  74. }
  75. return true;
  76. }
  77. }