processor.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. $sql = "SELECT * FROM " . tablename('wxcard_reply') . " WHERE rid = :rid ORDER BY RAND() LIMIT 1";
  12. $reply = pdo_fetch($sql, array(':rid' => $rid));
  13. if (empty($reply)) {
  14. return false;
  15. }
  16. load()->classs('weixin.account');
  17. load()->classs('coupon');
  18. $coupon = new coupon($_W['acid']);
  19. if(is_error($coupon)) {
  20. $this->error($reply, $coupon['message']);
  21. die;
  22. }
  23. $card = $coupon->BuildCardExt($reply['cid']);
  24. if(is_error($card)) {
  25. $this->error($reply, $card['message']);
  26. die;
  27. }
  28. $data = array(
  29. 'touser' => $_W['openid'],
  30. 'msgtype' => 'wxcard',
  31. 'wxcard' => array(
  32. 'card_id' => $card['card_id'],
  33. 'card_ext' => $card['card_ext'],
  34. )
  35. );
  36. $acc = WeAccount::createByUniacid();
  37. $status = $acc->sendCustomNotice($data);
  38. if(is_error($status)) {
  39. $this->error($reply, $status['message']);
  40. die;
  41. }
  42. if(!empty($reply['success'])) {
  43. return $this->respText($reply['success']);
  44. die;
  45. }
  46. return true;
  47. }
  48. public function error($reply, $msg) {
  49. if(empty($reply['error'])) {
  50. if(empty($msg)) {
  51. return true;
  52. }
  53. return $this->respText($msg);
  54. } else {
  55. return $this->respText($reply['error']);
  56. }
  57. }
  58. }