1
0

LoginHandle.php 906 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace common\logic;
  3. use components\Curl;
  4. use components\Exception;
  5. /**
  6. * 登陆
  7. * Class LoginHandle
  8. * @package common\logic
  9. */
  10. class LoginHandle
  11. {
  12. const URL = 'https://zpapi.licai.cn';
  13. /**
  14. * login
  15. * @author: libingke
  16. * @param $body
  17. * @return array
  18. */
  19. public function login($body)
  20. {
  21. $post = json_decode($body, true);
  22. if (!is_array($post))
  23. throw new Exception(1304, '消息格式错误');
  24. $post['redirect_uri'] = 'https://zpapi.licai.cn';
  25. $curl = new Curl();
  26. $curl->setPostParams($post);
  27. $result = json_decode($curl->post(static::URL), true);
  28. if ($curl->responseCode != 200)
  29. throw new Exception($curl->responseCode);
  30. if ($curl->errorText)
  31. throw new Exception(1304, $curl->errorText);
  32. if (isset($result['error']) && is_string($result['error']))
  33. throw new Exception(1304, $result['error']);
  34. $json = json_encode($result);
  35. return $json;
  36. }
  37. }