Home > Mobile >  Interface debugging success, but the runtime prompts the public services provided by the failure
Interface debugging success, but the runtime prompts the public services provided by the failure

Time:09-22


The development environment the following
 
CentOS 7
Python 3.7
Flask 1.1.1
Tornado 6.0.3

The key code below
 
Xml_data=(https://bbs.csdn.net/topics/request.stream.read)
Xml_objt=receive. Parse_xml (xml_data)
If xml_objt. MsgType=="text" :
Text_str="' & lt; Xml> ! [CDATA [% s]] ! [CDATA [% s]] % s ! [CDATA [text]] ! [CDATA [% s]] "'
The response=make_response (text_str % (xml_objt. FromUserName, xml_objt ToUserName, STR (int (time. Time ())), xml_objt. Content))
. The response headers [' the content-type ']='application/XML'
Return the response
The else:
Return make_response (" ")

The message to accept and parsing the following
 
# - * - coding: utf-8 - * -
The import XML. Etree. ElementTree as ET


Def parse_xml (web_data) :
If len (web_data)==0:
Return None
XmlData=https://bbs.csdn.net/topics/ET.fromstring (web_data)
Msg_type=xmlData. Find (" MsgType "). The text
Print (msg_type, xmlData)
Print (ET. Tostring (xmlData))
If msg_type=='event' :
The event_type=xmlData. Find (' Event '). The text
If the event_type=='CLICK' :
Return the Click (xmlData)
Elif the event_type in (' subscribe 'and' unsubscribe ') :
Return the Subscribe (xmlData)
Elif msg_type=='text:
Return TextMsg (xmlData)
Elif msg_type=='image' :
Return ImageMsg (xmlData)
Elif msg_type=='voice' :
Return VoiceMsg (xmlData)
The else:
The return of Msg (xmlData)


The class Msg (object) :
Def __init__ (self, xmlData) :
Self. ToUserName=xmlData. Find (' ToUserName). The text
Self. FromUserName=xmlData. Find (' FromUserName). The text
Self. CreateTime=xmlData. Find (" CreateTime "). The text
The self. The MsgType=xmlData. Find (" MsgType "). The text

The class TextMsg (Msg) :
Def __init__ (self, xmlData) :
Msg. __init__ (self, xmlData)
The self. The Content=xmlData. Find (' Content '). The text

Has ruled out the problem
 
1. There is no space interface in the return value
2. The interface is the return value field values are correct, ToUserName and FromUserName not
3. The XML return value of the node name right
4. Return code no problem
No. 5. Public backend server configuration is enabled
6. DNS is normal, normal port access
Number 7. The public is not bound to a third party platform

Other public have changed their names, accept to the user in the message here ToUserName is original ID, rather than the current public ID number, don't know whether there is influence
And now WeChat public operations of port alarm function cannot be used, so can't pass this test

CodePudding user response:

Tornado configuration as well as the Flask to run the code
 
App=Flask (__name__)
App. The debug=True
Define (" debug ", the default=True, help="debug Mode", type=bool)
...
If __name__=="__main__ ':
Options. Parse_command_line ()
Http_server=HTTPServer (WSGIContainer (app))
Http_server. Listen (80)
IOLoop. The instance (). The start ()

In addition, the interface URL is also no problem, there is no lack of '/' problem
  • Related