1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13:
14: class WxRobot_Cmd_Event_User{
15:
16: 17: 18:
19: public static $_instance = null;
20:
21: public $callback = array('today','n', 'h', 'r', '?');
22:
23: 24: 25: 26: 27:
28: public function __construct(){
29: $this->extends = WxRobot_Extends::instance();
30: $this->wxSdk = WxRobot_SDK::instance();
31: }
32:
33: 34: 35: 36: 37:
38: public static function instance(){
39: if( is_null (self::$_instance)){
40: self::$_instance = new self();
41: }
42: return self::$_instance;
43: }
44:
45: 46: 47: 48: 49: 50:
51: public function setValue($obj){
52: $this->obj = $obj;
53: }
54:
55: 56: 57: 58: 59: 60:
61: public function go($key){
62: $data = WxRobot_Table_Menu::instance()->weixin_get_menu_data();
63:
64: if($data){
65: foreach($data as $k=>$v){
66: if($key == $v['menu_key']){
67: return $this->choose($v['menu_callback'], $v['menu_name']);
68: }
69: }
70: }
71:
72: return $this->obj->help_info('key:'.$key."\n".'用户自定菜单响应未定义?');
73: }
74:
75: 76: 77: 78: 79: 80: 81:
82: public function choose($case, $name){
83: if($wp_plugins = $this->extends->dealwith('menu', $name)){
84: return $wp_plugins;
85: }
86:
87: include_once('class-wx-cmd-text.php');
88: if(in_array($case, $this->callback) || in_array(substr($case, 0, 1), $this->callback)){
89: $text = WxRobot_Cmd_Text::instance();
90: $text->setValue($this->obj, $case);
91: $case = $text->replay();
92: return $case;
93: }else{
94: $reply = $this->wxSdk->toMsgText($case);
95: return $reply;
96: }
97: }
98: }
99: ?>
100: