Home >Backend Development >Python Tutorial >How to write a public account in python

How to write a public account in python

coldplay.xixi
coldplay.xixiOriginal
2020-11-03 11:39:013552browse

How to write a public account in python: first run cmd, enter [pip install werobot] to install the WeRoBot framework; then open the ide, open cmd in the project directory, enter [python app.py] and run; finally, the service program Just log in to the public account and modify the configuration.

How to write a public account in python

Related free learning recommendations: python video tutorial

How to write public accounts in python:

1. WeRoBot is a WeChat public account development framework that has encapsulated various interface functions for us. Here we will use it to complete the development function of the public account. First run cmd and enter pip install werobot to install the framework.

How to write a public account in python

2. Then open the ide (Visual Studio Code used by the editor). Here we use WeRoBot to implement a small example of hello world. The code is as follows (the code is saved as app. py):

       import werobot
       # token由自己定义,之后会用到
       robot = werobot.WeRoBot(token='tokenhere') 
       @robot.handler
       def hello(message):
              return 'Hello World!'
       # 让服务器监听在 0.0.0.0:80
       robot.config['HOST'] = '0.0.0.0'
       robot.config['PORT'] = 80
       robot.run()

How to write a public account in python

3. Then in the project directory, open cmd and enter python app.py, so that the program will run~

How to write a public account in python

4. After the program is running, we need to connect the service program to the public account. First, log in and enter the official account management platform.

How to write a public account in python

5. Find and enter the development configuration page and click Modify Configuration.

How to write a public account in python

#6. We fill in the URL of our previous service (such as http://xx.xx.xx.xx:80) and token in order, and randomly generate an encryption Just enter the secret key, then select plain text mode and submit.

How to write a public account in python

#7. Then return to the server configuration page and click Enable.

How to write a public account in python

##Related learning recommendations: WeChat public account development Tutorial

The above is the detailed content of How to write a public account in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn