Просмотр исходного кода

提交封装好的电影基础调用类

family 1 год назад
Родитель
Сommit
2e2fc3f56d

+ 306 - 0
app/common/repositories/movie/DouHuoMallFilmApiRequest.php

@@ -0,0 +1,306 @@
1
+<?php
2
+
3
+
4
+namespace app\common\repositories\movie;
5
+
6
+use think\facade\Cache;
7
+
8
+/**
9
+ * 微唯宝电影
10
+ */
11
+class DouHuoMallFilmApiRequest
12
+{
13
+    //接口文档:https://docs.qq.com/doc/DWkJQS0h3WENvVmdG?u=a6a6ad6c89714f6394f5fd13fcffc2ac
14
+    private static $path = 'http://wmh5.douhuomall.com';
15
+    private static $app_id = 'YS3a8ab661406e47bb86';
16
+    private static $app_secret = '41d8b8e1dd9a454a1abc4534297e33c3';
17
+    private static $mobile = '16630402568';
18
+
19
+    private static $successCode = 200;
20
+    private static $douHuoMallFilmAccessTokenCache = 'DouHuoMallFilmAccessToken';
21
+
22
+    /**
23
+     *
24
+     *
25
+     * @return false|mixed
26
+     */
27
+    public static function request_access_token()
28
+    {
29
+        $url = '/openapi/Auth/accessToken';
30
+        $time = date('Y-m-d H:i:s');
31
+        $body = [
32
+            'app_id' => self::$app_id,
33
+            'sign' => self::getSign($time),
34
+            'mobile' => self::$mobile,
35
+            'datetime' => $time
36
+        ];
37
+        $res = self::curl_post(self::$path . $url, $body);
38
+        if ($res['code'] == self::$successCode) {
39
+            $expire_time = strtotime($res['data']['expire_time']) - 5 - time();
40
+            $expire_time = $expire_time > 0 ? $expire_time : 3600;
41
+            Cache::set(self::$douHuoMallFilmAccessTokenCache, $res['data']['access_token'], $expire_time);// 将取到的token存入redis方便下次使用
42
+            return $res['data']['access_token'];
43
+        }
44
+        return '';
45
+    }
46
+
47
+    /**
48
+     * 获取token
49
+     *
50
+     * @return mixed
51
+     */
52
+    public static function get_access_token()
53
+    {
54
+        $access_token = Cache::get(self::$douHuoMallFilmAccessTokenCache);
55
+        return $access_token ?? self::request_access_token();
56
+    }
57
+
58
+    /**
59
+     * 获取城市列表
60
+     * @return false|int|mixed
61
+     */
62
+    public static function getMovieCity($page = 1, $limit = 10, $initial = '', $city_name = '')
63
+    {
64
+        $url = '/openapi/Movie/getCity';
65
+        $body = [
66
+            'Access-Token' => self::get_access_token(),
67
+            'page' => $page,
68
+            'limit' => $limit
69
+        ];
70
+        if (!empty($initial)) $body['initial'] = $initial;
71
+        if (!empty($city_name)) $body['city_name'] = $city_name;
72
+
73
+        $res = self::curl_post(self::$path . $url, $body);
74
+        return $res;
75
+    }
76
+
77
+    /**
78
+     * 获取城市分区列表
79
+     * @return false|int|mixed
80
+     */
81
+    public static function getMovieArea($city_sign = '')
82
+    {
83
+        $url = '/openapi/Movie/getArea';
84
+        $body = [
85
+            'Access-Token' => self::get_access_token(),
86
+            'city_sign' => $city_sign
87
+        ];
88
+
89
+        $res = self::curl_post(self::$path . $url, $body);
90
+        return $res;
91
+    }
92
+
93
+    /**
94
+     * 获取影院列表
95
+     * @param $page
96
+     * @param $limit
97
+     * @param $city_sign
98
+     * @param $area_sign
99
+     * @return mixed|string
100
+     */
101
+    public static function getCinema($page = 1, $limit = 10, $city_sign = '', $area_sign = '')
102
+    {
103
+        $url = '/openapi/Movie/getCinema';
104
+        $body = [
105
+            'Access-Token' => self::get_access_token(),
106
+            'page' => $page,
107
+            'limit' => $limit
108
+        ];
109
+        if (!empty($city_sign)) $body['city_sign'] = $city_sign;
110
+        if (!empty($area_sign)) $body['area_sign'] = $area_sign;
111
+
112
+        $res = self::curl_post(self::$path . $url, $body);
113
+        return $res;
114
+    }
115
+
116
+    /**
117
+     * 获取影片列表
118
+     * @param $page
119
+     * @param $limit
120
+     * @param $cinema_sign
121
+     * @param $film_sign
122
+     * @return mixed|string
123
+     */
124
+    public static function getFilm($page = 1, $limit = 10, $cinema_sign = '', $film_sign = '')
125
+    {
126
+        $url = '/openapi/Movie/getFilm';
127
+        $body = [
128
+            'Access-Token' => self::get_access_token(),
129
+            'page' => $page,
130
+            'limit' => $limit
131
+        ];
132
+        if (!empty($cinema_sign)) $body['cinema_sign'] = $cinema_sign;
133
+        if (!empty($film_sign)) $body['film_sign'] = $film_sign;
134
+
135
+        $res = self::curl_post(self::$path . $url, $body);
136
+        return $res;
137
+    }
138
+
139
+    /**
140
+     * 获取排片影院列表(废弃)
141
+     * @param $page
142
+     * @param $limit
143
+     * @param $cinema_sign
144
+     * @param $film_sign
145
+     * @return mixed|string
146
+     */
147
+    public static function getFilmSched($page = 1, $limit = 10, $film_sign = '', $longitude = '', $latitude = '')
148
+    {
149
+        $url = '/openapi/Movie/getFilmSched';
150
+        $body = [
151
+            'Access-Token' => self::get_access_token(),
152
+            'page' => $page,
153
+            'limit' => $limit,
154
+            'film_sign' => $film_sign,
155
+            'longitude' => $longitude,
156
+            'latitude' => $latitude
157
+        ];
158
+
159
+        $res = self::curl_post(self::$path . $url, $body);
160
+        return $res;
161
+    }
162
+
163
+    /**
164
+     * 获取影院场次列表
165
+     *
166
+     * @param $film_sign
167
+     * @param $cinema_sign
168
+     * @return mixed|string
169
+     */
170
+    public static function getCinemaSched($film_sign = '', $cinema_sign = '')
171
+    {
172
+        $url = '/openapi/Movie/getCinemaSched';
173
+        $body = [
174
+            'Access-Token' => self::get_access_token(),
175
+            'film_sign' => $film_sign,
176
+            'cinema_sign' => $cinema_sign
177
+        ];
178
+
179
+        $res = self::curl_post(self::$path . $url, $body);
180
+        return $res;
181
+    }
182
+
183
+    /**
184
+     * 获取场次座位
185
+     *
186
+     * @param $relation_id
187
+     * @param $sched_sign
188
+     * @return mixed|string
189
+     */
190
+    public static function getSchedSeat($relation_id = '', $sched_sign = '')
191
+    {
192
+        $url = '/openapi/Movie/getSchedSeat';
193
+        $body = [
194
+            'Access-Token' => self::get_access_token(),
195
+            'relation_id' => $relation_id,
196
+            'sched_sign' => $sched_sign
197
+        ];
198
+
199
+        $res = self::curl_post(self::$path . $url, $body);
200
+        return $res;
201
+    }
202
+
203
+    /**
204
+     * 锁座订单
205
+     *
206
+     * @param $relation_id
207
+     * @param $sched_sign
208
+     * @return mixed|string
209
+     */
210
+    public static function submitOrde($phone, $channel_type, $sched_sign, $third_order, $order_price)
211
+    {
212
+        $url = '/openapi/Movie/submitOrder';
213
+        $body = [
214
+            'Access-Token' => self::get_access_token(),
215
+            'channel_type' => $channel_type,
216
+            'sched_sign' => $sched_sign,
217
+            'third_order' => $third_order,
218
+            'order_price' => $order_price,
219
+            'phone' => $phone
220
+        ];
221
+
222
+        $res = self::curl_post(self::$path . $url, $body);
223
+        return $res;
224
+    }
225
+
226
+    /**
227
+     * 确认订单
228
+     *
229
+     * @param $third_order
230
+     * @param $order_price
231
+     * @return mixed|string
232
+     */
233
+    public static function confirmOrder($third_order, $order_price)
234
+    {
235
+        $url = '/openapi/Movie/confirmOrder';
236
+        $body = [
237
+            'Access-Token' => self::get_access_token(),
238
+            'third_order' => $third_order,
239
+            'order_price' => $order_price
240
+        ];
241
+
242
+        $res = self::curl_post(self::$path . $url, $body);
243
+        return $res;
244
+    }
245
+
246
+    /**
247
+     * 查询订单信息
248
+     *
249
+     * @param $third_order
250
+     * @return mixed|string
251
+     */
252
+    public static function getOrderInfo($third_order)
253
+    {
254
+        $url = '/openapi/Movie/getOrderInfo';
255
+        $body = [
256
+            'Access-Token' => self::get_access_token(),
257
+            'third_order' => $third_order
258
+        ];
259
+
260
+        $res = self::curl_post(self::$path . $url, $body);
261
+        return $res;
262
+    }
263
+
264
+    /**
265
+     * 签名
266
+     *
267
+     * @param $time
268
+     * @return string
269
+     */
270
+    public static function getSign($time)
271
+    {
272
+        //按照以下顺序将字符串拼接起来 app_id+mobile+timestamp+app_secret 再用md5加密
273
+        return md5(self::$app_id . self::$mobile . $time . self::$app_secret);
274
+    }
275
+
276
+    //通过curl发送post请求带body传参
277
+    public static function curl_post($url, $postFields = null, $header = array())
278
+    {
279
+        $curl = curl_init();
280
+        //设置抓取的url
281
+        curl_setopt($curl, CURLOPT_URL, $url);
282
+        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
283
+        curl_setopt($curl, CURLOPT_TIMEOUT, 30);
284
+        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postFields));
285
+//        curl_setopt($curl, CURLOPT_TIMEOUT_MS, 500);
286
+        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
287
+//        curl_setopt($curl, CURLOPT_HEADER, 1);
288
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
289
+        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
290
+        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
291
+        //执行命令
292
+        $data = curl_exec($curl);
293
+//        if (is_null(json_decode($data))) {
294
+//            $data = strstr($data, '{');
295
+//        }
296
+        // 显示错误信息
297
+        if (curl_error($curl)) {
298
+            return curl_error($curl);
299
+        } else {
300
+            curl_close($curl);
301
+            return json_decode($data, true);
302
+        }
303
+    }
304
+
305
+
306
+}

Разница между файлами не показана из-за своего большого размера
+ 2074 - 0
app/common/repositories/movie/MovieRepository.php


Разница между файлами не показана из-за своего большого размера
+ 1426 - 0
app/controller/api/movie/Movie.php