Card.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2023 ThinkAdmin [ thinkadmin.top ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免责声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/WeChatDeveloper
  13. // | github 代码仓库:https://github.com/zoujingli/WeChatDeveloper
  14. // +----------------------------------------------------------------------
  15. namespace WeChat;
  16. use WeChat\Contracts\BasicWeChat;
  17. /**
  18. * 卡券管理
  19. * Class Card
  20. * @package WeChat
  21. */
  22. class Card extends BasicWeChat
  23. {
  24. /**
  25. * 创建卡券
  26. * @param array $data
  27. * @return array
  28. * @throws Exceptions\InvalidResponseException
  29. * @throws Exceptions\LocalCacheException
  30. */
  31. public function create(array $data)
  32. {
  33. $url = "https://api.weixin.qq.com/card/create?access_token=ACCESS_TOKEN";
  34. $this->registerApi($url, __FUNCTION__, func_get_args());
  35. return $this->httpPostForJson($url, $data);
  36. }
  37. /**
  38. * 设置买单接口
  39. * @param string $card_id
  40. * @param bool $is_open
  41. * @return array
  42. * @throws Exceptions\InvalidResponseException
  43. * @throws Exceptions\LocalCacheException
  44. */
  45. public function setPaycell($card_id, $is_open = true)
  46. {
  47. $url = "https://api.weixin.qq.com/card/paycell/set?access_token=ACCESS_TOKEN";
  48. $this->registerApi($url, __FUNCTION__, func_get_args());
  49. return $this->httpPostForJson($url, ['card_id' => $card_id, 'is_open' => $is_open]);
  50. }
  51. /**
  52. * 设置自助核销接口
  53. * @param string $card_id
  54. * @param bool $is_open
  55. * @return array
  56. * @throws Exceptions\InvalidResponseException
  57. * @throws Exceptions\LocalCacheException
  58. */
  59. public function setConsumeCell($card_id, $is_open = true)
  60. {
  61. $url = "https://api.weixin.qq.com/card/selfconsumecell/set?access_token=ACCESS_TOKEN";
  62. $this->registerApi($url, __FUNCTION__, func_get_args());
  63. return $this->httpPostForJson($url, ['card_id' => $card_id, 'is_open' => $is_open]);
  64. }
  65. /**
  66. * 创建二维码接口
  67. * @param array $data
  68. * @return array
  69. * @throws Exceptions\InvalidResponseException
  70. * @throws Exceptions\LocalCacheException
  71. */
  72. public function createQrc(array $data)
  73. {
  74. $url = "https://api.weixin.qq.com/card/qrcode/create?access_token=ACCESS_TOKEN";
  75. $this->registerApi($url, __FUNCTION__, func_get_args());
  76. return $this->httpPostForJson($url, $data);
  77. }
  78. /**
  79. * 创建货架接口
  80. * @param array $data
  81. * @return array
  82. * @throws Exceptions\InvalidResponseException
  83. * @throws Exceptions\LocalCacheException
  84. */
  85. public function createLandingPage(array $data)
  86. {
  87. $url = "https://api.weixin.qq.com/card/landingpage/create?access_token=ACCESS_TOKEN";
  88. $this->registerApi($url, __FUNCTION__, func_get_args());
  89. return $this->httpPostForJson($url, $data);
  90. }
  91. /**
  92. * 导入自定义code
  93. * @param string $card_id
  94. * @param array $code
  95. * @return array
  96. * @throws Exceptions\InvalidResponseException
  97. * @throws Exceptions\LocalCacheException
  98. */
  99. public function deposit($card_id, array $code)
  100. {
  101. $url = "https://api.weixin.qq.com/card/code/deposit?access_token=ACCESS_TOKEN";
  102. $this->registerApi($url, __FUNCTION__, func_get_args());
  103. return $this->httpPostForJson($url, ['card_id' => $card_id, 'code' => $code]);
  104. }
  105. /**
  106. * 查询导入code数目
  107. * @param string $card_id
  108. * @return array
  109. * @throws Exceptions\InvalidResponseException
  110. * @throws Exceptions\LocalCacheException
  111. */
  112. public function getDepositCount($card_id)
  113. {
  114. $url = "https://api.weixin.qq.com/card/code/getdepositcount?access_token=ACCESS_TOKEN";
  115. $this->registerApi($url, __FUNCTION__, func_get_args());
  116. return $this->httpPostForJson($url, ['card_id' => $card_id]);
  117. }
  118. /**
  119. * 核查code接口
  120. * @param string $card_id 进行导入code的卡券ID
  121. * @param array $code 已经微信卡券后台的自定义code,上限为100个
  122. * @return array
  123. * @throws Exceptions\InvalidResponseException
  124. * @throws Exceptions\LocalCacheException
  125. */
  126. public function checkCode($card_id, array $code)
  127. {
  128. $url = "https://api.weixin.qq.com/card/code/checkcode?access_token=ACCESS_TOKEN";
  129. $this->registerApi($url, __FUNCTION__, func_get_args());
  130. return $this->httpPostForJson($url, ['card_id' => $card_id, 'code' => $code]);
  131. }
  132. /**
  133. * 图文消息群发卡券
  134. * @param string $card_id
  135. * @return array
  136. * @throws Exceptions\InvalidResponseException
  137. * @throws Exceptions\LocalCacheException
  138. */
  139. public function getNewsHtml($card_id)
  140. {
  141. $url = "https://api.weixin.qq.com/card/mpnews/gethtml?access_token=ACCESS_TOKEN";
  142. $this->registerApi($url, __FUNCTION__, func_get_args());
  143. return $this->httpPostForJson($url, ['card_id' => $card_id]);
  144. }
  145. /**
  146. * 设置测试白名单
  147. * @param array $openids
  148. * @param array $usernames
  149. * @return array
  150. * @throws Exceptions\InvalidResponseException
  151. * @throws Exceptions\LocalCacheException
  152. */
  153. public function setTestWhiteList($openids = [], $usernames = [])
  154. {
  155. $url = "https://api.weixin.qq.com/card/testwhitelist/set?access_token=ACCESS_TOKEN";
  156. $this->registerApi($url, __FUNCTION__, func_get_args());
  157. return $this->httpPostForJson($url, ['openid' => $openids, 'username' => $usernames]);
  158. }
  159. /**
  160. * 线下核销查询Code
  161. * @param string $code 单张卡券的唯一标准
  162. * @param string $card_id 卡券ID代表一类卡券。自定义code卡券必填
  163. * @param bool $check_consume 是否校验code核销状态,填入true和false时的code异常状态返回数据不同
  164. * @return array
  165. * @throws Exceptions\InvalidResponseException
  166. * @throws Exceptions\LocalCacheException
  167. */
  168. public function getCode($code, $card_id = null, $check_consume = null)
  169. {
  170. $data = ['code' => $code];
  171. is_null($card_id) || $data['card_id'] = $card_id;
  172. is_null($check_consume) || $data['check_consume'] = $check_consume;
  173. $url = "https://api.weixin.qq.com/card/code/get?access_token=ACCESS_TOKEN";
  174. $this->registerApi($url, __FUNCTION__, func_get_args());
  175. return $this->httpPostForJson($url, $data);
  176. }
  177. /**
  178. * 线下核销核销Code
  179. * @param string $code 需核销的Code码
  180. * @param null $card_id 券ID。创建卡券时use_custom_code填写true时必填。非自定义Code不必填写
  181. * @return array
  182. * @throws Exceptions\InvalidResponseException
  183. * @throws Exceptions\LocalCacheException
  184. */
  185. public function consume($code, $card_id = null)
  186. {
  187. $data = ['code' => $code];
  188. is_null($card_id) || $data['card_id'] = $card_id;
  189. $url = "https://api.weixin.qq.com/card/code/consume?access_token=ACCESS_TOKEN";
  190. $this->registerApi($url, __FUNCTION__, func_get_args());
  191. return $this->httpPostForJson($url, $data);
  192. }
  193. /**
  194. * Code解码接口
  195. * @param string $encrypt_code
  196. * @return array
  197. * @throws Exceptions\InvalidResponseException
  198. * @throws Exceptions\LocalCacheException
  199. */
  200. public function decrypt($encrypt_code)
  201. {
  202. $url = "https://api.weixin.qq.com/card/code/decrypt?access_token=ACCESS_TOKEN";
  203. $this->registerApi($url, __FUNCTION__, func_get_args());
  204. return $this->httpPostForJson($url, ['encrypt_code' => $encrypt_code]);
  205. }
  206. /**
  207. * 获取用户已领取卡券接口
  208. * @param string $openid
  209. * @param null|string $card_id
  210. * @return array
  211. * @throws Exceptions\InvalidResponseException
  212. * @throws Exceptions\LocalCacheException
  213. */
  214. public function getCardList($openid, $card_id = null)
  215. {
  216. $data = ['openid' => $openid];
  217. is_null($card_id) || $data['card_id'] = $card_id;
  218. $url = "https://api.weixin.qq.com/card/user/getcardlist?access_token=ACCESS_TOKEN";
  219. $this->registerApi($url, __FUNCTION__, func_get_args());
  220. return $this->httpPostForJson($url, $data);
  221. }
  222. /**
  223. * 查看卡券详情
  224. * @param string $card_id
  225. * @return array
  226. * @throws Exceptions\InvalidResponseException
  227. * @throws Exceptions\LocalCacheException
  228. */
  229. public function getCard($card_id)
  230. {
  231. $url = "https://api.weixin.qq.com/card/get?access_token=ACCESS_TOKEN";
  232. $this->registerApi($url, __FUNCTION__, func_get_args());
  233. return $this->httpPostForJson($url, ['card_id' => $card_id]);
  234. }
  235. /**
  236. * 批量查询卡券列表
  237. * @param int $offset 查询卡列表的起始偏移量,从0开始,即offset: 5是指从从列表里的第六个开始读取
  238. * @param int $count 需要查询的卡片的数量(数量最大50)
  239. * @param array $status_list 支持开发者拉出指定状态的卡券列表
  240. * @return array
  241. * @throws Exceptions\InvalidResponseException
  242. * @throws Exceptions\LocalCacheException
  243. */
  244. public function batchGet($offset, $count = 50, array $status_list = [])
  245. {
  246. $data = ['offset' => $offset, 'count' => $count];
  247. empty($status_list) || $data['status_list'] = $status_list;
  248. $url = "https://api.weixin.qq.com/card/batchget?access_token=ACCESS_TOKEN";
  249. $this->registerApi($url, __FUNCTION__, func_get_args());
  250. return $this->httpPostForJson($url, $data);
  251. }
  252. /**
  253. * 更改卡券信息接口
  254. * @param string $card_id
  255. * @param array $member_card
  256. * @return array
  257. * @throws Exceptions\InvalidResponseException
  258. * @throws Exceptions\LocalCacheException
  259. */
  260. public function updateCard($card_id, array $member_card)
  261. {
  262. $url = "https://api.weixin.qq.com/card/update?access_token=ACCESS_TOKEN";
  263. $this->registerApi($url, __FUNCTION__, func_get_args());
  264. return $this->httpPostForJson($url, ['card_id' => $card_id, 'member_card' => $member_card]);
  265. }
  266. /**
  267. * 修改库存接口
  268. * @param string $card_id 卡券ID
  269. * @param null|integer $increase_stock_value 增加多少库存,支持不填或填0
  270. * @param null|integer $reduce_stock_value 减少多少库存,可以不填或填0
  271. * @return array
  272. * @throws Exceptions\InvalidResponseException
  273. * @throws Exceptions\LocalCacheException
  274. */
  275. public function modifyStock($card_id, $increase_stock_value = null, $reduce_stock_value = null)
  276. {
  277. $data = ['card_id' => $card_id];
  278. is_null($increase_stock_value) || $data['increase_stock_value'] = $increase_stock_value;
  279. is_null($reduce_stock_value) || $data['reduce_stock_value'] = $reduce_stock_value;
  280. $url = "https://api.weixin.qq.com/card/modifystock?access_token=ACCESS_TOKEN";
  281. $this->registerApi($url, __FUNCTION__, func_get_args());
  282. return $this->httpPostForJson($url, $data);
  283. }
  284. /**
  285. * 更改Code接口
  286. * @param string $code 需变更的Code码
  287. * @param string $new_code 变更后的有效Code码
  288. * @param null|string $card_id 卡券ID
  289. * @return array
  290. * @throws Exceptions\InvalidResponseException
  291. * @throws Exceptions\LocalCacheException
  292. */
  293. public function updateCode($code, $new_code, $card_id = null)
  294. {
  295. $data = ['code' => $code, 'new_code' => $new_code];
  296. is_null($card_id) || $data['card_id'] = $card_id;
  297. $url = "https://api.weixin.qq.com/card/code/update?access_token=ACCESS_TOKEN";
  298. $this->registerApi($url, __FUNCTION__, func_get_args());
  299. return $this->httpPostForJson($url, $data);
  300. }
  301. /**
  302. * 删除卡券接口
  303. * @param string $card_id
  304. * @return array
  305. * @throws Exceptions\InvalidResponseException
  306. * @throws Exceptions\LocalCacheException
  307. */
  308. public function deleteCard($card_id)
  309. {
  310. $url = "https://api.weixin.qq.com/card/delete?access_token=ACCESS_TOKEN";
  311. $this->registerApi($url, __FUNCTION__, func_get_args());
  312. return $this->httpPostForJson($url, ['card_id' => $card_id]);
  313. }
  314. /**
  315. * 设置卡券失效接口
  316. * @param string $code
  317. * @param string $card_id
  318. * @param null|string $reason
  319. * @return array
  320. * @throws Exceptions\InvalidResponseException
  321. * @throws Exceptions\LocalCacheException
  322. */
  323. public function unAvailable($code, $card_id, $reason = null)
  324. {
  325. $data = ['code' => $code, 'card_id' => $card_id];
  326. is_null($reason) || $data['reason'] = $reason;
  327. $url = "https://api.weixin.qq.com/card/code/unavailable?access_token=ACCESS_TOKEN";
  328. $this->registerApi($url, __FUNCTION__, func_get_args());
  329. return $this->httpPostForJson($url, $data);
  330. }
  331. /**
  332. * 拉取卡券概况数据接口
  333. * @param string $begin_date 查询数据的起始时间
  334. * @param string $end_date 查询数据的截至时间
  335. * @param string $cond_source 卡券来源(0为公众平台创建的卡券数据 1是API创建的卡券数据)
  336. * @return array
  337. * @throws Exceptions\InvalidResponseException
  338. * @throws Exceptions\LocalCacheException
  339. */
  340. public function getCardBizuininfo($begin_date, $end_date, $cond_source)
  341. {
  342. $data = ['begin_date' => $begin_date, 'end_date' => $end_date, 'cond_source' => $cond_source];
  343. $url = "https://api.weixin.qq.com/datacube/getcardbizuininfo?access_token=ACCESS_TOKEN";
  344. $this->registerApi($url, __FUNCTION__, func_get_args());
  345. return $this->httpPostForJson($url, $data);
  346. }
  347. /**
  348. * 获取免费券数据接口
  349. * @param string $begin_date 查询数据的起始时间
  350. * @param string $end_date 查询数据的截至时间
  351. * @param integer $cond_source 卡券来源,0为公众平台创建的卡券数据、1是API创建的卡券数据
  352. * @param null $card_id 卡券ID
  353. * @return array
  354. * @throws Exceptions\InvalidResponseException
  355. * @throws Exceptions\LocalCacheException
  356. */
  357. public function getCardCardinfo($begin_date, $end_date, $cond_source, $card_id = null)
  358. {
  359. $data = ['begin_date' => $begin_date, 'end_date' => $end_date, 'cond_source' => $cond_source];
  360. is_null($card_id) || $data['card_id'] = $card_id;
  361. $url = "https://api.weixin.qq.com/datacube/getcardcardinfo?access_token=ACCESS_TOKEN";
  362. $this->registerApi($url, __FUNCTION__, func_get_args());
  363. return $this->httpPostForJson($url, $data);
  364. }
  365. /**
  366. * 激活会员卡
  367. * @param array $data
  368. * @return array
  369. * @throws Exceptions\InvalidResponseException
  370. * @throws Exceptions\LocalCacheException
  371. */
  372. public function activateMemberCard(array $data)
  373. {
  374. $url = 'https://api.weixin.qq.com/card/membercard/activate?access_token=ACCESS_TOKEN';
  375. $this->registerApi($url, __FUNCTION__, func_get_args());
  376. return $this->httpPostForJson($url, $data);
  377. }
  378. /**
  379. * 设置开卡字段接口
  380. * 用户激活时需要填写的选项
  381. * @param array $data
  382. * @return array
  383. * @throws Exceptions\InvalidResponseException
  384. * @throws Exceptions\LocalCacheException
  385. */
  386. public function setActivateMemberCardUser(array $data)
  387. {
  388. $url = 'https://api.weixin.qq.com/card/membercard/activateuserform/set?access_token=ACCESS_TOKEN';
  389. $this->registerApi($url, __FUNCTION__, func_get_args());
  390. return $this->httpPostForJson($url, $data);
  391. }
  392. /**
  393. * 获取用户提交资料
  394. * 根据activate_ticket获取到用户填写的信息
  395. * @param string $activate_ticket
  396. * @return array
  397. * @throws Exceptions\InvalidResponseException
  398. * @throws Exceptions\LocalCacheException
  399. */
  400. public function getActivateMemberCardTempinfo($activate_ticket)
  401. {
  402. $url = 'https://api.weixin.qq.com/card/membercard/activatetempinfo/get?access_token=ACCESS_TOKEN';
  403. $this->registerApi($url, __FUNCTION__, func_get_args());
  404. return $this->httpPostForJson($url, ['activate_ticket' => $activate_ticket]);
  405. }
  406. /**
  407. * 更新会员信息
  408. * @param array $data
  409. * @return array
  410. * @throws Exceptions\InvalidResponseException
  411. * @throws Exceptions\LocalCacheException
  412. */
  413. public function updateMemberCardUser(array $data)
  414. {
  415. $url = 'https://api.weixin.qq.com/card/membercard/updateuser?access_token=ACCESS_TOKEN';
  416. $this->registerApi($url, __FUNCTION__, func_get_args());
  417. return $this->httpPostForJson($url, $data);
  418. }
  419. /**
  420. * 拉取会员卡概况数据接口
  421. * @param string $begin_date 查询数据的起始时间
  422. * @param string $end_date 查询数据的截至时间
  423. * @param string $cond_source 卡券来源(0为公众平台创建的卡券数据 1是API创建的卡券数据)
  424. * @return array
  425. * @throws Exceptions\InvalidResponseException
  426. * @throws Exceptions\LocalCacheException
  427. */
  428. public function getCardMemberCardinfo($begin_date, $end_date, $cond_source)
  429. {
  430. $data = ['begin_date' => $begin_date, 'end_date' => $end_date, 'cond_source' => $cond_source];
  431. $url = "https://api.weixin.qq.com/datacube/getcardmembercardinfo?access_token=ACCESS_TOKEN";
  432. $this->registerApi($url, __FUNCTION__, func_get_args());
  433. return $this->httpPostForJson($url, $data);
  434. }
  435. /**
  436. * 拉取单张会员卡数据接口
  437. * @param string $begin_date 查询数据的起始时间
  438. * @param string $end_date 查询数据的截至时间
  439. * @param string $card_id 卡券id
  440. * @return array
  441. * @throws Exceptions\InvalidResponseException
  442. * @throws Exceptions\LocalCacheException
  443. */
  444. public function getCardMemberCardDetail($begin_date, $end_date, $card_id)
  445. {
  446. $data = ['begin_date' => $begin_date, 'end_date' => $end_date, 'card_id' => $card_id];
  447. $url = "https://api.weixin.qq.com/datacube/getcardmembercarddetail?access_token=ACCESS_TOKEN";
  448. $this->registerApi($url, __FUNCTION__, func_get_args());
  449. return $this->httpPostForJson($url, $data);
  450. }
  451. /**
  452. * 拉取会员信息(积分查询)接口
  453. * @param string $card_id 查询会员卡的cardid
  454. * @param string $code 所查询用户领取到的code值
  455. * @return array
  456. * @throws Exceptions\InvalidResponseException
  457. * @throws Exceptions\LocalCacheException
  458. */
  459. public function getCardMemberCard($card_id, $code)
  460. {
  461. $data = ['card_id' => $card_id, 'code' => $code];
  462. $url = "https://api.weixin.qq.com/card/membercard/userinfo/get?access_token=ACCESS_TOKEN";
  463. $this->registerApi($url, __FUNCTION__, func_get_args());
  464. return $this->httpPostForJson($url, $data);
  465. }
  466. /**
  467. * 设置支付后投放卡券接口
  468. * @param array $data
  469. * @return array
  470. * @throws Exceptions\InvalidResponseException
  471. * @throws Exceptions\LocalCacheException
  472. */
  473. public function payGiftCard(array $data)
  474. {
  475. $url = "https://api.weixin.qq.com/card/paygiftcard/add?access_token=ACCESS_TOKEN";
  476. $this->registerApi($url, __FUNCTION__, func_get_args());
  477. return $this->httpPostForJson($url, $data);
  478. }
  479. /**
  480. * 删除支付后投放卡券规则
  481. * @param integer $rule_id 支付即会员的规则名称
  482. * @return array
  483. * @throws Exceptions\InvalidResponseException
  484. * @throws Exceptions\LocalCacheException
  485. */
  486. public function delPayGiftCard($rule_id)
  487. {
  488. $url = "https://api.weixin.qq.com/card/paygiftcard/add?access_token=ACCESS_TOKEN";
  489. $this->registerApi($url, __FUNCTION__, func_get_args());
  490. return $this->httpPostForJson($url, ['rule_id' => $rule_id]);
  491. }
  492. /**
  493. * 查询支付后投放卡券规则详情
  494. * @param integer $rule_id 要查询规则id
  495. * @return array
  496. * @throws Exceptions\InvalidResponseException
  497. * @throws Exceptions\LocalCacheException
  498. */
  499. public function getPayGiftCard($rule_id)
  500. {
  501. $url = "https://api.weixin.qq.com/card/paygiftcard/getbyid?access_token=ACCESS_TOKEN";
  502. $this->registerApi($url, __FUNCTION__, func_get_args());
  503. return $this->httpPostForJson($url, ['rule_id' => $rule_id]);
  504. }
  505. /**
  506. * 批量查询支付后投放卡券规则
  507. * @param integer $offset 起始偏移量
  508. * @param integer $count 查询的数量
  509. * @param bool $effective 是否仅查询生效的规则
  510. * @return array
  511. * @throws Exceptions\InvalidResponseException
  512. * @throws Exceptions\LocalCacheException
  513. */
  514. public function batchGetPayGiftCard($offset = 0, $count = 10, $effective = true)
  515. {
  516. $data = ['type' => 'RULE_TYPE_PAY_MEMBER_CARD', 'offset' => $offset, 'count' => $count, 'effective' => $effective];
  517. $url = "https://api.weixin.qq.com/card/paygiftcard/batchget?access_token=ACCESS_TOKEN";
  518. $this->registerApi($url, __FUNCTION__, func_get_args());
  519. return $this->httpPostForJson($url, $data);
  520. }
  521. /**
  522. * 创建支付后领取立减金活动
  523. * @param array $data
  524. * @return array
  525. * @throws Exceptions\InvalidResponseException
  526. * @throws Exceptions\LocalCacheException
  527. */
  528. public function addActivity(array $data)
  529. {
  530. $url = "https://api.weixin.qq.com/card/mkt/activity/create?access_token=ACCESS_TOKEN";
  531. $this->registerApi($url, __FUNCTION__, func_get_args());
  532. return $this->httpPostForJson($url, $data);
  533. }
  534. /**
  535. * 开通券点账户接口
  536. * @return array
  537. * @throws Exceptions\InvalidResponseException
  538. * @throws Exceptions\LocalCacheException
  539. */
  540. public function payActivate()
  541. {
  542. $url = "https://api.weixin.qq.com/card/pay/activate?access_token=ACCESS_TOKEN";
  543. $this->registerApi($url, __FUNCTION__, func_get_args());
  544. return $this->httpGetForJson($url);
  545. }
  546. /**
  547. * 对优惠券批价
  548. * @param string $card_id 需要来配置库存的card_id
  549. * @param integer $quantity 本次需要兑换的库存数目
  550. * @return array
  551. * @throws Exceptions\InvalidResponseException
  552. * @throws Exceptions\LocalCacheException
  553. */
  554. public function getPayprice($card_id, $quantity)
  555. {
  556. $url = "POST https://api.weixin.qq.com/card/pay/getpayprice?access_token=ACCESS_TOKEN";
  557. $this->registerApi($url, __FUNCTION__, func_get_args());
  558. return $this->httpPostForJson($url, ['card_id' => $card_id, 'quantity' => $quantity]);
  559. }
  560. /**
  561. * 查询券点余额接口
  562. * @return array
  563. * @throws Exceptions\InvalidResponseException
  564. * @throws Exceptions\LocalCacheException
  565. */
  566. public function getCoinsInfo()
  567. {
  568. $url = "https://api.weixin.qq.com/card/pay/getcoinsinfo?access_token=ACCESS_TOKEN";
  569. $this->registerApi($url, __FUNCTION__, func_get_args());
  570. return $this->httpGetForJson($url);
  571. }
  572. /**
  573. * 确认兑换库存接口
  574. * @param string $card_id 需要来兑换库存的card_id
  575. * @param integer $quantity 本次需要兑换的库存数目
  576. * @param string $order_id 仅可以使用上面得到的订单号,保证批价有效性
  577. * @return array
  578. * @throws Exceptions\InvalidResponseException
  579. * @throws Exceptions\LocalCacheException
  580. */
  581. public function payConfirm($card_id, $quantity, $order_id)
  582. {
  583. $data = ['card_id' => $card_id, 'quantity' => $quantity, 'order_id' => $order_id];
  584. $url = "https://api.weixin.qq.com/card/pay/confirm?access_token=ACCESS_TOKEN";
  585. $this->registerApi($url, __FUNCTION__, func_get_args());
  586. return $this->httpPostForJson($url, $data);
  587. }
  588. /**
  589. * 充值券点接口
  590. * @param integer $coin_count
  591. * @return array
  592. * @throws Exceptions\InvalidResponseException
  593. * @throws Exceptions\LocalCacheException
  594. */
  595. public function payRecharge($coin_count)
  596. {
  597. $url = "https://api.weixin.qq.com/card/pay/recharge?access_token=ACCESS_TOKEN";
  598. $this->registerApi($url, __FUNCTION__, func_get_args());
  599. return $this->httpPostForJson($url, ['coin_count' => $coin_count]);
  600. }
  601. /**
  602. * 查询订单详情接口
  603. * @param string $order_id
  604. * @return array
  605. * @throws Exceptions\InvalidResponseException
  606. * @throws Exceptions\LocalCacheException
  607. */
  608. public function payGetOrder($order_id)
  609. {
  610. $url = "https://api.weixin.qq.com/card/pay/getorder?access_token=ACCESS_TOKEN";
  611. $this->registerApi($url, __FUNCTION__, func_get_args());
  612. return $this->httpPostForJson($url, ['order_id' => $order_id]);
  613. }
  614. /**
  615. * 查询券点流水详情接口
  616. * @param array $data
  617. * @return array
  618. * @throws Exceptions\InvalidResponseException
  619. * @throws Exceptions\LocalCacheException
  620. */
  621. public function payGetList(array $data)
  622. {
  623. $url = "https://api.weixin.qq.com/card/pay/getorderlist?access_token=ACCESS_TOKEN";
  624. $this->registerApi($url, __FUNCTION__, func_get_args());
  625. return $this->httpPostForJson($url, $data);
  626. }
  627. }