def on_cmd(command): log.info("enter command mode with command :%s"%str(command)) #return (cmd_result,isValidCmd) #isvalidCmd=False if command == '?': return (cmd.help_info,True) else: return (None,False)
def on_text_msg(doc): Content=getValue(doc,'Content') Content = string.strip(Content,' ') length = len(Content) length_info="request content length:%s"%str(length) log.info(length_info) if length == 1: is_ascii = ks_http.isAsciiChar(Content) if is_ascii: #into cmd mode (cmdResult,isValidCmd)= on_cmd(Content) if isValidCmd: return cmdResult else: #invalid cmd, so go on google pass Content=ks_http.google(Content) return Content
def on_post(): raw_post=sys.stdin.read() log.info("raw:%s"%str(raw_post)) doc = xml.dom.minidom.parseString(raw_post) try: ToUserName=getValue(doc,'ToUserName') FromUserName=getValue(doc,'FromUserName') MsgType=getValue(doc,'MsgType') #location image text handler=msg_handler.get(MsgType,unknown_msg_type) content=handler(doc) """ CreateTime=getValue(doc,'CreateTime') MsgType=getValue(doc,'MsgType') Content=getValue(doc,'Content') Content=ks_http.google(Content) """ #Content=getValue(doc,'Label') #print Content #log.info(Content) response = """<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[%s]]></Content> </xml>"""%(FromUserName,ToUserName,time.time(),content) log.info("response:%s"%response) print response except: log.exception("exception in on_post") return
import os,sys import simplejson as json import traceback import xml.dom.minidom import time cgitb.enable() import string import ks_http from ks_http import log import cmd Token = "kuaisoo" log.info("------------start--------------------\r\n") """ os.environ['REQUEST_METHOD']='GET' os.environ['QUERY_STRING']='signature=840e8ee35ef65dd598f1c5f249fa213801fdf6d4×tamp=1356517202&nonce=1355917928&echostr=tfffff' os.environ['REQUEST_URI']='/scgi-bin/handler.py?signature=840e8ee35ef65dd598f1c5f249fa213801fdf6d4×tamp=1356517202&nonce=1355917928' """ REQUEST_METHOD = os.environ['REQUEST_METHOD'] REQUEST_URI= os.environ['REQUEST_URI'] QUERY_STRING = os.environ['QUERY_STRING'] log.info ("%s on %s"%(REQUEST_METHOD,REQUEST_URI)) ks_http.head() def getValue(doc,val):