Example of using WeChat API in the Python Bottle framework

Source: Internet
Author: User

Example of using APIs in the Python Bottle framework

This article mainly introduces the example of using APIs in the Python Bottle framework. The author also provides a generated scanner QR code. For more information, see

It is estimated that Otaku is not familiar with this thing. After so many years of development, he finally made a friendly step to the open platform. I thought it would have a detailed api and Other interfaces. I was excited to apply for a public platform, and then began to find the location of various Apis ......

It took nearly an hour and still could not be found ......

Finally, I used the Google kill and finally found such a link. I went here. It's no more simple api documentation than that.

What is most incomprehensible is that there is no local development environment support and debugging should be conducted in the production environment every time.

The most gratifying thing is that the production environment debugging is complete several times.

The Python (bottle) version code is as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

#-*-Coding: UTF-8 -*-

 

From bottle import debug, default_app, run, get, request, post

 

Import sys, OS, time, libxml2dom

 

@ Get ('/')

 

Def index ():

 

Return request. GET. get ('echostr ')

 

@ Post ('/')

 

Def index_post ():

 

For key, value in request. POST. allitems ():

 

Doc = libxml2dom. parseString (key)

 

_ To = doc. xpath ('// fromusername') [0]. textContent

 

_ From = doc. xpath ('// tousername') [0]. textContent

 

# _ Content = doc. xpath ('// content') [0]. textContent

 

Return "" <xml>

 

<ToUserName> <! [CDATA [% s]> </ToUserName>

 

<FromUserName> <! [CDATA [% s]> </FromUserName>

 

<CreateTime> % s </CreateTime>

 

<MsgType> <! [CDATA [text]> </MsgType>

 

<Content> <! [CDATA [% s]> </Content>

 

<FuncFlag> 0 </FuncFlag>

 

</Xml> "" % (_ to, _ from, int (time. time (), u'let me go ')

 

If _ name _ = "_ main __":

 

# Interactive mode

 

Debug (True)

 

Port = int (sys. argv [1] if len (sys. argv)> 1 else 8888)

 

Run (host = '0. 0.0.0 ', port = port, reloader = True)

 

Else:

 

# Mod WSGI launch

 

OS. chdir (OS. path. dirname (_ file __))

 

App = default_app ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.