processor.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 ChatsModuleProcessor extends WeModuleProcessor {
  8. public $priority = 255;
  9. public function begin($expire = 300) {
  10. $this->beginContext($expire);
  11. return true;
  12. }
  13. public function end() {
  14. $this->respText('系统消息:公众号关闭了对话功能!');
  15. $this->endContext();
  16. return;
  17. }
  18. public function respond() {
  19. global $_W;
  20. $msgtype = $this->message['type'];
  21. $allow = array('text', 'image', 'location', 'link', 'trace');
  22. if(!in_array($msgtype, $allow)) {
  23. return $this->respText('抱歉,系统仅支持 文字,图片,地理位置,链接类型的消息!');
  24. }
  25. $close = 0;
  26. if($msgtype == 'text') {
  27. $content = $this->message['content'];
  28. if($content == '关闭') {
  29. $content = '<span class="text-danger">系统消息:粉丝关闭了对话</span>';
  30. $close = 1;
  31. }
  32. } elseif($msgtype == 'image') {
  33. $content = $this->message['picurl'];
  34. } elseif($msgtype == 'location') {
  35. $content = iserializer(array(
  36. 'location_x' => $this->message['location_x'],
  37. 'location_y' => $this->message['location_y'],
  38. 'scale' => $this->message['scale'],
  39. ));
  40. } elseif($msgtype == 'link') {
  41. $content = $this->message['url'];
  42. }
  43. if(!empty($content)) {
  44. $insert = array(
  45. 'uniacid' => $_W['uniacid'],
  46. 'acid' => $_W['acid'],
  47. 'openid' => $_W['openid'],
  48. 'msgtype' => $msgtype,
  49. 'flag' => 2,
  50. 'content' => $content,
  51. 'createtime' => TIMESTAMP
  52. );
  53. pdo_insert('mc_chats_record', $insert);
  54. }
  55. $this->refreshContext(300);
  56. if($close == 1) {
  57. $this->endContext();
  58. return $this->respText('您成功关闭回话。');
  59. }
  60. return $this->respText('');
  61. }
  62. }