building.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * 建筑接口
  4. *
  5. * User: Ellisran
  6. * Date: 2018/9/27
  7. * Time: 16:23
  8. */
  9. class Building {
  10. private $BuildUrl = 'https://yun.smartcost.com.cn/cld'; // 建筑-cld url接口地址
  11. public function getUsersAndCompilationByID ($id) {
  12. $url = $this->BuildUrl. '/getUsersAndCompilation?ssoID='. $id;
  13. $result = json_decode($this->curl_request($url), true);
  14. if ($result['error'] == 0) {
  15. return $result['data'];
  16. } else {
  17. return '';
  18. }
  19. }
  20. public function getUsersAndCompilationByMobile ($mobile) {
  21. $url = $this->BuildUrl. '/getUsersAndCompilation?mobile='. $mobile;
  22. $result = json_decode($this->curl_request($url), true);
  23. if ($result['error'] == 0) {
  24. return $result['data'];
  25. } else {
  26. return '';
  27. }
  28. }
  29. public function setUserCompilation($ssoId, $compilationId) {
  30. $url = $this->BuildUrl. '/setUserUpgrade';
  31. $data = array('ssoId' => $ssoId, 'cid' => $compilationId);
  32. $result = json_decode($this->curl_request($url, $data), true);
  33. if ($result['error'] == 0) {
  34. return true;
  35. } else {
  36. return false;
  37. }
  38. }
  39. /**
  40. * curl 获取接口数据,data为空时为GET方法,有值则为POST方法
  41. *
  42. * @param $url
  43. * @param string $data
  44. * @return mixed|string
  45. */
  46. private function curl_request($url, $data = '') {
  47. $curl = curl_init();
  48. curl_setopt($curl, CURLOPT_URL, $url);
  49. curl_setopt($curl, CURLOPT_HEADER, 0);
  50. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  51. if($data) {
  52. curl_setopt($curl, CURLOPT_POST, 1);
  53. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
  54. }
  55. curl_setopt($curl, CURLOPT_TIMEOUT, 10);
  56. $data = curl_exec($curl);
  57. curl_close($curl);
  58. return $data;
  59. }
  60. }