def weixin_msg(): logging.error("1.weixin: in weixin_msg ") if weixin.verification(request): logging.error("2.weixin verify done") data = request.data msg = weixin.parse_msg(data) if weixin.user_subscribe_event(msg): return weixin.help_info(msg) elif weixin.is_text_msg(msg): content = msg['Content'] if content == u'?' or content == u'?': return weixin.help_info(msg) elif (content == u'm' or content == u'M' or content == u'money' or content == u'MONEY' or content == u'Money'): return weixin.currency_info_AUDCNY_Pic(msg) elif (content == u'p' or content == u'P' or content == u'petrol' or content == u'PETROL' or content == u'Petrol'): return weixin.petrol(msg) else: return weixin.help_info(msg) elif weixin.is_location_msg(msg): Label = msg['Label'] return weixin.help_info(msg) return 'message processing fail'
def weixin_msg(): logging.error("1.weixin: in weixin_msg ") if weixin.verification(request): logging.error("2.weixin verify done") data = request.data msg = weixin.parse_msg(data) if weixin.user_subscribe_event(msg): return weixin.help_info(msg) elif weixin.is_text_msg(msg): content = msg['Content'] if content == u'?' or content == u'?': return weixin.help_info(msg) elif (content == u'n' or content == u'N' or content == u'new' or content == u'NEW' or content == u'New'): posts = operatorDB.get_weixin_articles() rmsg = weixin.response_news_msg(msg, posts) logging.error("3.weixin get rmsg: %s"%rmsg) return rmsg else: return weixin.help_info(msg) elif weixin.is_location_msg(msg): Label = msg['Label'] return weixin.help_info(msg) return 'message processing fail'
def post(self): global crawltoday #print self.request.body msg_req = self.request.body msg_req_xml = weixin.parse_msg(msg_req) # parse out the xml, assuming the msg_req is UTF8 encoded msg_type = weixin.get_msg_type(msg_req_xml) if msg_type == 'event': msg_event = weixin.get_msg_event(msg_req_xml) if msg_event == 'subscribe': msg_resp_str = weixin.build_flex_msg(msg_req_xml, u"欢迎关注,查看历史上的今天请发送\"今天\"两字") elif msg_type == 'text': msg_content = weixin.get_msg_content(msg_req_xml) if msg_content == u"今天2": content = '' index = 0 for entry in crawltoday.eventEntries: content += entry.title index += 1 if index == MAX_EVENT_ENTRIES: break msg_resp_str = weixin.build_flex_msg(msg_req_xml, content) elif msg_content == u"今天": content = '' index = 0 for entry in crawltoday.eventEntries: content += weixin.build_one_news(entry.title, entry.detail, entry.img_url) index += 1 if index == MAX_EVENT_ENTRIES: break msg_resp_str = weixin.build_news_msg(msg_req_xml, content, index) elif msg_content == u"更新2": msg_resp_str = weixin.build_flex_msg(msg_req_xml, "updating at server..., try again after 10 mins!") del crawltoday crawltoday = CrawlToday() today_page = crawltoday.grab_page() crawltoday.parse_events(today_page) #elif msg_content == u"孙中山": # msg_resp_str = weixin.build_test_news_msg(msg_req_xml) else: #msg_resp_str = weixin.build_autoreply_msg(msg_req_xml) msg_resp_str = weixin.build_flex_msg(msg_req_xml, u"本机器人不支持聊天,查看今天信息请发送\"今天\"两字") self.write(msg_resp_str.encode(encoding='UTF-8', errors='ignore'))