processor.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 WxcardModuleProcessor extends WeModuleProcessor {
  8. public function respond() {
  9. global $_W;
  10. $rid = $this->rule;
  11. $reply = table('wxcard_reply')->where(array('rid' => $rid))->orderby('RAND()')->get();
  12. if (empty($reply)) {
  13. return false;
  14. }
  15. load()->classs('weixin.account');
  16. load()->classs('coupon');
  17. $coupon = new coupon($_W['acid']);
  18. if (is_error($coupon)) {
  19. $this->error($reply, $coupon['message']);
  20. die;
  21. }
  22. $card = $coupon->BuildCardExt($reply['cid']);
  23. if (is_error($card)) {
  24. $this->error($reply, $card['message']);
  25. die;
  26. }
  27. $data = array(
  28. 'touser' => $_W['openid'],
  29. 'msgtype' => 'wxcard',
  30. 'wxcard' => array(
  31. 'card_id' => $card['card_id'],
  32. 'card_ext' => $card['card_ext'],
  33. ),
  34. );
  35. $acc = WeAccount::createByUniacid();
  36. $status = $acc->sendCustomNotice($data);
  37. if (is_error($status)) {
  38. $this->error($reply, $status['message']);
  39. die;
  40. }
  41. if (!empty($reply['success'])) {
  42. return $this->respText($reply['success']);
  43. die;
  44. }
  45. return true;
  46. }
  47. public function error($reply, $msg) {
  48. if (empty($reply['error'])) {
  49. if (empty($msg)) {
  50. return true;
  51. }
  52. return $this->respText($msg);
  53. } else {
  54. return $this->respText($reply['error']);
  55. }
  56. }
  57. }