|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the overtrue/wechat. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) overtrue <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Card.php. |
|
14
|
|
|
* |
|
15
|
|
|
* @author overtrue <[email protected]> |
|
16
|
|
|
* @copyright 2016 overtrue <[email protected]> |
|
17
|
|
|
* |
|
18
|
|
|
* @link https://github.com/overtrue |
|
19
|
|
|
* @link http://overtrue.me |
|
20
|
|
|
*/ |
|
21
|
|
|
namespace EasyWeChat\Card; |
|
22
|
|
|
|
|
23
|
|
|
use Doctrine\Common\Cache\Cache; |
|
24
|
|
|
use Doctrine\Common\Cache\FilesystemCache; |
|
25
|
|
|
use EasyWeChat\Core\AbstractAPI; |
|
26
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
27
|
|
|
|
|
28
|
|
|
class Card extends AbstractAPI |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Cache. |
|
32
|
|
|
* |
|
33
|
|
|
* @var Cache |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $cache; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Ticket cache prefix. |
|
39
|
|
|
*/ |
|
40
|
|
|
const TICKET_CACHE_PREFIX = 'overtrue.wechat.card_api_ticket.'; |
|
41
|
|
|
|
|
42
|
|
|
const API_GET_COLORS = 'https://api.weixin.qq.com/card/getcolors'; |
|
43
|
|
|
const API_CREATE = 'https://api.weixin.qq.com/card/create'; |
|
44
|
|
|
const API_QRCODE_CREATE = 'https://api.weixin.qq.com/card/qrcode/create'; |
|
45
|
|
|
const API_QRCODE_SHOW = 'https://mp.weixin.qq.com/cgi-bin/showqrcode'; |
|
46
|
|
|
const API_GET_CARD_TICKET = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket'; |
|
47
|
|
|
const API_LANDING_PAGE = 'https://api.weixin.qq.com/card/landingpage/create'; |
|
48
|
|
|
const API_DEPOSIT = 'https://api.weixin.qq.com/card/code/deposit'; |
|
49
|
|
|
const API_GET_DEPOSIT_COUNT = 'https://api.weixin.qq.com/card/code/getdepositcount'; |
|
50
|
|
|
const API_CHECK_CODE = 'https://api.weixin.qq.com/card/code/checkcode'; |
|
51
|
|
|
const API_GET_HTML = 'https://api.weixin.qq.com/card/mpnews/gethtml'; |
|
52
|
|
|
const API_TEST_WHITE_LIST = 'https://api.weixin.qq.com/card/testwhitelist/set'; |
|
53
|
|
|
const API_CODE_GET = 'https://api.weixin.qq.com/card/code/get'; |
|
54
|
|
|
const API_CONSUME = 'https://api.weixin.qq.com/card/code/consume'; |
|
55
|
|
|
const API_DECRYPT = 'https://api.weixin.qq.com/card/code/decrypt'; |
|
56
|
|
|
const API_GET_CARD_LIST = 'https://api.weixin.qq.com/card/user/getcardlist'; |
|
57
|
|
|
const API_CARD_GET = 'https://api.weixin.qq.com/card/get'; |
|
58
|
|
|
const API_BATCH_GET = 'https://api.weixin.qq.com/card/batchget'; |
|
59
|
|
|
const API_UPDATE = 'https://api.weixin.qq.com/card/update'; |
|
60
|
|
|
const API_PAY_CELL_SET = 'https://api.weixin.qq.com/card/paycell/set'; |
|
61
|
|
|
const API_MODIFY_STOCK = 'https://api.weixin.qq.com/card/modifystock'; |
|
62
|
|
|
const API_CODE_UPDATE = 'https://api.weixin.qq.com/card/code/update'; |
|
63
|
|
|
const API_CARD_DELETE = 'https://api.weixin.qq.com/card/delete'; |
|
64
|
|
|
const API_UNAVAILABLE = 'https://api.weixin.qq.com/card/code/unavailable'; |
|
65
|
|
|
const API_CARD_BIZ_UIN_INFO = 'https://api.weixin.qq.com/datacube/getcardbizuininfo'; |
|
66
|
|
|
const API_CARD_CARD_INFO = 'https://api.weixin.qq.com/datacube/getcardcardinfo'; |
|
67
|
|
|
const API_CARD_MEMBER_CARD_INFO = 'https://api.weixin.qq.com/datacube/getcardmembercardinfo'; |
|
68
|
|
|
const API_CARD_ACTIVATE = 'https://api.weixin.qq.com/card/membercard/activate'; |
|
69
|
|
|
const API_ACTIVATE_USER_FORM = 'https://api.weixin.qq.com/card/membercard/activateuserform/set'; |
|
70
|
|
|
const API_MEMBER_USER_INFO = 'https://api.weixin.qq.com/card/membercard/userinfo/get'; |
|
71
|
|
|
const API_UPDATE_USER = 'https://api.weixin.qq.com/card/membercard/updateuser'; |
|
72
|
|
|
const API_SUB_MERCHANT = 'https://api.weixin.qq.com/card/submerchant/submit'; |
|
73
|
|
|
const API_GET_APPLY_PROTOCOL = 'https://api.weixin.qq.com/card/getapplyprotocol'; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* 获取卡券颜色. |
|
77
|
|
|
* |
|
78
|
|
|
* @return array |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public function getColors() |
|
81
|
|
|
{ |
|
82
|
1 |
|
return $this->parseJSON('get', [self::API_GET_COLORS]); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* 创建卡券. |
|
87
|
|
|
* |
|
88
|
|
|
* @param string $cardType |
|
89
|
|
|
* @param array $baseInfo |
|
90
|
|
|
* @param array $especial |
|
91
|
|
|
* @param array $advancedInfo |
|
92
|
|
|
* |
|
93
|
|
|
* @return bool|array |
|
94
|
|
|
*/ |
|
95
|
1 |
|
public function create($cardType = 'member_card', $baseInfo = [], $especial = [], $advancedInfo = []) |
|
96
|
|
|
{ |
|
97
|
1 |
|
$card = []; |
|
98
|
1 |
|
$card['card'] = []; |
|
99
|
1 |
|
$card['card']['card_type'] = strtoupper($cardType); |
|
100
|
|
|
|
|
101
|
1 |
|
$type = strtolower($cardType); |
|
102
|
|
|
|
|
103
|
|
|
$cardInfo = [ |
|
104
|
1 |
|
'base_info' => $baseInfo, |
|
105
|
1 |
|
]; |
|
106
|
|
|
|
|
107
|
1 |
|
$card['card'][$type] = []; |
|
108
|
1 |
|
$card['card'][$type] = array_merge($cardInfo, $especial, $advancedInfo); |
|
109
|
|
|
|
|
110
|
1 |
|
if (is_string($cardType) && is_array($baseInfo) && is_array($especial)) { |
|
111
|
1 |
|
return $this->parseJSON('json', [self::API_CREATE, $card]); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
return false; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* 创建二维码. |
|
119
|
|
|
* |
|
120
|
|
|
* @param array $cards |
|
121
|
|
|
* |
|
122
|
|
|
* @return array|bool |
|
123
|
|
|
*/ |
|
124
|
1 |
|
public function qrCode($cards = []) |
|
125
|
|
|
{ |
|
126
|
1 |
|
return $this->parseJSON('json', [self::API_QRCODE_CREATE, $cards]); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* ticket 换取二维码图片. |
|
131
|
|
|
* |
|
132
|
|
|
* @param string $ticket |
|
133
|
|
|
* |
|
134
|
|
|
* @return array |
|
135
|
|
|
*/ |
|
136
|
1 |
|
public function showQrCode($ticket = null) |
|
137
|
|
|
{ |
|
138
|
|
|
$params = [ |
|
139
|
1 |
|
'ticket' => $ticket, |
|
140
|
1 |
|
]; |
|
141
|
|
|
|
|
142
|
1 |
|
$http = $this->getHttp(); |
|
143
|
|
|
|
|
144
|
|
|
/** @var ResponseInterface $response */ |
|
145
|
1 |
|
$response = $http->get(self::API_QRCODE_SHOW, $params); |
|
146
|
|
|
|
|
147
|
|
|
return [ |
|
148
|
1 |
|
'status' => $response->getStatusCode(), |
|
149
|
1 |
|
'reason' => $response->getReasonPhrase(), |
|
150
|
1 |
|
'headers' => $response->getHeaders(), |
|
151
|
1 |
|
'body' => strval($response->getBody()), |
|
152
|
1 |
|
'url' => self::API_QRCODE_SHOW.'?'.http_build_query($params), |
|
153
|
1 |
|
]; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* 通过ticket换取二维码 链接. |
|
158
|
|
|
* |
|
159
|
|
|
* @param string $ticket |
|
160
|
|
|
* |
|
161
|
|
|
* @return string |
|
162
|
|
|
*/ |
|
163
|
1 |
|
public function showQrCodeUrl($ticket) |
|
164
|
|
|
{ |
|
165
|
1 |
|
$params = '?ticket='.$ticket; |
|
166
|
|
|
|
|
167
|
1 |
|
return self::API_QRCODE_SHOW.$params; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* 获取 卡券 Api_ticket. |
|
172
|
|
|
* |
|
173
|
|
|
* @param bool $refresh 是否强制刷新 |
|
174
|
|
|
* |
|
175
|
|
|
* @return string $apiTicket |
|
176
|
|
|
*/ |
|
177
|
2 |
View Code Duplication |
public function cardApiTicket($refresh = false) |
|
178
|
|
|
{ |
|
179
|
2 |
|
$key = self::TICKET_CACHE_PREFIX.$this->getAccessToken()->getAppId(); |
|
180
|
|
|
|
|
181
|
2 |
|
$ticket = $this->getCache()->fetch($key); |
|
182
|
|
|
|
|
183
|
2 |
|
if (!$ticket || $refresh) { |
|
184
|
1 |
|
$result = $this->parseJSON('get', [self::API_GET_CARD_TICKET, ['type' => 'wx_card']]); |
|
185
|
|
|
|
|
186
|
1 |
|
$this->getCache()->save($key, $result['ticket'], $result['expires_in'] - 500); |
|
187
|
|
|
|
|
188
|
1 |
|
return $result['ticket']; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
1 |
|
return $ticket; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* 微信卡券:JSAPI 卡券Package - 基础参数没有附带任何值 - 再生产环境中需要根据实际情况进行修改. |
|
196
|
|
|
* |
|
197
|
|
|
* @param array $cards |
|
198
|
|
|
* @param int $timestamp |
|
199
|
|
|
* @param string $apiTicket |
|
200
|
|
|
* |
|
201
|
|
|
* @return string |
|
202
|
|
|
*/ |
|
203
|
1 |
|
public function wxCardPackage(array $cards, $timestamp = null, $apiTicket = null) |
|
204
|
|
|
{ |
|
205
|
1 |
|
if (empty($timestamp) || $timestamp === '') { |
|
|
|
|
|
|
206
|
1 |
|
$timestamp = time(); |
|
207
|
1 |
|
} |
|
208
|
|
|
|
|
209
|
1 |
|
if (empty($apiTicket) || $apiTicket === '') { |
|
210
|
1 |
|
$apiTicket = $this->cardApiTicket(); |
|
211
|
1 |
|
} |
|
212
|
|
|
|
|
213
|
1 |
|
$result = []; |
|
214
|
1 |
|
foreach ($cards as $index => $card) { |
|
215
|
1 |
View Code Duplication |
if (empty($card['code']) || !isset($card['code'])) { |
|
|
|
|
|
|
216
|
1 |
|
$card['code'] = ''; |
|
217
|
1 |
|
} |
|
218
|
|
|
|
|
219
|
1 |
View Code Duplication |
if (empty($card['openid']) || !isset($card['openid'])) { |
|
|
|
|
|
|
220
|
1 |
|
$card['openid'] = ''; |
|
221
|
1 |
|
} |
|
222
|
|
|
|
|
223
|
1 |
|
$arrays = [$apiTicket, $timestamp, $card['card_id'], $card['code'], $card['openid']]; |
|
224
|
1 |
|
sort($arrays, SORT_STRING); |
|
225
|
1 |
|
$string = sha1(implode($arrays)); |
|
226
|
|
|
|
|
227
|
1 |
|
$result['cardList'][$index]['cardId'] = $card['card_id']; |
|
228
|
1 |
|
$result['cardList'][$index]['cardExt']['code'] = $card['code']; |
|
229
|
1 |
|
$result['cardList'][$index]['cardExt']['openid'] = $card['openid']; |
|
230
|
|
|
|
|
231
|
1 |
|
$result['cardList'][$index]['cardExt']['timestamp'] = $timestamp; |
|
232
|
1 |
|
$result['cardList'][$index]['cardExt']['signature'] = $string; |
|
233
|
|
|
|
|
234
|
1 |
|
if (!empty($card['outer_id'])) { |
|
235
|
1 |
|
$result['cardList'][$index]['cardExt']['outer_id'] = $card['outer_id']; |
|
236
|
1 |
|
} |
|
237
|
|
|
|
|
238
|
1 |
|
$result['cardList'][$index]['cardExt'] = json_encode($result['cardList'][$index]['cardExt']); |
|
239
|
1 |
|
} |
|
240
|
|
|
|
|
241
|
1 |
|
return json_encode($result); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* 创建货架接口. |
|
246
|
|
|
* |
|
247
|
|
|
* @param string $banner |
|
248
|
|
|
* @param string $pageTitle |
|
249
|
|
|
* @param bool $canShare |
|
250
|
|
|
* @param string $scene [SCENE_NEAR_BY 附近,SCENE_MENU 自定义菜单,SCENE_QRCODE 二维码,SCENE_ARTICLE 公众号文章, |
|
251
|
|
|
* SCENE_H5 h5页面,SCENE_IVR 自动回复,SCENE_CARD_CUSTOM_CELL 卡券自定义cell] |
|
252
|
|
|
* @param array $cardList |
|
253
|
|
|
* |
|
254
|
|
|
* @return array |
|
255
|
|
|
*/ |
|
256
|
1 |
|
public function landingPage($banner, $pageTitle, $canShare, $scene, $cardList) |
|
257
|
|
|
{ |
|
258
|
|
|
$params = [ |
|
259
|
1 |
|
'banner' => $banner, |
|
260
|
1 |
|
'page_title' => $pageTitle, |
|
261
|
1 |
|
'can_share' => $canShare, |
|
262
|
1 |
|
'scene' => $scene, |
|
263
|
1 |
|
'card_list' => $cardList, |
|
264
|
1 |
|
]; |
|
265
|
|
|
|
|
266
|
1 |
|
return $this->parseJSON('json', [self::API_LANDING_PAGE, $params]); |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* 导入code接口. |
|
271
|
|
|
* |
|
272
|
|
|
* @param string $cardId |
|
273
|
|
|
* @param array $code |
|
274
|
|
|
* |
|
275
|
|
|
* @return array |
|
276
|
|
|
*/ |
|
277
|
1 |
View Code Duplication |
public function deposit($cardId, $code) |
|
278
|
|
|
{ |
|
279
|
|
|
$params = [ |
|
280
|
1 |
|
'card_id' => $cardId, |
|
281
|
1 |
|
'code' => $code, |
|
282
|
1 |
|
]; |
|
283
|
|
|
|
|
284
|
1 |
|
return $this->parseJSON('json', [self::API_DEPOSIT, $params]); |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
/** |
|
288
|
|
|
* 查询导入code数目. |
|
289
|
|
|
* |
|
290
|
|
|
* @param string $cardId |
|
291
|
|
|
* |
|
292
|
|
|
* @return array |
|
293
|
|
|
*/ |
|
294
|
1 |
View Code Duplication |
public function getDepositCount($cardId) |
|
295
|
|
|
{ |
|
296
|
|
|
$params = [ |
|
297
|
1 |
|
'card_id' => $cardId, |
|
298
|
1 |
|
]; |
|
299
|
|
|
|
|
300
|
1 |
|
return $this->parseJSON('json', [self::API_GET_DEPOSIT_COUNT, $params]); |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
/** |
|
304
|
|
|
* 核查code接口. |
|
305
|
|
|
* |
|
306
|
|
|
* @param string $cardId |
|
307
|
|
|
* @param array $code |
|
308
|
|
|
* |
|
309
|
|
|
* @return array |
|
310
|
|
|
*/ |
|
311
|
1 |
View Code Duplication |
public function checkCode($cardId, $code) |
|
312
|
|
|
{ |
|
313
|
|
|
$params = [ |
|
314
|
1 |
|
'card_id' => $cardId, |
|
315
|
1 |
|
'code' => $code, |
|
316
|
1 |
|
]; |
|
317
|
|
|
|
|
318
|
1 |
|
return $this->parseJSON('json', [self::API_CHECK_CODE, $params]); |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
/** |
|
322
|
|
|
* 图文消息群发卡券. |
|
323
|
|
|
* |
|
324
|
|
|
* @param string $cardId |
|
325
|
|
|
* |
|
326
|
|
|
* @return array |
|
327
|
|
|
*/ |
|
328
|
1 |
View Code Duplication |
public function getHtml($cardId) |
|
329
|
|
|
{ |
|
330
|
|
|
$params = [ |
|
331
|
1 |
|
'card_id' => $cardId, |
|
332
|
1 |
|
]; |
|
333
|
|
|
|
|
334
|
1 |
|
return $this->parseJSON('json', [self::API_GET_HTML, $params]); |
|
335
|
|
|
} |
|
336
|
|
|
|
|
337
|
|
|
/** |
|
338
|
|
|
* 设置测试白名单. |
|
339
|
|
|
* |
|
340
|
|
|
* @param array $openid |
|
341
|
|
|
* @param array $username |
|
342
|
|
|
* |
|
343
|
|
|
* @return array |
|
344
|
|
|
*/ |
|
345
|
1 |
|
public function testWhitelist($openid, $username) |
|
346
|
|
|
{ |
|
347
|
|
|
$params = [ |
|
348
|
1 |
|
'openid' => $openid, |
|
349
|
1 |
|
'username' => $username, |
|
350
|
1 |
|
]; |
|
351
|
|
|
|
|
352
|
1 |
|
return $this->parseJSON('json', [self::API_TEST_WHITE_LIST, $params]); |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
/** |
|
356
|
|
|
* 查询Code接口. |
|
357
|
|
|
* |
|
358
|
|
|
* @param string $code |
|
359
|
|
|
* @param bool $checkConsume |
|
360
|
|
|
* @param string $cardId |
|
361
|
|
|
* |
|
362
|
|
|
* @return array |
|
363
|
|
|
*/ |
|
364
|
1 |
View Code Duplication |
public function getCode($code, $checkConsume, $cardId) |
|
365
|
|
|
{ |
|
366
|
|
|
$params = [ |
|
367
|
1 |
|
'code' => $code, |
|
368
|
1 |
|
'check_consume' => $checkConsume, |
|
369
|
1 |
|
'card_id' => $cardId, |
|
370
|
1 |
|
]; |
|
371
|
|
|
|
|
372
|
1 |
|
return $this->parseJSON('json', [self::API_CODE_GET, $params]); |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
/** |
|
376
|
|
|
* 核销Code接口. |
|
377
|
|
|
* |
|
378
|
|
|
* @param string $cardId |
|
379
|
|
|
* @param string $code |
|
380
|
|
|
* |
|
381
|
|
|
* @return array |
|
382
|
|
|
*/ |
|
383
|
1 |
View Code Duplication |
public function consume($cardId, $code) |
|
384
|
|
|
{ |
|
385
|
|
|
$params = [ |
|
386
|
1 |
|
'card_id' => $cardId, |
|
387
|
1 |
|
'code' => $code, |
|
388
|
1 |
|
]; |
|
389
|
|
|
|
|
390
|
1 |
|
return $this->parseJSON('json', [self::API_CONSUME, $params]); |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
|
|
/** |
|
394
|
|
|
* Code解码接口. |
|
395
|
|
|
* |
|
396
|
|
|
* @param string $encryptedCode |
|
397
|
|
|
* |
|
398
|
|
|
* @return array |
|
399
|
|
|
*/ |
|
400
|
1 |
|
public function decrypt($encryptedCode) |
|
401
|
|
|
{ |
|
402
|
|
|
$params = [ |
|
403
|
1 |
|
'encrypt_code' => $encryptedCode, |
|
404
|
1 |
|
]; |
|
405
|
|
|
|
|
406
|
1 |
|
return $this->parseJSON('json', [self::API_DECRYPT, $params]); |
|
407
|
|
|
} |
|
408
|
|
|
|
|
409
|
|
|
/** |
|
410
|
|
|
* 获取用户已领取卡券接口. |
|
411
|
|
|
* |
|
412
|
|
|
* @param string $openid |
|
413
|
|
|
* @param string $cardId |
|
414
|
|
|
* |
|
415
|
|
|
* @return array |
|
416
|
|
|
*/ |
|
417
|
1 |
View Code Duplication |
public function getCardList($openid, $cardId = '') |
|
418
|
|
|
{ |
|
419
|
|
|
$params = [ |
|
420
|
1 |
|
'openid' => $openid, |
|
421
|
1 |
|
'card_id' => $cardId, |
|
422
|
1 |
|
]; |
|
423
|
|
|
|
|
424
|
1 |
|
return $this->parseJSON('json', [self::API_GET_CARD_LIST, $params]); |
|
425
|
|
|
} |
|
426
|
|
|
|
|
427
|
|
|
/** |
|
428
|
|
|
* 查看卡券详情. |
|
429
|
|
|
* |
|
430
|
|
|
* @param string $cardId |
|
431
|
|
|
* |
|
432
|
|
|
* @return array |
|
433
|
|
|
*/ |
|
434
|
1 |
View Code Duplication |
public function getCard($cardId) |
|
435
|
|
|
{ |
|
436
|
|
|
$params = [ |
|
437
|
1 |
|
'card_id' => $cardId, |
|
438
|
1 |
|
]; |
|
439
|
|
|
|
|
440
|
1 |
|
return $this->parseJSON('json', [self::API_CARD_GET, $params]); |
|
441
|
|
|
} |
|
442
|
|
|
|
|
443
|
|
|
/** |
|
444
|
|
|
* 批量查询卡列表. |
|
445
|
|
|
* |
|
446
|
|
|
* @param int $offset |
|
447
|
|
|
* @param int $count |
|
448
|
|
|
* @param string $statusList |
|
449
|
|
|
* |
|
450
|
|
|
* @return array |
|
451
|
|
|
*/ |
|
452
|
1 |
View Code Duplication |
public function getBatch($offset = 0, $count = 10, $statusList = 'CARD_STATUS_VERIFY_OK') |
|
453
|
|
|
{ |
|
454
|
|
|
$params = [ |
|
455
|
1 |
|
'offset' => $offset, |
|
456
|
1 |
|
'count' => $count, |
|
457
|
1 |
|
'status_list' => $statusList, |
|
458
|
1 |
|
]; |
|
459
|
|
|
|
|
460
|
1 |
|
return $this->parseJSON('json', [self::API_BATCH_GET, $params]); |
|
461
|
|
|
} |
|
462
|
|
|
|
|
463
|
|
|
/** |
|
464
|
|
|
* 更改卡券信息接口 and 设置跟随推荐接口. |
|
465
|
|
|
* |
|
466
|
|
|
* @param string $cardId |
|
467
|
|
|
* @param string $type |
|
468
|
|
|
* @param array $baseInfo |
|
469
|
|
|
* @param array $especial |
|
470
|
|
|
* |
|
471
|
|
|
* @return array |
|
472
|
|
|
*/ |
|
473
|
1 |
|
public function update($cardId, $type, $baseInfo = [], $especial = []) |
|
474
|
|
|
{ |
|
475
|
1 |
|
$card = []; |
|
476
|
1 |
|
$card['card_id'] = $cardId; |
|
477
|
1 |
|
$card[$type] = []; |
|
478
|
|
|
|
|
479
|
1 |
|
$cardInfo = []; |
|
480
|
1 |
|
$cardInfo['base_info'] = $baseInfo; |
|
481
|
|
|
|
|
482
|
1 |
|
$card[$type] = array_merge($cardInfo, $especial); |
|
483
|
|
|
|
|
484
|
1 |
|
return $this->parseJSON('json', [self::API_UPDATE, $card]); |
|
485
|
|
|
} |
|
486
|
|
|
|
|
487
|
|
|
/** |
|
488
|
|
|
* 设置微信买单接口. |
|
489
|
|
|
* 设置买单的card_id必须已经配置了门店,否则会报错. |
|
490
|
|
|
* |
|
491
|
|
|
* @param string $cardId |
|
492
|
|
|
* @param bool $isOpen |
|
493
|
|
|
* |
|
494
|
|
|
* @return array |
|
495
|
|
|
*/ |
|
496
|
1 |
View Code Duplication |
public function setPayCell($cardId, $isOpen = true) |
|
497
|
|
|
{ |
|
498
|
|
|
$params = [ |
|
499
|
1 |
|
'card_id' => $cardId, |
|
500
|
1 |
|
'is_open' => $isOpen, |
|
501
|
1 |
|
]; |
|
502
|
|
|
|
|
503
|
1 |
|
return $this->parseJSON('json', [self::API_PAY_CELL_SET, $params]); |
|
504
|
|
|
} |
|
505
|
|
|
|
|
506
|
|
|
/** |
|
507
|
|
|
* 修改库存接口. |
|
508
|
|
|
* |
|
509
|
|
|
* @param string $cardId |
|
510
|
|
|
* @param string $stock |
|
511
|
|
|
* @param int $value |
|
512
|
|
|
* |
|
513
|
|
|
* @return array |
|
514
|
|
|
*/ |
|
515
|
1 |
|
public function modifyStock($cardId, $stock = 'increase', $value = 0) |
|
516
|
|
|
{ |
|
517
|
|
|
$params = [ |
|
518
|
1 |
|
'card_id' => $cardId, |
|
519
|
1 |
|
]; |
|
520
|
|
|
|
|
521
|
1 |
|
if ($stock === 'increase') { |
|
522
|
1 |
|
$params['increase_stock_value'] = intval($value); |
|
523
|
1 |
|
} elseif ($stock === 'reduce') { |
|
524
|
|
|
$params['reduce_stock_value'] = intval($value); |
|
525
|
|
|
} else { |
|
526
|
|
|
return false; |
|
527
|
|
|
} |
|
528
|
|
|
|
|
529
|
1 |
|
return $this->parseJSON('json', [self::API_MODIFY_STOCK, $params]); |
|
530
|
|
|
} |
|
531
|
|
|
|
|
532
|
|
|
/** |
|
533
|
|
|
* 更改Code接口. |
|
534
|
|
|
* |
|
535
|
|
|
* @param string $code |
|
536
|
|
|
* @param string $newCode |
|
537
|
|
|
* @param array $cardId |
|
538
|
|
|
* |
|
539
|
|
|
* @return array |
|
540
|
|
|
*/ |
|
541
|
1 |
View Code Duplication |
public function updateCode($code, $newCode, $cardId = []) |
|
542
|
|
|
{ |
|
543
|
|
|
$params = [ |
|
544
|
1 |
|
'code' => $code, |
|
545
|
1 |
|
'new_code' => $newCode, |
|
546
|
1 |
|
'card_id' => $cardId, |
|
547
|
1 |
|
]; |
|
548
|
|
|
|
|
549
|
1 |
|
return $this->parseJSON('json', [self::API_CODE_UPDATE, $params]); |
|
550
|
|
|
} |
|
551
|
|
|
|
|
552
|
|
|
/** |
|
553
|
|
|
* 删除卡券接口. |
|
554
|
|
|
* |
|
555
|
|
|
* @param string $cardId |
|
556
|
|
|
* |
|
557
|
|
|
* @return array |
|
558
|
|
|
*/ |
|
559
|
1 |
View Code Duplication |
public function delete($cardId) |
|
560
|
|
|
{ |
|
561
|
|
|
$params = [ |
|
562
|
1 |
|
'card_id' => $cardId, |
|
563
|
1 |
|
]; |
|
564
|
|
|
|
|
565
|
1 |
|
return $this->parseJSON('json', [self::API_CARD_DELETE, $params]); |
|
566
|
|
|
} |
|
567
|
|
|
|
|
568
|
|
|
/** |
|
569
|
|
|
* 设置卡券失效. |
|
570
|
|
|
* |
|
571
|
|
|
* @param string $code |
|
572
|
|
|
* @param string $cardId |
|
573
|
|
|
* |
|
574
|
|
|
* @return array |
|
575
|
|
|
*/ |
|
576
|
1 |
View Code Duplication |
public function disable($code, $cardId = '') |
|
577
|
|
|
{ |
|
578
|
|
|
$params = [ |
|
579
|
1 |
|
'code' => $code, |
|
580
|
1 |
|
'card_id' => $cardId, |
|
581
|
1 |
|
]; |
|
582
|
|
|
|
|
583
|
1 |
|
return $this->parseJSON('json', [self::API_UNAVAILABLE, $params]); |
|
584
|
|
|
} |
|
585
|
|
|
|
|
586
|
|
|
/** |
|
587
|
|
|
* 拉取卡券概况数据接口. |
|
588
|
|
|
* |
|
589
|
|
|
* @param string $beginDate |
|
590
|
|
|
* @param string $endDate |
|
591
|
|
|
* @param int $condSource |
|
592
|
|
|
* |
|
593
|
|
|
* @return array |
|
594
|
|
|
*/ |
|
595
|
1 |
|
public function getCardBizUinInfo($beginDate, $endDate, $condSource = 0) |
|
596
|
|
|
{ |
|
597
|
1 |
|
if (is_numeric($beginDate)) { |
|
598
|
|
|
$beginDate = date('Y-m-d', $beginDate); |
|
599
|
|
|
} |
|
600
|
|
|
|
|
601
|
1 |
|
if (is_numeric($endDate)) { |
|
602
|
|
|
$endDate = date('Y-m-d', $endDate); |
|
603
|
|
|
} |
|
604
|
|
|
|
|
605
|
|
|
$params = [ |
|
606
|
1 |
|
'begin_date' => $beginDate, |
|
607
|
1 |
|
'end_date' => $endDate, |
|
608
|
1 |
|
'cond_source' => intval($condSource), |
|
609
|
1 |
|
]; |
|
610
|
|
|
|
|
611
|
1 |
|
return $this->parseJSON('json', [self::API_CARD_BIZ_UIN_INFO, $params]); |
|
612
|
|
|
} |
|
613
|
|
|
|
|
614
|
|
|
/** |
|
615
|
|
|
* 获取免费券数据接口. |
|
616
|
|
|
* |
|
617
|
|
|
* @param string $beginDate |
|
618
|
|
|
* @param string $endDate |
|
619
|
|
|
* @param int $condSource |
|
620
|
|
|
* @param string $cardId |
|
621
|
|
|
* |
|
622
|
|
|
* @return array |
|
623
|
|
|
*/ |
|
624
|
1 |
View Code Duplication |
public function getFreeCardInfo($beginDate, $endDate, $condSource = 0, $cardId = '') |
|
625
|
|
|
{ |
|
626
|
|
|
$params = [ |
|
627
|
1 |
|
'begin_date' => $beginDate, |
|
628
|
1 |
|
'end_date' => $endDate, |
|
629
|
1 |
|
'cond_source' => intval($condSource), |
|
630
|
1 |
|
'card_id' => $cardId, |
|
631
|
1 |
|
]; |
|
632
|
|
|
|
|
633
|
1 |
|
return $this->parseJSON('json', [self::API_CARD_CARD_INFO, $params]); |
|
634
|
|
|
} |
|
635
|
|
|
|
|
636
|
|
|
/** |
|
637
|
|
|
* 拉取会员卡数据接口. |
|
638
|
|
|
* |
|
639
|
|
|
* @param string $beginDate |
|
640
|
|
|
* @param string $endDate |
|
641
|
|
|
* @param int $condSource |
|
642
|
|
|
* |
|
643
|
|
|
* @return array |
|
644
|
|
|
*/ |
|
645
|
1 |
View Code Duplication |
public function getMemberCardInfo($beginDate, $endDate, $condSource = 0) |
|
646
|
|
|
{ |
|
647
|
|
|
$params = [ |
|
648
|
1 |
|
'begin_date' => $beginDate, |
|
649
|
1 |
|
'end_date' => $endDate, |
|
650
|
1 |
|
'cond_source' => intval($condSource), |
|
651
|
1 |
|
]; |
|
652
|
|
|
|
|
653
|
1 |
|
return $this->parseJSON('json', [self::API_CARD_MEMBER_CARD_INFO, $params]); |
|
654
|
|
|
} |
|
655
|
|
|
|
|
656
|
|
|
/** |
|
657
|
|
|
* 会员卡接口激活. |
|
658
|
|
|
* |
|
659
|
|
|
* @param array $activate |
|
660
|
|
|
* |
|
661
|
|
|
* @return array |
|
662
|
|
|
*/ |
|
663
|
1 |
|
public function activate($activate = []) |
|
664
|
|
|
{ |
|
665
|
1 |
|
return $this->parseJSON('json', [self::API_CARD_ACTIVATE, $activate]); |
|
666
|
|
|
} |
|
667
|
|
|
|
|
668
|
|
|
/** |
|
669
|
|
|
* 设置开卡字段接口. |
|
670
|
|
|
* |
|
671
|
|
|
* @param string $cardId |
|
672
|
|
|
* @param array $requiredForm |
|
673
|
|
|
* @param array $optionalForm |
|
674
|
|
|
* |
|
675
|
|
|
* @return array |
|
676
|
|
|
*/ |
|
677
|
1 |
|
public function activateUserForm($cardId, $requiredForm = [], $optionalForm = []) |
|
678
|
|
|
{ |
|
679
|
1 |
|
$card = []; |
|
680
|
1 |
|
$card['card_id'] = $cardId; |
|
681
|
|
|
|
|
682
|
1 |
|
$params = array_merge($card, $requiredForm, $optionalForm); |
|
683
|
|
|
|
|
684
|
1 |
|
return $this->parseJSON('json', [self::API_ACTIVATE_USER_FORM, $params]); |
|
685
|
|
|
} |
|
686
|
|
|
|
|
687
|
|
|
/** |
|
688
|
|
|
* 拉取会员信息接口. |
|
689
|
|
|
* |
|
690
|
|
|
* @param string $cardId |
|
691
|
|
|
* @param string $code |
|
692
|
|
|
* |
|
693
|
|
|
* @return array |
|
694
|
|
|
*/ |
|
695
|
1 |
View Code Duplication |
public function getMemberCardUser($cardId, $code) |
|
696
|
|
|
{ |
|
697
|
|
|
$params = [ |
|
698
|
1 |
|
'card_id' => $cardId, |
|
699
|
1 |
|
'code' => $code, |
|
700
|
1 |
|
]; |
|
701
|
|
|
|
|
702
|
1 |
|
return $this->parseJSON('json', [self::API_MEMBER_USER_INFO, $params]); |
|
703
|
|
|
} |
|
704
|
|
|
|
|
705
|
|
|
/** |
|
706
|
|
|
* 更新会员信息. |
|
707
|
|
|
* |
|
708
|
|
|
* @param array $updateUser |
|
709
|
|
|
* |
|
710
|
|
|
* @return array |
|
711
|
|
|
*/ |
|
712
|
1 |
|
public function updateMemberCardUser($updateUser = []) |
|
713
|
|
|
{ |
|
714
|
1 |
|
$params = $updateUser; |
|
715
|
|
|
|
|
716
|
1 |
|
return $this->parseJSON('json', [self::API_UPDATE_USER, $params]); |
|
717
|
|
|
} |
|
718
|
|
|
|
|
719
|
|
|
/** |
|
720
|
|
|
* 添加子商户. |
|
721
|
|
|
* |
|
722
|
|
|
* @param string $brandName |
|
723
|
|
|
* @param string $logoUrl |
|
724
|
|
|
* @param string $protocol |
|
725
|
|
|
* @param int $endTime |
|
726
|
|
|
* @param int $primaryCategoryId |
|
727
|
|
|
* @param int $secondaryCategoryId |
|
728
|
|
|
* @param string $agreementMediaId |
|
729
|
|
|
* @param string $operatorMediaId |
|
730
|
|
|
* @param string $appId |
|
731
|
|
|
* |
|
732
|
|
|
* @return array |
|
733
|
|
|
*/ |
|
734
|
1 |
|
public function subMerchant($brandName, $logoUrl, $protocol, $endTime, $primaryCategoryId, $secondaryCategoryId, $agreementMediaId, $operatorMediaId, $appId = '') |
|
735
|
|
|
{ |
|
736
|
|
|
$params = [ |
|
737
|
|
|
'info' => [ |
|
738
|
1 |
|
'brand_name' => $brandName, |
|
739
|
1 |
|
'logo_url' => $logoUrl, |
|
740
|
1 |
|
'protocol' => $protocol, |
|
741
|
1 |
|
'end_time' => $endTime, |
|
742
|
1 |
|
'primary_category_id' => $primaryCategoryId, |
|
743
|
1 |
|
'secondary_category_id' => $secondaryCategoryId, |
|
744
|
1 |
|
'agreement_media_id' => $agreementMediaId, |
|
745
|
1 |
|
'operator_media_id' => $operatorMediaId, |
|
746
|
1 |
|
'app_id' => $appId, |
|
747
|
1 |
|
], |
|
748
|
1 |
|
]; |
|
749
|
|
|
|
|
750
|
1 |
|
return $this->parseJSON('json', [self::API_SUB_MERCHANT, $params]); |
|
751
|
|
|
} |
|
752
|
|
|
|
|
753
|
|
|
/** |
|
754
|
|
|
* 卡券开放类目查询接口. |
|
755
|
|
|
* |
|
756
|
|
|
* @return array|bool |
|
757
|
|
|
*/ |
|
758
|
1 |
|
public function getApplyProtocol() |
|
759
|
|
|
{ |
|
760
|
1 |
|
return $this->parseJSON('get', [self::API_GET_APPLY_PROTOCOL]); |
|
761
|
|
|
} |
|
762
|
|
|
|
|
763
|
|
|
/** |
|
764
|
|
|
* Set cache manager. |
|
765
|
|
|
* |
|
766
|
|
|
* @param \Doctrine\Common\Cache\Cache $cache |
|
767
|
|
|
* |
|
768
|
|
|
* @return $this |
|
769
|
|
|
*/ |
|
770
|
2 |
|
public function setCache(Cache $cache) |
|
771
|
|
|
{ |
|
772
|
2 |
|
$this->cache = $cache; |
|
773
|
|
|
|
|
774
|
2 |
|
return $this; |
|
775
|
|
|
} |
|
776
|
|
|
|
|
777
|
|
|
/** |
|
778
|
|
|
* Return cache manager. |
|
779
|
|
|
* |
|
780
|
|
|
* @return \Doctrine\Common\Cache\Cache |
|
781
|
|
|
*/ |
|
782
|
2 |
|
public function getCache() |
|
783
|
|
|
{ |
|
784
|
2 |
|
return $this->cache ?: $this->cache = new FilesystemCache(sys_get_temp_dir()); |
|
785
|
|
|
} |
|
786
|
|
|
|
|
787
|
|
|
/** |
|
788
|
|
|
* Set current url. |
|
789
|
|
|
* |
|
790
|
|
|
* @param string $url |
|
791
|
|
|
* |
|
792
|
|
|
* @return array |
|
793
|
|
|
*/ |
|
794
|
1 |
|
public function setUrl($url) |
|
795
|
|
|
{ |
|
796
|
1 |
|
$this->url = $url; |
|
|
|
|
|
|
797
|
|
|
|
|
798
|
1 |
|
return $this; |
|
799
|
|
|
} |
|
800
|
|
|
} |
|
801
|
|
|
|