parameters: (request)
return_statement: return HttpResponse(content)
docstring: 事件分发函数，根据post数据中的event
docstring_summary: 事件分发函数，根据post数据中的event
docstring_tokens: 事件分发函数，根据post数据中的event
function: def dispatch_event(request):
      """ 事件分发函数，根据post数据中的event
      """
      xml = request.body
      root = ET.fromstring(xml)
      params = {elem.tag.lower(): elem.text for elem in root}
  
      try:
          handler_name = '%s_handler' % params['event'].lower()
          handler = globals()[handler_name]
      except KeyError:
          handler = default_handler
  
      result = handler(params)
  
      if not result:
          return HttpResponse('')
  
      user_extend = {
          'ToUserName': params['fromusername'],
          'FromUserName': params['tousername'],
          'CreateTime': int(time.time()),
      }
      result.update(user_extend)
      # 组合为xml
      content = build_xml(result)
      return HttpResponse(content)
function_tokens: def dispatch_event ( request ) : xml = request . body root = ET . fromstring ( xml ) params = { elem . tag . lower ( ) : elem . text for elem in root } try : handler_name = '%s_handler' % params [ 'event' ] . lower ( ) handler = globals ( ) [ handler_name ] except KeyError : handler = default_handler result = handler ( params ) if not result : return HttpResponse ( '' ) user_extend = { 'ToUserName' : params [ 'fromusername' ] , 'FromUserName' : params [ 'tousername' ] , 'CreateTime' : int ( time . time ( ) ) , } result . update ( user_extend ) # 组合为xml content = build_xml ( result ) return HttpResponse ( content )