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); } } }