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/Cmd
  8:  *  @since      5.3.0
  9:  */
 10: 
 11: /**
 12:  * WxRobot 命令响应类
 13:  */
 14: class WxRobot_Cmd{
 15: 
 16:     /**
 17:      * WxRobot_Cmd Instance
 18:      */
 19:     public static $_instance = null;
 20: 
 21:     /**
 22:      * 构造函数
 23:      *
 24:      * @return void
 25:      */
 26:     public function __construct(){
 27: 
 28:         include_once('weixin-sdk-api/weixin_crypt/wxBizMsgCrypt.php');
 29: 
 30:         $this->options  = get_option(WEIXIN_ROBOT_OPTIONS);
 31:         $this->extends  = WxRobot_Extends::instance();
 32:         $this->info     = wx_request_array();
 33:     }
 34: 
 35:     /**
 36:      * WxRobot 命令响应实例化
 37:      * 
 38:      * @return WxRobot_Cmd instance
 39:      */
 40:     public static function instance(){
 41:         if( is_null (self::$_instance)){
 42:             self::$_instance = new self();
 43:         }
 44:         return self::$_instance;
 45:     }
 46:     
 47:     /**
 48:      *  命令分析
 49:      *  
 50:      *  @return xml
 51:      */
 52:     public function cmd(){
 53: 
 54:         //插件接口调用
 55:         if($wp_plugins = $this->extends->dealwith('all', $this->info)){
 56:             $this->result =  $wp_plugins;
 57:         }else{
 58:             $this->result = $this->cmd_choose();
 59:         }
 60: 
 61:         //开启数据库记录判断
 62:         if($this->options['weixin_robot_record']){
 63:             $this->weixin_robot_insert();
 64:         }
 65: 
 66:         //是否加密通信
 67:         if(!empty($this->options['EncodingAESKey'])  && !empty($_GET['encrypt_type'])){
 68:             $this->result = wx_send_encode($this->result);
 69:         }
 70: 
 71:         return $this->result;
 72:     }
 73: 
 74:     /**
 75:      * 微信记录插入到数据中
 76:      *
 77:      * @return bool
 78:      */
 79:     public function weixin_robot_insert(){
 80:         $info = $this->info;
 81:             
 82:         $from = $info['FromUserName'];
 83:         $to = $info['ToUserName'];
 84:         $msgid = isset($info['MsgId']) ? $info['MsgId']: '';
 85:         $msgtype = $info['MsgType'];
 86:         $createtime = $info['CreateTime'];
 87: 
 88:         //文本内容
 89:         $content = isset($info['Content']) ? $info['Content']: '';
 90: 
 91:         //图片资源
 92:         $picurl = isset($info['PicUrl']) ? $info['PicUrl']: '';
 93: 
 94:         //地理位置上传
 95:         $location_x = isset($info['Location_X']) ? $info['Location_X']: '0.00';
 96:         $location_y = isset($info['Location_Y']) ? $info['Location_Y']: '0.00';
 97:         $scale = isset($info['Scale']) ? $info['Scale']: '0.00';
 98:         $label = isset($info['Label']) ? $info['Label']: '';
 99: 
100:         //link分享
101:         $title= isset($info['Title']) ? $info['Title']: '';
102:         $description = isset($info['Description']) ? $info['Description']: '';
103:         $url = isset($info['Url']) ? $info['Url']: '';
104: 
105:         //事件
106:         $event = isset($info['Event']) ? $info['Event']: '';
107: 
108:         if(!empty($event)){
109:             //事件中的特殊操作
110:             if('TEMPLATESENDJOBFINISH'==$info['Event']){
111:                 $content = '模版发送返回消息'.$info['Status'];
112:             }else if('MASSSENDJOBFINISH' == $info['Event']){
113:                 $content = '事件推送群发结果:'.$info['Status'].
114:                 '成功发送粉丝:'.$info['SentCount'].',失败发送粉丝:'.$info['ErrorCount'];
115:             }
116:         }
117: 
118:         $eventkey = isset($info['EventKey']) ? $info['EventKey']: '';
119: 
120:         //语音识别
121:         $format = isset($info['Format']) ? $info['Format']: '';
122:         $recognition = isset($info['Recognition']) ? $info['Recognition']: '';
123: 
124:         //资源ID
125:         $mediaid = isset($info['MediaId']) ? $info['MediaId']: '';
126:         $thumbmediaid = isset($info['ThumbMediaId']) ? $info['ThumbMediaId']: '';
127: 
128:         //回复
129:         $response = $this->ret_reply_type();
130: 
131:         //反应时间,本来是还有数据库插入的耗时(此时可以忽略不计)
132:         $response_time = timer_stop(0);
133:         $result =  WxRobot_Table_Records::instance()->insert($from, $to, $msgid, $msgtype, $createtime, $content, 
134:             $picurl, $location_x, $location_y,$scale, $label, $title, $description, 
135:             $url, $event,$eventkey,$format, $recognition, $mediaid, $thumbmediaid, $response, $response_time);
136: 
137:         return $result;
138:     }
139: 
140:     /**
141:      * 回复的类型
142:      * 
143:      * @return string
144:      */
145:     public function ret_reply_type(){
146:         $result = wx_parse_xml($this->result);
147:         if(isset($result['MsgType']) && !empty($result['MsgType']) ){
148:             switch($result['MsgType']){
149:                 case 'text'     :   return '文本回复';
150:                 case 'voice'    :   return '声音回复';
151:                 case 'music'    :   return '音乐回复';
152:                 case 'video'    :   return '视频回复';
153:                 case 'link'     :   return '声音回复';
154:                 case 'event'    :   return '事件回复';
155:                 case 'news'     :   return '图文回复';
156:                 case 'image'    :   return '图片回复';
157:                 case 'location' :   return '地址回复';
158:             }
159:         }
160:         return '无回复';
161:     }
162: 
163: 
164:     /**
165:      * @func 类型选择
166:      */
167:     public function cmd_choose(){
168:         switch($this->info['MsgType']){
169:             //文本消息  
170:             case 'text':return $this->textReply();break;
171:             //图片消息
172:             case 'image':return $this->imageReply();break;
173:             //语音消息
174:             case 'voice':return $this->voiceReply();break;
175:             //视频消息
176:             case 'video':return $this->videoReply();break;
177:             //事件消息
178:             case 'event':return $this->eventReply();break;
179:             //地理位置
180:             case 'location':return $this->locationReply();break;
181:             //连接信息
182:             case 'link':return $this->linkReply;break;
183:             //默认消息
184:             default:return $this->textReply();break;
185:         }
186:     }
187: 
188:     //文本消息回复
189:     public function textReply(){
190:         $kw = $this->info['Content'];//关键字
191:         include_once('weixin-robot/class-wx-cmd-text.php');
192:         
193:         WxRobot_Cmd_Text::instance()->setValue($this, $kw);
194:         return WxRobot_Cmd_Text::instance()->replay();
195:     }
196: 
197:     //图片消息回复
198:     public function imageReply(){
199: 
200:         $info['PicUrl'] = $this->info['PicUrl'];
201:         $info['MediaId'] = $this->info['MediaId'];
202: 
203:         //插件接口调用
204:         if($wp_plugins = $this->extends->dealwith('image', $info)){
205:             return $wp_plugins;
206:         }
207:     }
208: 
209:     //语音消息回复(腾讯普通开发者未开启),使用时,请注意
210:     public function voiceReply(){
211: 
212:         $info['MediaId'] = $this->info['MediaId'];
213:         $info['Format'] = $this->info['Format'];
214:         $info['Recognition'] = $this->info['Recognition'];
215:         
216:         //插件接口调用
217:         if($wp_plugins = $this->extends->dealwith('voice', $info)){
218:             return $wp_plugins;
219:         }
220:     }
221: 
222:     //视频消息回复
223:     public function videoReply(){
224:         $info['MediaId'] = $this->info['MediaId'];
225:         $info['ThumbMediaId'] = $this->info['ThumbMediaId'];
226: 
227:         //插件接口调用
228:         if($wp_plugins = $this->extends->dealwith('video', $info)){
229:             return $wp_plugins;
230:         }
231:     }
232: 
233: 
234:     //事件消息回复
235:     public function eventReply(){
236:         $type = $this->info['Event'];
237:         if($type == 'CLICK'){//自定义菜单事件
238:             include_once('weixin-robot/class-wx-event-user.php');
239:             $key = $this->info['EventKey'];
240:             if(!empty($key)){
241:                 $weixin_robot_event_user = WxRobot_Cmd_Event_User::instance();
242:                 $weixin_robot_event_user->setValue($this);
243:                 return $weixin_robot_event_user->go($key);
244:             }
245:         }else{
246:             include_once('weixin-robot/class-wx-event.php');
247:             $weixin_robot_event = WxRobot_Cmd_Event::instance();
248:             $type = $type.'Event';
249:             return $weixin_robot_event->$type();
250:         }
251:     }
252: 
253:     //地理位置回复
254:     public function locationReply(){
255:     
256:         $info['Location_X'] = $this->info['Location_X'];
257:         $info['Location_Y'] = $this->info['Location_Y'];
258:         $info['Scale'] = $this->info['Scale'];
259:         $info['Label'] = $this->info['Label'];
260: 
261:         //插件接口调用
262:         if($wp_plugins = $this->extends->dealwith('location', $info)){
263:             return $wp_plugins;
264:         }
265:     }
266: 
267:     //分享链接信息
268:     public function linkReply(){
269: 
270:         $info['Title'] = $this->info['Title'];
271:         $info['Description'] = $this->info['Description'];
272:         $info['Url'] = $this->info['Url'];
273: 
274:         //插件接口调用
275:         if($wp_plugins = $this->extends->dealwith('link', $info)){
276:             return $wp_plugins;
277:         }
278:     }
279: 
280:     /**
281:      * 返回帮助信息
282:      *
283:      * @param string $info 帮助信息
284:      * @return xml
285:      */
286:     public function help_info($info = ''){
287:         if($this->options['weixin_robot_helper_is'] != 'true'){
288:             $text = $this->options['weixin_robot_helper'];
289:             if(!empty($info)){
290:                 return $this->toMsgText($info."\n".$text);//文本
291:             }else{
292:                 return $this->toMsgText($text);//文本
293:             }
294:         }
295:     }
296:     
297: }
298: ?>
299: 
API documentation generated by ApiGen