Haoxiaoyun.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace call;
  3. class Haoxiaoyun
  4. {
  5. protected $domain = 'https://www.ixiaoguanjia.cn';
  6. /**
  7. * 登陆接口
  8. */
  9. public function login($phone)
  10. {
  11. $url = '/api/login/login';
  12. $param = [
  13. 'account' => $phone,
  14. 'password' => $phone
  15. ];
  16. $headers = array(
  17. 'accept: application/json',
  18. 'Content-Type: multipart/form-data'
  19. );
  20. $rs = $this->curl($url, $param, $headers);
  21. return json_decode($rs, true);
  22. }
  23. public function bind($caller, $callee, $type = 1)
  24. {
  25. $login = $this->login($caller);
  26. if ($login['code'] != 1) return $login;
  27. $url = '/api/call/callBind';
  28. $param = [
  29. 'type' => $type,
  30. 'callee' => $callee
  31. ];
  32. $headers = array(
  33. 'accept: application/json',
  34. 'token: ' . $login['data']['user']['token'],
  35. 'apptype: android',
  36. 'appcode: 100',
  37. 'Content-Type: multipart/form-data'
  38. );
  39. $rs = $this->curl($url, $param, $headers);
  40. return json_decode($rs, true);
  41. }
  42. /**
  43. * curl请求
  44. *
  45. * @param String $url
  46. * @param Array $param
  47. * @return String
  48. */
  49. public function curl($url, $param, $header)
  50. {
  51. $curl = curl_init();
  52. curl_setopt_array($curl, array(
  53. CURLOPT_URL => $this->domain . $url,
  54. CURLOPT_RETURNTRANSFER => true,
  55. CURLOPT_ENCODING => "UTF-8",
  56. CURLOPT_MAXREDIRS => 10,
  57. CURLOPT_TIMEOUT => 30,
  58. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  59. CURLOPT_CUSTOMREQUEST => "POST",
  60. CURLOPT_POSTFIELDS => $param,
  61. CURLOPT_HTTPHEADER => $header,
  62. ));
  63. $response = curl_exec($curl);
  64. // $err = curl_error($curl);
  65. curl_close($curl);
  66. // if ($err) {
  67. // echo "cURL Error #:" . $err;
  68. // } else {
  69. // echo $response;
  70. // }
  71. return $response;
  72. }
  73. }