Overview

Packages

  • None
  • WxRobot
    • Admin
    • Cmd
    • CoreFunctions
    • Exends
    • Install
    • Table
    • Uninstall
    • WxSDK

Classes

  • ErrorCode
  • PKCS7Encoder
  • Prpcrypt
  • SHA1
  • Weixin_BaseCore
  • WeiXin_SDK
  • Weixin_Template
  • WXBizMsgCrypt
  • WxRobot_Admin
  • WxRobot_Admin_Menu_Extends
  • WxRobot_Admin_Menu_Instro
  • WxRobot_Admin_Menu_Menu
  • WxRobot_Admin_Menu_Records
  • WxRobot_Admin_Menu_Reply
  • WxRobot_Admin_Menu_Setting
  • WxRobot_Admin_Menu_Statistics
  • WxRobot_Cmd
  • WxRobot_Cmd_Event
  • WxRobot_Cmd_Event_User
  • WxRobot_Cmd_Text
  • WxRobot_Extends
  • WxRobot_Install
  • WxRobot_Robot
  • WxRobot_SDK
  • WxRobot_Table_Extends
  • WxRobot_Table_Menu
  • WxRobot_Table_Records
  • WxRobot_Table_Reply
  • WxRobot_Uninstall
  • WxRobot_Wp
  • XMLParse

