def process_body(self, doc): #print 'process_body' try: msg = wx_xml.wxxml2dict(doc) except IException as e: e.detail() return '' except Exception: self.log.error('Exception raise in do_request') return '' msgtype = wx_xml.get_wxmsg(msg, 'MsgType') to_user = wx_xml.get_wxmsg(msg, 'ToUserName') from_user = wx_xml.get_wxmsg(msg, 'FromUserName') if to_user != self.conf.id: self.log.error('to_user is err,in:%s,xml:%s' % (to_user, self.conf.id)) return '' try: ret_text = self.process_msg(msg, msgtype, to_user, from_user) except IException as ie: ie.detail() return wx_xml.reply_text_msg(from_user, to_user, wx_xml.DEF_RESULT) return ret_text
def process_location(self, msg, to_id, from_id): latitude = wx_xml.get_wxmsg(msg, 'Latitude') longitude = wx_xml.get_wxmsg(msg, 'Longitude') precision = wx_xml.get_wxmsg(msg, 'Precision') if latitude == None or longitude == None or precision == None: linfo = 'lack latitude longitude or precision while location' raise IException(ErrCode.APPErr, linfo) return wx_xml.MsgType.FORMAT, ''
def process_encode(self, args, body): try: enctype = args['encrypt_type'][0] nonce = args['nonce'][0] timestamp = args['timestamp'][0] signature = args['signature'][0] msg_signature = args['msg_signature'][0] except KeyError: self.log.error('lack argus') return self.reply('', nonce) if enctype != self.ENCODE_AES: self.log.error('encode type is not aes, %s %s' % (enctype, self.ENCODE_AES)) return self.reply('', nonce) if not self.check_signature(signature, timestamp, nonce, self.conf.token): self.log.error('check signature failed') return self.reply('', nonce) print 'check signature ok' doc = self.decode_xml(body, msg_signature, timestamp, nonce) if doc is None: self.log.error('decode request body failed') return self.reply('', nonce) try: msg = wx_xml.wxxml2dict(doc) except IException as e: e.detail() return self.reply('', nonce) except Exception: self.log.error('Exception raise in do_request') return self.reply('', nonce) msgtype = wx_xml.get_wxmsg(msg, 'MsgType') to_user = wx_xml.get_wxmsg(msg, 'ToUserName') from_user = wx_xml.get_wxmsg(msg, 'FromUserName') if to_user != self.conf.id: self.log.error('to_user is err,in:%s,xml:%s' % (to_user, self.conf.id)) return self.reply('', nonce) try: to_xml = self.process_msg(msg, msgtype, to_user, from_user) except IException as ie: ie.detail() return self.reply('', nonce) return self.reply(to_xml, nonce)
def process_text(self, msg, to_id, from_id): #print 'MsgProcessor process_text' content = wx_xml.get_wxmsg(msg, 'Content') if content == None: raise IException(ErrCode.APPErr, 'lack context') user_pri = self.mongo.admin.find_pri(from_id) if user_pri is None: return self.admin_logic.process_fanyoyo(from_id, content) else: return self.admin_logic.process_text(from_id, user_pri, content)
def process_click(self, msg, to_id, from_id): key = wx_xml.get_wxmsg(msg, 'EventKey') if key == None: raise IException(ErrCode.APPErr, 'no button while click') umgr = url_mgr.UrlMgr() if key in umgr.multi_pages: item_arr = umgr.multi_pages[key] return wx_xml.MsgType.NEWS, item_arr elif key in umgr.pages: item_arr = [] item_arr.append(umgr.pages[key]) return wx_xml.MsgType.NEWS, item_arr else: return wx_xml.MsgType.NEWS, umgr.homepage()
def process_event(self, msg, to_id, from_id): type = wx_xml.get_wxmsg(msg, 'Event') if type == None: raise IException(ErrCode.APPErr, 'lack type') if type == 'subscribe': return self.process_subscribe(msg, to_id, from_id) elif type == 'unsubscribe': return self.process_unsubscribe(msg, to_id, from_id) elif type == 'SCAN': return self.process_scan(msg, to_id, from_id) elif type == 'LOCATION': return self.process_location(msg, to_id, from_id) elif type == 'CLICK': return self.process_click(msg, to_id, from_id) elif type == 'VIEW': return self.process_view(msg, to_id, from_id)
def process_voice(self, msg, to_id, from_id): media_id = wx_xml.get_wxmsg(msg, 'MediaId') format = wx_xml.get_wxmsg(msg, 'Format') if media_id == None: raise IException(ErrCode.APPErr, 'lack id') return None
def process_image(self, msg, to_id, from_id): pic_url = wx_xml.get_wxmsg(msg, 'PicUrl') media_id = wx_xml.get_wxmsg(msg, 'MediaId') if pic_url == None or media_id == None: raise IException(ErrCode.APPErr, 'lack url or id') return None
def process_view(self, msg, to_id, from_id): url = wx_xml.get_wxmsg(msg, 'EventKey') if url == None: raise IException(ErrCode.APPErr, 'lack url while view') return wx_xml.MsgType.FORMAT, ''
def process_scan(self, msg, to_id, from_id): key = wx_xml.get_wxmsg(msg, 'EventKey') ticket = wx_xml.get_wxmsg(msg, 'Ticket') if key == None or ticket == None: raise IException(ErrCode.APPErr, 'lack tikcy or key while scan') return wx_xml.MsgType.FORMAT, ''