processor.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. class PaycenterModuleProcessor extends WeModuleProcessor {
  8. public function respond() {
  9. global $_W;
  10. $rid = $this->rule;
  11. $reply = table('wxcard_reply')
  12. ->where(array('rid' => $rid))
  13. ->orderby('RAND()')
  14. ->get();
  15. if (empty($reply)) {
  16. return false;
  17. }
  18. load()->classs('weixin.account');
  19. load()->classs('coupon');
  20. $coupon = new coupon($_W['acid']);
  21. if (is_error($coupon)) {
  22. $this->error($reply, $coupon['message']);
  23. die;
  24. }
  25. $card = $coupon->BuildCardExt($reply['cid']);
  26. if (is_error($card)) {
  27. $this->error($reply, $card['message']);
  28. die;
  29. }
  30. $data = array(
  31. 'touser' => $_W['openid'],
  32. 'msgtype' => 'wxcard',
  33. 'wxcard' => array(
  34. 'card_id' => $card['card_id'],
  35. 'card_ext' => $card['card_ext'],
  36. ),
  37. );
  38. $acc = WeAccount::createByUniacid();
  39. $status = $acc->sendCustomNotice($data);
  40. if (is_error($status)) {
  41. $this->error($reply, $status['message']);
  42. die;
  43. }
  44. if (!empty($reply['success'])) {
  45. return $this->respText($reply['success']);
  46. die;
  47. }
  48. return true;
  49. }
  50. public function error($reply, $msg) {
  51. if (empty($reply['error'])) {
  52. if (empty($msg)) {
  53. return true;
  54. }
  55. return $this->respText($msg);
  56. } else {
  57. return $this->respText($reply['error']);
  58. }
  59. }
  60. }