Functions

  • wx_admin_log
  • wx_is_xml
  • wx_notice_msg
  • wx_parse_xml
  • wx_random_big_pic
  • wx_random_small_pic
  • wx_request_array
  • wx_request_decode
  • wx_request_is_encode
  • wx_request_xml
  • wx_send_encode
  • Overview
  • Package
  • Class
  1: <?php
  2: /**
  3:  *  WxRobot - 扩展类
  4:  *
  5:  *  @author     midoks
  6:  *  @category   WxRobot
  7:  *  @package    WxRobot/Exends
  8:  *  @since      5.3.0
  9:  */
 10: 
 11: 
 12: class WxRobot_Extends{
 13: 
 14:     /**
 15:      * WxRobot_Cmd Instance
 16:      */
 17:     public static $_instance = null;
 18: 
 19:     /**
 20:      * 构造函数
 21:      *
 22:      * @return void
 23:      */
 24:     public function __construct(){
 25:     
 26:         $this->options = get_option(WEIXIN_ROBOT_OPTIONS);
 27:         $this->obj     = WxRobot_SDK::instance();
 28:     }
 29: 
 30:     /**
 31:      * WxRobot 实例化
 32:      * 
 33:      * @return WxRobot_Extends instance
 34:      */
 35:     public static function instance(){
 36:         if( is_null (self::$_instance)){
 37:             self::$_instance = new self();
 38:         }
 39:         return self::$_instance;
 40:     }
 41: 
 42:     /**
 43:      * 处理分离的功能
 44:      *
 45:      * @param string $func 功能名
 46:      * @param string $args 其他参数
 47:      * @return bool
 48:      */
 49:     public function dealwith($func, $args){
 50:         $res = '';
 51:         switch($func){
 52:             case 'all'      :   $res = $this->p_all($args);break;
 53:             case 'subscribe':   $res = $this->p_subscribe('');break;
 54:             case 'scan'     :   $res = $this->p_scan($args);break;
 55:             case 'text'     :   $res = $this->p_text($args);break;
 56:             case 'image'    :   $res = $this->p_image($args);break;
 57:             case 'voice'    :   $res = $this->p_voice($args);break;
 58:             case 'video'    :   $res = $this->p_video($args);break;
 59:             case 'location' :   $res = $this->p_location($args);break;
 60:             case 'link'     :   $res = $this->p_link($args);break;
 61:             case 'menu'     :   $res = $this->p_menu($args);break;
 62:             default         :   $res = $this->p_text('');break;
 63:         }
 64:         if(empty($res)){
 65:             return false;
 66:         }
 67:         return $res;
 68:     }
 69: 
 70: 
 71:     /**
 72:      * 所有信息处理
 73:      *
 74:      * @param array $args 所有数据
 75:      * @return mixed
 76:      */ 
 77:     private function p_all($args){
 78:         if(empty($args)){return false;}
 79:         if($data = $this->extends_start('all', $args)){
 80:             return $data;
 81:         }
 82:         return false;
 83:     }
 84: 
 85:     /**
 86:      * 订阅事件处理
 87:      *
 88:      * @return mixed
 89:      */
 90:     private function p_subscribe($args){
 91:         if($data = $this->extends_start('subscribe', $args)){
 92:             return $data;
 93:         }
 94:         return false;
 95:     }
 96: 
 97:     /**
 98:      * 扫描处理
 99:      *
100:      * @return mixed
101:      */
102:     private function p_scan($args){
103:         if($data = $this->extends_start('scan', $args)){
104:             return $data;
105:         }
106:         return false;
107:     }
108: 
109:     /**
110:      *  文本关键回复
111:      *  
112:      *  @param string $kw 关键字
113:      *  @return mixed
114:      */
115:     private function p_text($kw){
116:         if(empty($kw)){return false;}
117:         if($data = $this->extends_start('text', $kw)){
118:             return $data;
119:         }
120:         return false;
121:     }
122: 
123:     /**
124:      *  图片事件处理
125:      *
126:      *  @param array $info 图片消息
127:      *  @return mixed
128:      */
129:     private function p_image($info){
130:         if(empty($info)){return false;}
131:         if($data = $this->extends_start('image', $info)){
132:             return $data;
133:         }
134:         return false;
135:     }
136: 
137:     /**
138:      *  声音信息处理
139:      *
140:      *  @param array $info 图片消息
141:      *  @return mixed
142:      */
143:     private function p_voice($info){
144:         if(empty($info)){return false;}
145:         if($data = $this->extends_start('voice', $info)){
146:             return $data;
147:         }
148:         return false;
149:     }
150: 
151:     /**
152:      *  视频信息处理
153:      *
154:      *  @param array $info 图片消息
155:      *  @return mixed
156:      */
157:     private function p_video($info){
158:         if(empty($info)){return false;}
159:         if($data = $this->extends_start('video', $info)){
160:             return $data;
161:         }
162:         return false;
163:     }
164: 
165:     /**
166:      *  地理信息处理
167:      *
168:      *  @param array $info 图片消息
169:      *  @return mixed
170:      */
171:     private function p_location($info){
172:         if(empty($info)){return false;}
173:         if($data = $this->extends_start('location', $info)){
174:             return $data;
175:         }
176:         return false;
177:     }
178: 
179:     /**
180:      *  分享链接信息处理
181:      *
182:      *  @param array 图片消息
183:      *  @return mixed
184:      */
185:     private function p_link(){
186:         if(empty($info)){return false;}
187:         if($data = $this->extends_start('link', $info)){
188:             return $data;
189:         }
190:         return false;
191:     }
192: 
193:     /**
194:      * 分离出菜单控制(本插件功能并不能做到100%,提供次接口,让你自己控制)
195:      *
196:      * @param menu_name 菜单名字
197:      * @return mixed
198:      */
199:     private function p_menu($menu_name){
200:         if(empty($menu_name)){return false;}
201:         if($data = $this->extends_start('menu', $menu_name)){
202:             return $data;
203:         }
204:         return false;
205:     }
206: 
207:     /**
208:      * 插件启用
209:      *
210:      * @param string $name 插件名
211:      * @param array  $args 参数
212:      * @return mixed
213:      */
214:     private function extends_start($name, $args){
215:         $flist = WxRobot_Table_Extends::instance()->select_extends_type($name);
216:         if(!$flist) return false;
217:         foreach($flist as $k=>$v){
218:             if($name == $v['ext_type']){
219:                 $abspath = WEIXIN_PLUGINS.$v['ext_name'];
220:                 if(!file_exists($abspath)){
221:                     WxRobot_Table_Extends::instance()->delete_extends_name($v['ext_name']);
222:                 }else{
223:                     include_once($abspath);
224:                     $tt = explode('.', $v['ext_name']);
225:                     $cn = $tt[0];
226:                     $obj = new $cn($this);
227:                     if(method_exists($obj, 'start')){
228:                         $data = $obj->start($args);
229:                         if( $data ) return $data;
230:                     }
231:                 }   
232:             }
233:         }
234:         return false;
235:     }   
236: 
237: 
238:     /**
239:      * 获取扩展文件名
240:      *
241:      * @parma string $f 扩展绝对地址
242:      * @return bool
243:      */
244:     private function _c($f){
245:         if(!file_exists($f)){
246:             $fn = basename($f);
247:             WxRobot_Table_Extends::instance()->delete_extends_name($fn);
248:             return false;
249:         }else{
250:             include_once($f);
251:             return true;
252:         }
253:     }
254: 
255:     /**
256:      * 后台功能控制
257:      * 
258:      * @param string $fn 插件名
259:      * @return void
260:      */
261:     public function admin($fn){
262:         $abspath = WEIXIN_PLUGINS.$fn.'.php';
263:         if($this->_c($abspath)){
264:             $obj = new $fn($this);
265:             if(method_exists($obj, 'admin')){   
266:                 $obj->admin();
267:             }
268:         }
269:     }
270: 
271:     /**
272:      * 前端页面调用
273:      *
274:      * @param string $fn 插件名
275:      * @return void
276:      */
277:     public function frontend($fn){
278:         $abspath = WEIXIN_PLUGINS.$fn.'.php';
279:         if($this->_c($abspath)){
280:             $obj = new $fn($this);
281:             if(method_exists($obj, 'frontend')){
282:                 $obj->frontend();
283:             }
284:             
285:         }
286:     }
287: 
288: 
289:     /**
290:      * 在WP微信机器人后台控制(添加子菜单)
291:      *
292:      * @param object $object 对象
293:      * @param string $method 方法
294:      * @param string $titleName 标题名
295:      * @param string $linkName URL连接名字
296:      * @return void
297:      */
298:     public function admin_menu($object, $method, $titleName, $linkName){
299:         add_submenu_page('weixin_robot',
300:             'weixin_robot', 
301:             $titleName,
302:             'manage_options',
303:             $linkName,
304:             array($object, $method));
305:     }
306: 
307: 
308:     /**
309:      * 微信SDK功能的使用
310:      *
311:      * @param string $method 方法
312:      * @param array $args 参数
313:      * @retutn void
314:      */
315:     public function __call($method, $args){
316:         if(!empty($args)){
317:             return call_user_func_array(array($this->obj, $method), $args);
318:         }else{
319:             return call_user_func(array($this->obj, $method));
320:         }
321:     }
322: 
323:     /**
324:      *  获取接受的所有信息
325:      *
326:      *  @return array 返回所有的信息
327:      */
328:     public function getAcceptInfo(){
329:         return $this->info;
330:     }
331: 
332:     /**
333:      *  获取本插件的所有配置信息
334:      *
335:      *  @return array 返回数组
336:      */
337:     public function getConfigInfo(){
338:         return $this->options;
339:     }
340: 
341:     /**
342:      * 用户OpenID
343:      *
344:      * @return string
345:      */
346:     public function getUserOpenID(){
347:         return $this->info['FromUserName'];
348:     }
349: 
350:     /**
351:      * 获取开发AppID
352:      *
353:      * @return string
354:      */
355:     public function getAppID(){
356:         return $this->options['ai'];
357:     }
358: 
359:     /**
360:      * 获取开发AppSelect
361:      *
362:      * @return string
363:      */
364:     public function getAppSelect(){
365:         return $this->options['as'];
366:     }
367: }
368: ?>
369: 
API documentation generated by ApiGen