| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- <?php
- namespace app\common\repositories\movie;
- use think\facade\Cache;
- /**
- * 微唯宝电影
- */
- class DouHuoMallFilmApiRequest
- {
- //接口文档:https://docs.qq.com/doc/DWkJQS0h3WENvVmdG?u=a6a6ad6c89714f6394f5fd13fcffc2ac
- private static $path = 'http://wmh5.douhuomall.com';
- private static $app_id = 'YS3a8ab661406e47bb86';
- private static $app_secret = '41d8b8e1dd9a454a1abc4534297e33c3';
- private static $mobile = '17855366921';
- private static $successCode = 200;
- private static $douHuoMallFilmAccessTokenCache = 'DouHuoMallFilmAccessToken';
- /**
- *
- *
- * @return false|mixed
- */
- public static function request_access_token()
- {
- $url = '/openapi/Auth/accessToken';
- $time = date('Y-m-d H:i:s');
- $body = [
- 'app_id' => self::$app_id,
- 'sign' => self::getSign($time),
- 'mobile' => self::$mobile,
- 'datetime' => $time
- ];
- $res = self::curl_post(self::$path . $url, $body);
- if ($res['code'] == self::$successCode) {
- $expire_time = strtotime($res['data']['expire_time']) - 5 - time();
- $expire_time = $expire_time > 0 ? $expire_time : 3600;
- Cache::set(self::$douHuoMallFilmAccessTokenCache, $res['data']['access_token'], $expire_time);// 将取到的token存入redis方便下次使用
- return $res['data']['access_token'];
- }
- return '';
- }
- /**
- * 获取token
- *
- * @return mixed
- */
- public static function get_access_token()
- {
- $access_token = Cache::get(self::$douHuoMallFilmAccessTokenCache);
- return $access_token ?? self::request_access_token();
- }
- /**
- * 获取城市列表
- * @return false|int|mixed
- */
- public static function getMovieCity($page = 1, $limit = 10, $initial = '', $city_name = '')
- {
- $url = '/openapi/Movie/getCity';
- $body = [
- 'access_token' => self::get_access_token(),
- 'page' => $page,
- 'limit' => $limit
- ];
- if (!empty($initial)) $body['initial'] = $initial;
- if (!empty($city_name)) $body['city_name'] = $city_name;
- $res = self::curl_post(self::$path . $url, $body);
- return $res;
- }
- /**
- * 获取城市分区列表
- * @return false|int|mixed
- */
- public static function getMovieArea($city_sign = '')
- {
- $url = '/openapi/Movie/getArea';
- $body = [
- 'access_token' => self::get_access_token(),
- 'city_sign' => $city_sign
- ];
- $res = self::curl_post(self::$path . $url, $body);
- return $res;
- }
- /**
- * 获取影院列表
- * @param $page
- * @param $limit
- * @param $city_sign
- * @param $area_sign
- * @return mixed|string
- */
- public static function getCinema($page = 1, $limit = 10, $city_sign = '', $area_sign = '')
- {
- $url = '/openapi/Movie/getCinema';
- $body = [
- 'access_token' => self::get_access_token(),
- 'page' => $page,
- 'limit' => $limit
- ];
- if (!empty($city_sign)) $body['city_sign'] = $city_sign;
- if (!empty($area_sign)) $body['area_sign'] = $area_sign;
- $res = self::curl_post(self::$path . $url, $body);
- return $res;
- }
- /**
- * 获取影片列表
- * @param $page
- * @param $limit
- * @param $cinema_sign
- * @param $film_sign
- * @return mixed|string
- */
- public static function getFilm($page = 1, $limit = 10, $cinema_sign = '', $film_sign = '')
- {
- $url = '/openapi/Movie/getFilm';
- $body = [
- 'access_token' => self::get_access_token(),
- 'page' => $page,
- 'limit' => $limit
- ];
- if (!empty($cinema_sign)) $body['cinema_sign'] = $cinema_sign;
- if (!empty($film_sign)) $body['film_sign'] = $film_sign;
- $res = self::curl_post(self::$path . $url, $body);
- return $res;
- }
- /**
- * 获取排片影院列表(废弃)
- * @param $page
- * @param $limit
- * @param $cinema_sign
- * @param $film_sign
- * @return mixed|string
- */
- public static function getFilmSched($page = 1, $limit = 10, $film_sign = '', $longitude = '', $latitude = '', $city_sign = '')
- {
- $url = '/openapi/Movie/getFilmSched';
- $body = [
- 'access_token' => self::get_access_token(),
- 'page' => $page,
- 'limit' => $limit,
- 'film_sign' => $film_sign,
- 'longitude' => $longitude,
- 'latitude' => $latitude,
- 'city_sign' => $city_sign
- ];
- $res = self::curl_post(self::$path . $url, $body);
- return $res;
- }
- /**
- * 获取影院场次列表
- *
- * @param $film_sign
- * @param $cinema_sign
- * @return mixed|string
- */
- public static function getCinemaSched($film_sign = '', $cinema_sign = '')
- {
- $url = '/openapi/Movie/getCinemaSched';
- $body = [
- 'access_token' => self::get_access_token(),
- 'film_sign' => $film_sign,
- 'cinema_sign' => $cinema_sign
- ];
- $res = self::curl_post(self::$path . $url, $body);
- return $res;
- }
- /**
- * 获取场次座位
- *
- * @param $relation_id
- * @param $sched_sign
- * @return mixed|string
- */
- public static function getSchedSeat($relation_id = '', $sched_sign = '')
- {
- $url = '/openapi/Movie/getSchedSeat';
- $body = [
- 'access_token' => self::get_access_token(),
- 'relation_id' => $relation_id,
- 'sched_sign' => $sched_sign
- ];
- $res = self::curl_post(self::$path . $url, $body);
- return $res;
- }
- /**
- * 锁座订单
- *
- * @param $phone
- * @param $channel_type
- * @param $sched_sign
- * @param $seat_sign
- * @param $third_order
- * @param $order_price
- * @return mixed|string
- */
- public static function submitOrder($phone, $channel_type, $sched_sign, $seat_sign, $third_order, $order_price)
- {
- $url = '/openapi/Movie/submitOrder';
- $body = [
- 'access_token' => self::get_access_token(),
- 'channel_type' => $channel_type,
- 'sched_sign' => $sched_sign,
- 'third_order' => $third_order,
- 'order_price' => $order_price,
- 'phone' => $phone,
- 'seat_sign' => $seat_sign
- ];
- $res = self::curl_post(self::$path . $url, $body);
- return $res;
- }
- /**
- * 确认订单
- *
- * @param $third_order
- * @param $order_price
- * @return mixed|string
- */
- public static function confirmOrder($third_order, $order_price)
- {
- $url = '/openapi/Movie/confirmOrder';
- $body = [
- 'access_token' => self::get_access_token(),
- 'third_order' => $third_order,
- 'order_price' => $order_price
- ];
- $res = self::curl_post(self::$path . $url, $body);
- return $res;
- }
- /**
- * 查询订单信息
- *
- * @param $third_order
- * @return mixed|string
- */
- public static function getOrderInfo($third_order)
- {
- $url = '/openapi/Movie/getOrderInfo';
- $body = [
- 'access_token' => self::get_access_token(),
- 'third_order' => $third_order
- ];
- $res = self::curl_post(self::$path . $url, $body);
- return $res;
- }
- /**
- * 签名
- *
- * @param $time
- * @return string
- */
- public static function getSign($time)
- {
- //按照以下顺序将字符串拼接起来 app_id+mobile+timestamp+app_secret 再用md5加密
- return md5(self::$app_id . self::$mobile . $time . self::$app_secret);
- }
- //通过curl发送post请求带body传参
- public static function curl_post($url, $postFields = null, $header = array())
- {
- $curl = curl_init();
- //设置抓取的url
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($curl, CURLOPT_TIMEOUT, 30);
- curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postFields));
- // curl_setopt($curl, CURLOPT_TIMEOUT_MS, 500);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
- // curl_setopt($curl, CURLOPT_HEADER, 1);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- //执行命令
- $data = curl_exec($curl);
- // if (is_null(json_decode($data))) {
- // $data = strstr($data, '{');
- // }
- // 显示错误信息
- if (curl_error($curl)) {
- return curl_error($curl);
- } else {
- curl_close($curl);
- return json_decode($data, true);
- }
- }
- }
|