Home >Backend Development >Python Tutorial >How to write a public account in python
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.
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.
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()
3. Then in the project directory, open cmd and enter python app.py, so that the program will run~
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.
5. Find and enter the development configuration page and click Modify Configuration.
#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.
#7. Then return to the server configuration page and click Enable.
##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!