def POST(self): try: webData = web.data() print "Handle Post webdata is \n", webData # 打印后台日志 recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': content = recMsg.Content replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() if recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() else: return reply.Msg().send() if isinstance(recMsg, receive.EventMsg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.Event == 'CLICK': print 'It is a CLICK event' content = u'功能正在开发中,敬请期待..'.encode('utf-8') replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() print "暂且不处理" return reply.Msg().send() except Exception, Argment: return Argment
def POST(self): try: webData = web.data() print "Handle Post webdata is ", webData #后台打日志 recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': queryUser = recMsg.Content if queryUser in msgs.keys(): if msgs[queryUser]: content = msgs[queryUser].pop(); else: content = 'there is no msg for ' + queryUser else: content = 'there is no msg for ' + queryUser replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() if recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() else: return reply.Msg().send() else: print "暂且不处理" return reply.Msg().send() except Exception, Argment: return Argment
def POST(self): webData = web.data() util.lstr("Handle Post webdata is: ") util.lstr(webData) # print(type(webData)) # str recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': # info = 'empty' # content = '收到问题: ' + recMsg.Content + ' info: ' + info content = self.process_txt(recMsg.Content) replyMsg = reply.TextMsg(toUser, fromUser, content.encode('utf-8')) return replyMsg.send() if recMsg.MsgType == 'image': # 发送信息 # content = self.process_txt('image') # replyMsg = reply.TextMsg(toUser, fromUser, content.encode('utf-8')) # return replyMsg.send() replyMsg = reply.NewsMsg(toUser, fromUser, 1, '这可能是苹果白粉病', '苹果白粉病(Apple powdery mildew)在我国苹果产区发生普遍。除为害苹果外,还为害梨、沙果、海棠、槟子和山定子等,对山定子实生苗、小苹果类的槟沙果、海棠和苹果中的倭锦、祝、红玉、国光等品种为害重。', 'http://g.hiphotos.baidu.com/baike/w%3D268%3Bg%3D0/sign=442e0372f2d3572c66e29bdab228041a/18d8bc3eb13533facc74c7b5a8d3fd1f40345b6e.jpg', 'http://baike.baidu.com/item/%E8%8B%B9%E6%9E%9C%E7%99%BD%E7%B2%89%E7%97%85/10248498?fr=aladdin') return replyMsg.send() if recMsg.MsgType == 'voice': content = '用户: ' + recMsg.FromUserName + ' 发送了语音,转化为文字为: ' + recMsg.Recognition replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() else: return reply.Msg().send() else: util.lstr("暂且不处理") return reply.Msg().send()
def POST(self): try: token = Basic().get_access_token() print(token) webData = web.data() recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': content = "欢迎光临!" replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() if recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyImageMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyImageMsg.send() else: return reply.Msg().send() else: print("暂且不处理") return reply.Msg().send() except Exception as Argment: print(Argment) return Argment
def POST(self): try: webData = web.data() print("Handle Post webdata is :", webData) #后台打日志 recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName recv_content = recMsg.Content.decode() if recMsg.MsgType == 'text': print('recv:', recv_content) ans = agent.search(recv_content) #print('ans:',ans) #content = "公众号test" replyMsg = reply.TextMsg(toUser, fromUser, ans) return replyMsg.send() if recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() else: return reply.Msg().send() else: print("暂且不处理") return reply.Msg().send() except Exception as Argment: return Argment
def POST(self): try: webData = web.data() print "Handle Post webdata is ", webData #后台打日志 recMsg = receive.parse_xml(webData) xml = etree.fromstring(webData) #进行XML解析 if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': #content = recMsg.Content Content = xml.find("Content").text replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() if recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() else: return reply.Msg().send() else: print "暂且不处理" return reply.Msg().send() except Exception, Argment: return Argment
def POST(self): try: webdata = web.data() print("Handle Post webdata is ", webdata) print('hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh') #后台打日志 print('hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh') recMsg = receive.parse_xml(webdata) print("isinstance Msg", isinstance(recMsg, receive.Msg)) print(type(recMsg)) print("length of webdata", len(webdata)) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': content = 'test' replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() if recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) print(type(replyMsg)) return replyMsg.send() else: return reply.Msg().send() else: print("暂且不处理") return reply.Msg().send() except Exception, Argument: return Argument
def POST(self): try: webData = web.data() mylog = log.Mylog() mylog.printToLog("########\n[info]Handle Post webdata is " + webData.decode('utf-8') + "\n########\n") recMsg = receive.parse_xml(webData.decode()) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': replyMsg = keyword_reply.parse_keyword(recMsg.Content) return replyMsg.send(toUser, fromUser) if recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() if recMsg.MsgType == 'link': replyMsg = custom_reply.parse_link(recMsg.Description) #url=shorter(recMsg.Url) #print(url) replyMsg.update(toUser, recMsg.Url) return replyMsg.send(toUser, fromUser) else: return reply.Msg().send() else: mylog.printToLog("暂且不处理") return reply.Msg().send() except Exception as Argument: return Argument
def POST(self): try: webData = web.data() print "Handle Post webdata is ", webData # 后台打日志 recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': content = "test" replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() if recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() else: return reply.Msg().send() else: print "暂且不处理" return reply.Msg().send() except Exception as e: print(e)
def POST(self): try: webData = web.data() print("Handle Post webdata is %s" % webData) #后台打日志 recMsg = receive.parse_xml(webData) #print(str(isinstance(recMsg, Msg))) #print(str(recMsg.MsgType)) print("recMsg instanceof receive.Msg :%s, recMsg.MsgType:%s" % (str(isinstance(recMsg, Msg)), str(recMsg.MsgType))) if isinstance(recMsg, Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': handle_mess = HandleMessage() print(recMsg.Content) content = handle_mess.handle_message(recMsg.Content) print("##########:" + content) replyMsg = reply.TextMsg(toUser, fromUser, content) print("toUser:%s,fromUser:%s,info:%s" % (str(toUser), str(fromUser), str( recMsg.Content).encode("utf-8"))) return replyMsg.send() if recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() else: return reply.Msg().send() else: print("暂且不处理") return reply.Msg().send() except Exception as ar: return ar
def POST(self): try: webData = web.data() print("Handle post web data is:", webData) recvMsg = receive.parse_xml(webData) if isinstance(recvMsg, receive.Msg): toUser = recvMsg.FromUserName fromUser = recvMsg.ToUserName if recvMsg.MsgType == 'text': replyMsg = reply.TextMsg(toUser, fromUser, recvMsg.Content) textMsg = replyMsg.send() print("Return to WeChat Msg is :", textMsg) return textMsg if recvMsg.MsgType == 'image': mediaId = recvMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) imageMsg = replyMsg.send() return imageMsg else: return reply.Msg().send() if isinstance(recvMsg, receive.EventMsg): if recvMsg.Event == 'CLICK': if recvMsg.EventKey == 'mpGuide': content = u'编写中,尚未完成'.encode('utf-8') replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() print("暂不处理......") return reply.Msg().send() except Exception, Argment: print("[ERROR]: except Exception!!!!:", Argment) return Argment
def POST(self): try: webData = web.data() print "Handle Post webdata is \n", webData # 后台打印日志 recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.EventMsg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.Event == 'subscribe': content = '你好,这个公众号还未开化哦' replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() elif isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': print recMsg.Content content = Tuling(recMsg.Content).reply().encode('utf8') print content if recMsg.Content == '智障': content = '666' elif recMsg.Content == '我是智障': title = '中秋快乐' description = '惊不惊喜' picUrl = 'http://pic33.nipic.com/20130923/11927319_180343313383_2.jpg' url = 'http://www.umi101108.com' replyMsg = reply.TextImageMsg(toUser, fromUser, title, description, picUrl, url) return replyMsg.send() elif recMsg.Content == '电影': piaofang = Cbooo().getPiaofang() replyMsg = reply.MultiTextImageMsg( toUser, fromUser, piaofang, 5) return replyMsg.send() replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() elif recMsg.MsgType == 'image': mediaId = recMsg.MediaId PicUrl = recMsg.PicUrl try: content = How_old().getAttributes(PicUrl) print content replyMsg = reply.TextMsg(toUser, fromUser, content) except: replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() else: return reply.Msg().send() else: print "暂且不处理" return reply.Msg().send() except Exception, Argument: return Argument
def POST(self): # 新增加的POST函数 try: webData = web.data() print("Handle Post webdata is ", webData) # 后台打日志 recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'event': # 事件:用户订阅 if recMsg.Event == bytes('subscribe', encoding="utf8"): content = ct.show_help() replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() if recMsg.MsgType == 'text': # 接收文本 if recMsg.Content == bytes('1', encoding="utf8"): content = ct.add_server('10') elif recMsg.Content == bytes('2', encoding="utf8"): content = ct.sub_server('10') elif recMsg.Content == bytes('3', encoding="utf8"): content = ct.add_client(toUser) elif recMsg.Content == bytes('4', encoding="utf8"): content = ct.sub_client(toUser) elif recMsg.Content == bytes('5', encoding="utf8"): content = ct.add_order('10', toUser, 0) elif recMsg.Content == bytes('6', encoding="utf8"): content = ct.sub_order('10') elif recMsg.Content == bytes('7', encoding="utf8"): content = ct.sub_order(toUser, 0) elif recMsg.Content == bytes('8', encoding="utf8"): content = ct.show_info('10') elif recMsg.Content == bytes('9', encoding="utf8"): content = ct.show_info(toUser) else: content = ct.show_help() replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() if recMsg.MsgType == 'image': # 接收图片 mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() else: # 其他处理 return reply.Msg().send() else: print("暂且不处理") return reply.Msg().send() except Exception as Argment: return Argment
def POST(self): try: webData = web.data() util.lstr("Handle Post webdata is: ") util.lstr(webData) # print(type(webData)) # str recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName usr = user.UserProfile(recMsg.FromUserName) if recMsg.MsgType == 'text': info = 'empty' # 设置 cookie # cookie = web.cookies(count='-1') # info = 'cookie.count = {}'.format(cookie.count) # int_count = int(cookie.count) + 1 # web.setcookie('count', str(int_count), 3600) # end 设置 cookie info = '之前的问题是: ' + ','.join( usr.get_info(user.jkey_quetions)) usr.set_info(user.jkey_quetions, recMsg.Content) content = '收到问题: ' + recMsg.Content + ' info: ' + info replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() if recMsg.MsgType == 'image': # 保存图片 myMedia = Media() imageUrl = recMsg.PicUrl savedUrl = myMedia.get_saved_url(imageUrl) myMedia.save_user_image(imageUrl) # 发送信息 content = '用户: ' + recMsg.FromUserName + ' 发送图片,已保存在: ' + savedUrl replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() # mediaId = recMsg.MediaId # replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) # return replyMsg.send() if recMsg.MsgType == 'voice': content = '用户: ' + recMsg.FromUserName + ' 发送了语音,转化为文字为: ' + recMsg.Recognition replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() else: return reply.Msg().send() else: util.lstr("暂且不处理") return reply.Msg().send() except Exception, Argment: util.lstr('========Exception=======') util.lstr(traceback.format_exc()) return Argment
def POST(self): try: webData = web.data() util.lstr("Handle Post webdata is: ") util.lstr(webData) # print(type(webData)) # str recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName usr = user.UserProfile(recMsg.FromUserName) if recMsg.MsgType == 'text': return self.HandleUserMsg(usr, recMsg, Handle.dialog, toUser, fromUser) elif recMsg.MsgType == 'image': # 保存图片 myMedia = Media() imageUrl = recMsg.PicUrl savedUrl = myMedia.get_saved_url(imageUrl) myMedia.save_user_image(imageUrl) # 发送信息 content = '用户: ' + recMsg.FromUserName + ' 发送图片,已保存在: ' + savedUrl replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() # mediaId = recMsg.MediaId # replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) # return replyMsg.send() elif recMsg.MsgType == 'voice': content = '用户: ' + recMsg.FromUserName + ' 发送了语音,转化为文字为: ' + recMsg.Recognition replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() elif recMsg.MsgType == 'event': print(u'event received, recMsg.Content = ' + recMsg.Content) if recMsg.Content == u'unsubscribe': usr.delete() reply.Msg().send() elif recMsg.Content == u'subscribe': return self.HandleUserMsg(usr, recMsg, Handle.dialog, toUser, fromUser) else: return reply.Msg().send() else: util.lstr("暂且不处理") return reply.Msg().send() except Exception, Argment: util.lstr('========Exception=======') util.lstr(traceback.format_exc()) return Argment
def POST(self): try: webData = web.data() print("Handle Post webdata is ", webData) recMsg = receive.parse_xml(webData) toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if isinstance(recMsg, receive.Msg): if recMsg.MsgType == 'text': content = "test" print(toUser) replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() if recMsg.MsgType == "image": mediaId = recMsg.MediaId print(mediaId) replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() # else: # return reply.Msg().send() if isinstance(recMsg, receive.EventMsg): if recMsg.Event == 'CLICK': if recMsg.Eventkey == 'mpGuide': content = u"编写中".encode('utf8') replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() print("暂不处理") return reply.Msg().send() except Exception as e: return e
def POST(self): try: webData = web.data() print "接收客户信息:\n", webData # 后台打日志 recMsg = receive.parse_xml(webData)#处理接收微信发过来的信息 if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName recvtext = recMsg.Content#接收发送的信息 if recMsg.MsgType == 'text': try: if recvtext.isdigit():#判断接收的是数字还是字符串 #连接数据库获取评论信息 content = NetSQL.sqlitetest(recvtext)['txt'].encode('utf8') + "\n\n\n------来自网易云音乐评论------\n %s" % ( NetSQL.sqlitetest(recvtext)['footer'].encode('utf8'))#不转码报错ASCII print(content) #new对象 replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send()#调用方法发送 else: content = "请发送数字:1-104180\nhttp://daydayup11.cn/" replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send()#发送XML格式数据 except Exception,e: print("SendERR:",e) if recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() else: return reply.Msg().send() else:
def POST(self): try: webData = web.data() recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': content = recMsg.reply() render = web.template.render('templates/') return render.reply_text(fromUser, \ toUser, int(time.time()), content) replyMsg = reply.TextMsg(toUser, \ fromUser, content) return replyMsg.send() elif recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, \ fromUser, mediaId) return replyMsg.send() else: return reply.Msg().send() else: print "暂且不处理" return "success" except Exception, Argment: return Argment
def tick(self): if len(handle_queue) == 0: return recMsg = handle_queue.popleft() toUser = recMsg.FromUserName fromUser = recMsg.ToUserName replyMsg = reply.Msg(toUser, fromUser) if isinstance(recMsg, receive.TextMsg): content = recMsg.Content response = get_content(content) msgType = response['type'] content = response['content'] if msgType == 'text': replyMsg = reply.TextMsg(toUser, fromUser, content) elif msgType == 'news': replyMsg = reply.NewsMsg(toUser, fromUser, response['title'], response['content'], response['pic_url'], response['url']) elif isinstance(recMsg, receive.ImageMsg): pass elif isinstance(recMsg, receive.EventMsg): if recMsg.Event == 'subscribe': content = config.Welcome.format(key=get_keywords()) replyMsg = reply.TextMsg(toUser, fromUser, content) sender_queue.append(replyMsg)
def wechat_auth(): try: if request.method == 'GET': data = request.args print('Coming Get', data) if not data: return '' test = data.get('test', '') if test != '': content = get_content(test) return content['content'] signature = data.get('signature', '') if signature == '': return 'error' timestamp = data.get('timestamp', '') nonce = data.get('nonce', '') echostr = data.get('echostr', '') s = [timestamp, nonce, token] s.sort() s = ''.join(s).encode('utf8') if (hashlib.sha1(s).hexdigest() != signature): return 'failed' return make_response(echostr) if request.method == 'POST': xml_str = request.stream.read() # print('Coming Post', xml_str) recMsg = receive.parse_xml(xml_str) toUser = recMsg.FromUserName fromUser = recMsg.ToUserName replyMsg = reply.Msg(toUser, fromUser) if isinstance(recMsg, receive.TextMsg): content = recMsg.Content response = get_content(content) msgType = response['type'] content = response['content'] if msgType == 'text': replyMsg = reply.TextMsg(toUser, fromUser, content) elif msgType == 'news': replyMsg = reply.NewsMsg(toUser, fromUser, response['title'], response['content'], response['pic_url'], response['url']) elif isinstance(recMsg, receive.ImageMsg): pass elif isinstance(recMsg, receive.EventMsg): if recMsg.Event == 'subscribe': content = config.Welcome.format(key=get_keywords()) replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() except Exception as e: print(str(e)) return ''
def POST(self): try: webData = web.data() print "Handle Post webdata is ", webData # 后台打日志 recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': content = recMsg.Content replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() if recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() if isinstance(recMsg, receive.EventMsg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.Event == 'CLICK': if recMsg.Eventkey == 'mpGuide': content = u"编写中,尚未完成".encode('utf-8') replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() print "暂且不处理" return reply.Msg().send() except Exception, Argment: return Argment
async def postWX(request): webData = await request.text() print("%s" % (webData)) recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg) and recMsg.MsgType == "text": #注意fromUser 与 toUser交互 toUser = recMsg.FromUserName fromUser = recMsg.ToUserName content = "test-song" replyMsg = reply.TextMsg(toUser, fromUser, content) sendmsg = replyMsg.ToStr() return web.Response(body=sendmsg.encode('utf-8')) elif isinstance(recMsg, receive.TextMsg): pass elif isinstance(recMsg, receive.EventMsg): if recMsg.Event.lower() == 'subscribe': toUser = recMsg.FromUserName fromUser = recMsg.ToUserName content = "欢迎关注我的公众号" replyMsg = reply.TextMsg(toUser, fromUser, content) sendmsg = replyMsg.ToStr() return web.Response(body=sendmsg.encode('utf-8')) elif recMsg.Event.lower() == 'unsubscribe': return web.Response(body=reply.Msg().ToStr().encode('utf-8')) else: pass
def POST(self): global eventEngine, eventHandle, question, answer try: eventEngine.set() webData = web.data() #print "Handle Post webdata is ", webData #后台打日志 recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': print recMsg.Content question = recMsg.Content eventEngine.set() eventHandle.wait() eventHandle.clear() content = answer.strip() replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() if recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() else: return reply.Msg().send() else: print "暂且不处理" return "success" except Exception, Argment: return Argment
def POST(self): try: webData = web.data() print("Handle Post webdata is", webData) #后台打印日志 recMsg = receive.parse_xml(webData) print(recMsg) if isinstance(recMsg, receive.Msg): print(recMsg) print(receive.Msg) toUser = recMsg.FromUserName fromUser = recMsg.ToUserName print(recMsg.MsgType) if recMsg.MsgType == 'text': print("text") content = recMsg.Content.decode('utf-8') replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() if recMsg.MsgType == 'image': mediaId = recMsg.MediaId print(mediaId) print(11111111111111111) replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) print(replyMsg) print(11111111111) return replyMsg.send() else: return reply.Msg().send() else: print("暂且不处理未识别的消息") return success except Exception as Argment: return Argment
def POST(self): try: webData = web.data() recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': content = auoth.Text(toUser, recMsg.Content) #自动回复接口 replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() if recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() #if isinstance(recMsg,receive.EventMsg): #菜单 # if recMsg.Event=='CLICK': # if recMsg.Eventkey =='mpGuide': # content=u"编写中,尚未完成" # reply=reply.TextMsg(toUser,fromUser,content) # return reply.send() else: print "暂不处理" return reply.Msg().send() except Exception, Argument: return Argument
def POST(self): try: webData = web.data() print "Handle Post webdata is ", webData #后台打日志 recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): if recMsg.MsgType == 'text': toUser = recMsg.FromUserName fromUser = recMsg.ToUserName content = "You told me:" + recMsg.Content + ",thanks!" replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() if recMsg.MsgType == 'image': toUser = recMsg.FromUserName fromUser = recMsg.ToUserName mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() else: return reply.Msg().send() else: print "暂且不处理" return "success" except Exception, Argment: return Argment
def POST(self): try: webData = web.data() #后台打印 print('handle POST webdata', webData) recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': content = u"客服暂未开放,如需帮助请点击菜单旗舰店联系客服,或者拨打售后服务热线400-820-6276".encode( 'utf-8') replyMsg = reply.TextMsg(toUser, fromUser, content) if recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, content) return replyMsg.send() if isinstance(recMsg, receive.EventMsg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName print(recMsg.Event, recMsg.EventKey) if recMsg.Event == 'CLICK': if recMsg.EventKey == 'zbf': content = u"编写中".encode('utf-8') replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() else: print('not handle now') return reply.Msg().send() except Exception, e: return e
def POST(self): try: webData = web.data() print "Handle Post webdata is ", webData #后台打日志 recMsg = receive.parse_xml(webData) myMedia = Media() #print recMsg #print recMsg.MsgType if isinstance(recMsg, receive.Event): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'event': event = recMsg.Event if event == 'subscribe': content = "Hi, thanks for attention Fancytech WeChat! /::D" replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() elif isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': Content = recMsg.Content print Content if Content == '111': content = "别浪费流量,乱发消息!/:wipe" else: content = "Hi, Can I help you ? /::,@" replyMsg = reply.TextMsg(toUser, fromUser, content) print "反馈文字信息成功!!!!!!!!!" return replyMsg.send() if recMsg.MsgType == 'image': content = "图片已经接收...Thanks♪(・ω・)ノ" mediaId = recMsg.MediaId accessToken = Basic().get_access_token() myMedia.get(accessToken, mediaId, toUser) replyMsg = reply.TextMsg(toUser, fromUser, content) #replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() else: return reply.Msg().send() else: print "暂且不处理" return reply.Msg().send() except Exception, Argment: return Argment
def POST(self): try: webData = web.data() print "Handle Post webdata is ", webData recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': content = recMsg.Content with open('./files/handle.txt', 'a') as f: f.write('%s%s\n' % (toUser, content)) if content.strip() == "菜单": content = "这是一个菜单\n输入1:查看历史消息\n输入2:查看历史图片" elif content.strip() == "1": content = os.popen( "cat ./files/handle.txt | grep %s | tail -n 100 | awk -F '%s' '{print $2}'" % (toUser, toUser)).read()[:-1] elif content.strip() == "2": mediaId = os.popen( "cat ./files/images.txt | grep %s | tail -n 1 | awk -F '%s' '{print $2}'" % (toUser, toUser)).read()[:-1] if mediaId == "": #mediaId = "ko6zjMTgHhXFSy2p8W4eupv9v6EVjidxvzta4rHcmaovSxVzREoDxa1MBl89Sotu" mediaId = "1Plaf_sgdmVbg5Au_IzUfy_d20BvpQ05x0tSoJaBqtFH5aGB0eTyez6Uh48BSNNC" replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() elif content.strip() == "3": content = "你真漂亮!" replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() if recMsg.MsgType == 'image': mediaId = recMsg.MediaId with open('./files/images.txt', 'a') as f: f.write('%s%s\n' % (toUser, mediaId)) replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() else: return reply.Msg().send() else: print "暂且不处理" return reply.Msg().send() except Exception, Argment: return Argment
def POST(self): try: webData = web.data() print "Handle Post webdata is ", webData #后台打日志 recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': if recMsg.Content == '温度': content = str( getData_time('temperature')) + '\n室内温度为' + str( getData_value('temperature')) + '℃' elif recMsg.Content == '湿度': content = str( getData_time('humidity')) + '\n室内湿度为' + str( getData_value('humidity')) + '%' else: content = '抱歉尚未开通这项指令功能,你可以尝试发送‘温度’、‘湿度’来查看最新的室内信息,或者发送相应的语音消息 ' replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() if recMsg.MsgType == 'voice': if recMsg.Recognition == '温度。': content = str( getData_time('temperature')) + '\n室内温度为' + str( getData_value('temperature')) + '℃' elif recMsg.Recognition == '湿度。': content = str( getData_time('humidity')) + '\n室内湿度为' + str( getData_value('humidity')) + '%' else: content = recMsg.Recognition + '\n无法识别这条语音消息' replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() else: return reply.Msg().send() else: print "暂且不处理" return reply.Msg().send() except Exception, Argment: return Argment