LivevideoModel.class.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Home\Model;
  3. use Think\Model;
  4. /**
  5. * 拼团模型模型
  6. * @author fish
  7. *
  8. */
  9. class LivevideoModel {
  10. function get_wx_roomInfo($access_token, $page=1)
  11. {
  12. if(!$access_token) {
  13. return '';
  14. die();
  15. }
  16. $start = 50*($page-1);
  17. $url = 'http://api.weixin.qq.com/wxa/business/getliveinfo?access_token='.$access_token;
  18. $param = array(
  19. "start" => $start,
  20. "limit" => 50
  21. );
  22. $res = $this->_post($url, $param);
  23. $res = json_decode($res);
  24. if($res->errcode == 0) {
  25. $res->page = $page;
  26. $res->expire_time = time();
  27. return $res;
  28. } else if($res->errcode == 1) {
  29. // 代表未创建直播房间
  30. return "";
  31. }
  32. }
  33. private function _post($url, $data=array()) {
  34. //初使化init方法
  35. $ch = curl_init();
  36. //指定URL
  37. curl_setopt($ch, CURLOPT_URL, $url);
  38. //设定请求后返回结果
  39. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  40. //声明使用POST方式来进行发送
  41. curl_setopt($ch, CURLOPT_POST, 1);
  42. //发送什么数据呢
  43. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  44. //忽略证书
  45. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  46. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  47. //忽略header头信息
  48. curl_setopt($ch, CURLOPT_HEADER, 0);
  49. //设置超时时间
  50. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  51. //发送请求
  52. $output = curl_exec($ch);
  53. //关闭curl
  54. curl_close($ch);
  55. //返回数据
  56. return $output;
  57. }
  58. }