def on_text(self,doc): src_text=doc.xpath(r'//xml/Content/text()',smart_strings=False)[0] if src_text=='id': new_root=self._buildReplyBase() etree.SubElement(new_root,'MsgType').text=etree.CDATA('text') etree.SubElement(new_root,'Content').text=etree.CDATA(self.from_user) return new_root elif src_text=='reg': token=datamodel.basic.GetAccessToken() userdata=datamodel.basic.GetUserInfo(token,self.from_user) with dbconfig.Session() as session: weixin_user=WeixinUser() weixin_user.openid=self.from_user weixin_user.last_recv_time=time.time() weixin_user.subscribe=1 weixin_user.province=userdata['province'] weixin_user.city=userdata['city'] weixin_user.headimgurl=userdata['headimgurl'] weixin_user.language=userdata['language'] weixin_user.country=userdata['country'] weixin_user.sex=userdata['sex'] weixin_user.nickname=userdata['nickname'] session.merge(weixin_user) session.commit() new_root=self._buildReplyBase() etree.SubElement(new_root,'MsgType').text=etree.CDATA('text') etree.SubElement(new_root,'Content').text=etree.CDATA(u'%s,用户数据已更新'%(userdata['nickname'])) return new_root
def On_event_subscribe(self,doc): token=datamodel.basic.GetAccessToken() userdata=datamodel.basic.GetUserInfo(token,self.from_user) with dbconfig.Session() as session: weixin_user=WeixinUser() weixin_user.openid=self.from_user weixin_user.last_recv_time=time.time() weixin_user.subscribe=1 weixin_user.province=userdata['province'] weixin_user.city=userdata['city'] weixin_user.headimgurl=userdata['headimgurl'] weixin_user.language=userdata['language'] weixin_user.country=userdata['country'] weixin_user.sex=userdata['sex'] weixin_user.nickname=userdata['nickname'] session.merge(weixin_user) session.commit() scenceid=0 eventkey=doc.xpath(r"/xml/EventKey/text()",smart_strings=False) if eventkey: match=re.match(r'qrscene_(?P<code>\d+)',eventkey[0]) if match: scenceid=int(match.group('code')) print(scenceid) new_root=self._buildReplyBase() etree.SubElement(new_root,'MsgType').text=etree.CDATA('text') etree.SubElement(new_root,'Content').text=etree.CDATA(u'%s,感谢您关注现场加,功能开发中,请期待(scenceid=%d)'%(userdata['nickname'],scenceid)) return new_root