def POST(self): try: webData = web.data() # print "Handle Post webdata is ", webData #后台打日志 recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg) and recMsg.MsgType == 'text': toUser = recMsg.FromUserName fromUser = recMsg.ToUserName content = "test" replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() else: # print "暂且不处理" return "success" except Exception, Argment: return Argment
def POST(self): post_data = web.data() # print "Handle Post webdata is ", post_data recMsg = receive.parse_xml(post_data) if isinstance(recMsg, receive.Msg) and recMsg.MsgType == 'text': toUser = recMsg.FromUserName fromUser = recMsg.ToUserName content, msg_type = char(recMsg.Content) if msg_type == 'image': replyMsg = reply.ImageMsg(toUser, fromUser, content) elif msg_type == 'text': replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() else: return 'success'
def POST(self): try: webData = web.data() recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg) and recMsg.MsgType == 'text': toUser = recMsg.FromUserName fromUser = recMsg.ToUserName content = 'test' replyMsg = reply.TextMsg(toUser, fromUser, content) print replyMsg return replyMsg.send() else: print 'do nothing for now' return 'success' except Exception, Argument: return Argument
async def on_text_message(msg: receive.TextMsg) -> reply.Msg: to_user = msg.FromUserName from_user = msg.ToUserName keyword = msg.Content if keyword.lower() == 'lucky': return await on_lucky_message(msg) pattern = r'[a-zA-Z]+[ \-]?\d+' if re.match(pattern, keyword): links = await fetch(keyword) if links: content = links[0] else: content = 'Nothing can be found' else: content = 'Illegal keyword' return reply.TextMsg(to_user, from_user, content)
def POST(self): try: webData = web.data() recMsg = receive.parse_xml(webData) isType = recMsg.MsgType == 'text' or (recMsg.MsgType == 'event' and recMsg.Event == "subscribe") if isinstance(recMsg, receive.Msg) and isType: toUser = recMsg.FromUserName fromUser = recMsg.ToUserName content = recMsg.Content replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() else: print u"暂且不处理" 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) if isinstance(recMsg, receive.Msg) and recMsg.MsgType == 'text': toUser = recMsg.FromUserName fromUser = recMsg.ToUserName content = "test" replyMsg = reply.TextMsg(toUser, fromUser, content) threading.Thread(target=send_template_message, args=()).start() return replyMsg.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) if isinstance(recMsg, receive.Msg) and recMsg.MsgType == 'text': toUser = recMsg.FromUserName fromUser = recMsg.ToUserName content = "你好" replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() else: print("do nothing right now") return "success" except Exception as e: print('Exception:', e)
def POST(self): try: webData = web.data() print("Handle Post webdata is ", webData) recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg) and recMsg.MsgType == 'text': toUser = recMsg.FromUserName fromUser = recMsg.ToUserName # content = "test" # content = recMsg.Content.decode() content = get_rasa_reply(recMsg.Content.decode()) replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() else: print("return success") return "success" except: return "error"
def POST(self): try: webData = web.data() print("[debug] post data", webData) recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg) and recMsg.MsgType == 'text': #需要check toUser = recMsg.FromUserName fromUser = recMsg.ToUserName content = "test" replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() else: print("暂不处理") return "success" 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) and recMsg.MsgType == 'text': toUser = recMsg.FromUserName fromUser = recMsg.ToUserName # content = self.process_game(ToUserName, recMsg.Content) # import pdb;pdb.set_trace() content = self.process_game(toUser, recMsg.Content) replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() else: print "pass" 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) 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 weixin(): receive_msg = receive.parse_xml(request.body.read()) if receive_msg.msg_type == 'text': reply_msg = reply.TextMsg( to_user_name=receive_msg.from_user_name, from_user_name=receive_msg.to_user_name, content=receive_msg.content ) return reply_msg.send() elif receive_msg.msg_type == 'image': reply_msg = reply.ImageMsg( to_user_name=receive_msg.from_user_name, from_user_name=receive_msg.to_user_name, media_id=receive_msg.media_id ) return reply_msg.send() else: reply_msg = reply.Msg() return reply_msg.send()
def post(self): webData = self.request.body # print("body=", webData) recMsg = receive.parse_xml(webData) print("recMsg==", recMsg.__dict__) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': content = recMsg.Content replyMsg = reply.TextMsg(toUser, fromUser, content) self.write(replyMsg.send()) if recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) self.write(replyMsg.send()) else: # 暂不处理 self.write(reply.Msg().send())
def handle(request): print "################in func handle ###############" if request.method == 'GET': print "################in func GET ###############" signature = request.GET.get("signature", None) timestamp = request.GET.get("timestamp", None) nonce = request.GET.get("nonce", None) echostr = request.GET.get("echostr", None) token = 'hello2017' li = [token, timestamp, nonce] li.sort() #sha1 = hashlib.sha1() #map(sha1.update, li) hashcode = "%s%s%s" % tuple(li) hashcode = hashlib.sha1(hashcode).hexdigest() print "handle/GET func: hashcode, signature: ", hashcode, signature if hashcode == signature: return HttpResponse(echostr, content_type="text/plain") else: return HttpResponse(None, content_type="text/plain") elif request.method == 'POST': print "################in func POST ###############" webData = request.raw_post_data print "Handle POST webdata is:", webData recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): #and recMsg.MsgType == "text": toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': content = u"您好,请输入咨询的服务" replyMsg = reply.TextMsg(toUser, fromUser, content) return HttpResponse(replyMsg.send()) elif recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) print "--------------------" print replyMsg.send() return HttpResponse(replyMsg.send()) else: print "not handling" return HttpResponse(reply.Msg().send()) return HttpResponse(None)
def DoAction(self, actions, toUser, fromUser): ret = '' if not actions: ret = 'no action' elif len(actions) > 1: ret = 'too many actions' else: # actions[0].debugMsg() if actions[0]._type == 'ShowPlainText': ret = actions[0]._text.encode('utf-8') elif actions[0]._type == 'ShowNewsText': articles = [] objs = json.loads(actions[0]._text) for obj in objs: articles.append(reply.Article(**obj)) replyMsg = reply.NewsMsg(toUser, fromUser, len(articles), articles) return replyMsg return reply.TextMsg(toUser, fromUser, ret)
def POST(self): try: webData = web.data() print "Handle Post webdata is ", webData #后台打日志 recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg) and recMsg.MsgType == 'text': toUser = recMsg.FromUserName fromUser = recMsg.ToUserName content = get_predicted_sentence(recMsg.Content, enc_vocab, inv_dec_vocab, model, sess) content = content.encode('utf-8') # content = recMsg.Content replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() else: print "暂且不处理" return "success" except Exception, Argment: return Argment
def index(request): if request.method == 'GET': signature = request.GET['signature'] timestamp = request.GET['timestamp'] nonce = request.GET['nonce'] echostr = request.GET['echostr'] token = "hiwx" list = [token, timestamp, nonce] list.sort() sha1 = hashlib.sha1() map(sha1.update, list) hashcode = sha1.hexdigest() print "handle/GET func: hashcode, signature: ", hashcode, signature if hashcode == signature: return HttpResponse(echostr) return HttpResponse('get wx') elif request.method == 'POST': webData = request.read() recMsg = receive.parse_xml(webData) print webData print recMsg if isinstance(recMsg, receive.Msg) and recMsg.MsgType == 'text': print 'isinstance == true' toUser = recMsg.FromUserName fromUser = recMsg.ToUserName print fromUser content = "miss you. Waiting for you so long years..." replyMsg = reply.TextMsg(toUser, fromUser, content) basic = Basic() tocken = basic.get_access_token() userinfo = requests.get( 'https://api.weixin.qq.com/cgi-bin/user/info?access_token=' + tocken + '&openid=' + toUser + '&lang=zh_CN') print userinfo.text return HttpResponse(replyMsg.send(), content_type='text/xml') else: print 'isinstance == false' return HttpResponse("success")
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': response1 = requests.get( "https://api.coinmarketcap.com/v1/ticker/?limit=10000") jsonCoinList = json.loads(response1.content) for i in jsonCoinList: if i['symbol'] == recMsg.Content.upper(): requestText = "https://api.coinmarketcap.com/v1/ticker/" + i[ 'name'] + "/?convert=CNY" response2 = requests.get(requestText) jsonResponse = json.loads(response2.content) content = '加密货币名称:' + str(jsonResponse[0]['name']) + ' 交易代码:' + str(jsonResponse[0]['symbol']) \ + ' 交易排名:' + str(jsonResponse[0]['rank']) \ + ' 美元价格:' + str(jsonResponse[0]['price_usd']) + '美元\n' + ' 人民币价格:' \ + str(jsonResponse[0]['price_cny']) + '人民币' + ' 比特币价格:' \ + str(jsonResponse[0]['price_btc']) + '比特币' + ' 全部市值:' + str(jsonResponse[0]['market_cap_usd']) \ + '美元\n' + ' 24小时交易量:' + str(jsonResponse[0]['24h_volume_usd']) + '美元' + ' 市场流通量:' \ + str(jsonResponse[0]['available_supply']) + ' 全部流通量:' + str(jsonResponse[0]['total_supply']) \ + ' 1小时价格变动:' + str(jsonResponse[0]['percent_change_1h']) + '%\n' + ' 24小时价格变动:' \ + str(jsonResponse[0]['percent_change_24h']) + '%' + ' 7天价格变动:' + str(jsonResponse[0]['percent_change_7d']) + '%' replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() else: 'the message is not successful' if recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() else: return 'Please type in the correct code' else: print "Processing Temporarily Suspended" return "Please type in the correct code" 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 = "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() if isinstance(recMsg, receive.EventMsg): print("event") if recMsg.Event == 'CLICK': if recMsg.Eventkey == 'mpGuide': toUser = recMsg.FromUserName data = """ { "touser":"******", "template_id":"GVnSlVUMHDAr6uNtd7dJhnUr_Y0qEopR7SGwzyGVpto", "url":"http://www.mej.cn", "data":{ } } """ % toUser token = basic.Basic().get_access_token() reply_template = template.Template().send(data, token) return data else: print "暂且不处理" return "success" except Exception, Argment: print(Argment) return Argment
def weixin(): assert request.method == 'POST' webData = request.data print('WebData: ', webData) recMsg = receive.parse_xml(webData) if recMsg is None: print('Parse error') return 'success' if isinstance(recMsg, receive.Msg) and recMsg.MsgType == 'text': toUser = recMsg.FromUserName fromUser = recMsg.ToUserName text = recMsg.Content print('收到文本消息: "{}"'.format(text)) content = chatter.get_response(text) print('返回消息: "{}"'.format(content)) replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() else: print("暂且不处理") return "success"
def POST(self): try: webData = web.data() print("Handle Post webdata is ", webData) recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): data.code_base = data.code_base data.code_lang = data.code_lang data.code_param = data.code_param data.MsgId = data.MsgId if recMsg.code_lang == "python": content = recMsg.Content content = content.decode("utf-8") replyMsg = reply.TextMsg(content) return replyMsg.send() else: print("Test 1...") except Exception as e: return e
def POST(self): try: webData = web.data() print "Handle Post webdata is ", webData #后台打日志 recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg) and recMsg.MsgType == 'text': toUser = recMsg.FromUserName fromUser = recMsg.ToUserName fromMsg = recMsg.Content.replace("|", " ") fromMsg = fromMsg.replace(" ", " ") cmdFmtRegex = ur'\S+-\S+\s(\d{4}-\d{2}-\d{2})\s\S+\s\S' #if recMsg.Content == 'h' or recMsg.Content == 'help' or recMsg.Content == '帮助': if not re.match(cmdFmtRegex, fromMsg): content = "实时余票查询格式:\n出发地-目的地 出发日 车次1,车次2 车座类型1,车位类型2\n例如:\n苏州-武汉 2016-09-30 d3022,d3066 二等座" else: #command = "php /home/application/12306/12306/12306.php " + recMsg.Content #cmdDetails=re.split(ur" ",fromMsg) cmdDetails = fromMsg.split(" ") if cmdDetails and len(cmdDetails) >= 4: fromToStation = cmdDetails[0].split("-") fromStation = fromToStation[0].decode('utf-8') toStation = fromToStation[1].decode('utf-8') date = cmdDetails[1] checi = cmdDetails[2] seatType = cmdDetails[3].decode('utf-8') command = "".join([ "php /home/application/12306/12306/12306.php -f ", fromStation, " -t ", toStation, " -d ", date, " -m ", checi, " -n ", seatType, " -r 1" ]) print "command:" + command content = os.popen(command).read() print "result:", content replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() else: print "暂且不处理" return "success" except Exception, Argment: return Argment
def POST(self): try: web_data = web.data() print("Handle Post webdata is ", web_data) receive_message = receive.parse_xml(web_data) if isinstance( receive_message, receive.Msg) and receive_message.message_type == 'text': to_user = receive_message.from_user_name from_user = receive_message.to_user_name content = 'test' reply_message = reply.TextMsg(toUserName=to_user, fromUserName=from_user, content=content) return reply_message.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) 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: print "暂且不处理" return "success" except Exception, Argment: return Argment
def POST(self): return '123' try: print('123') webData = web.data() print(webData) recvMsg = receive.parser_xml(webData) if isinstance(recvMsg, receive.Msg) and recvMsg.MsgType == 'text': toUser = recvMsg.FromUserName fromUser = recvMsg.ToUserName content = 'test' replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() else: print('not handle') return 'success' except Exception as e: print(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) and recMsg.MsgType == 'text': toUser = recMsg.FromUserName fromUser = recMsg.ToUserName data = urllib2.urlopen('http://api.qingyunke.com/api.php?key=free&appid=0&msg='+recMsg.Content) a = data.read() print 'data.read()' d = json.loads(a) content = d['content'].encode('utf-8') replyMsg = reply.TextMsg(toUser,fromUser,content) return replyMsg.send() else: print "暂不处理" return "success" # 返回成功 except Exception,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) and recMsg.MsgType == 'text': toUser = recMsg.FromUserName fromUser = recMsg.ToUserName input = recMsg.Content.decode(encoding='utf-8') context = ssl._create_unverified_context() output = urllib.request.urlopen( "https://tagging.aminer.cn/query/" + input, context=context).read().decode(encoding='utf-8') print(output) dic = re.findall("\"([^\"]*)\": \"([^\"]*)\"", output) url = "https://www.aminer.cn/search?" ans = "" for info in dic: if info[1] == "org": url += "o=" + urllib.parse.quote(info[0]) + "&" ans += "来自" + info[0] for info in dic: if info[1] == "name": url += "n=" + urllib.parse.quote(info[0]) + "&" ans += "名为" + info[0] + "的学者" for info in dic: if info[1] == "item": url += "k=" + urllib.parse.quote(info[0]) + "&" ans += "的" + info[0] url = url[:-1] link = "<a href=\"" + url + "\">" + ans + "</a>" print(link) replyMsg = reply.TextMsg(toUser, fromUser, link) return replyMsg.send() else: print("暂且不处理") return "success" except Exception as 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) and recMsg.MsgType == 'text': toUser = recMsg.FromUserName fromUser = recMsg.ToUserName content = recMsg.Content # print(content) reply_content = "" split_res = content.split() if len(split_res) <> 2: reply_content = "format is wrong!" else: # content to mysql_query query = self.sport_info.convert_to_query( split_res[0], split_res[1]) #print(query) # self.log_file.write("query:" + query) if query <> "": res = self.mysql_handle.insert(query) #if self.mysql_handle.insert(query) <> False: if res: reply_content = self.month_report() else: reply_content = "insert db failed!" date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) self.log_file.write(date + ": " + content + "\n") replyMsg = reply.TextMsg(toUser, fromUser, reply_content) return replyMsg.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) if isinstance(recMsg, receive.Msg) and recMsg.MsgType == 'text': toUser = recMsg.FromUserName fromUser = recMsg.ToUserName print(recMsg.Content.decode('utf-8')) content = ZeroAI.chat(recMsg.Content.decode('utf-8'), recMsg.FromUserName) #if '价' in content or '请' in content or '歉' in content or '市场' in content or 'price' in content or '模拟' in content or '无' in content: replyMsg = reply.TextMsg(toUser, fromUser, content) #else: # replyMsg = reply.ImageMsg(toUser, fromUser, content) return replyMsg.send() else: print("暂且不处理") return "success" except Exception as Argment: return Argment
def POST(self): try: webData = web.data() print "Handle Post webdata is " print webData #后台打日志 recMsg = receive.parse_xml(webData) toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': content = recMsg.Content if content == u"天气": replyMsg = "多云" else: 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() except Exception, Argment: return Argment