微信相关接口
This project provides a FastAPI-based API to manage and retrieve the WeChat access token. The access token is automatically refreshed every 7000 seconds and can also be manually refreshed via a POST request. The API also includes logging to track access token retrieval and refresh operations.
- Automatically refresh WeChat access token every 7000 seconds.
- Manually refresh access token via a POST request.
- Retrieve the current access token via a GET request.
- Logging of access token retrieval and refresh operations.
- Log files are rotated weekly.
- Python 3.7 or higher
- Pip (Python package installer)
-
Clone the repository:
git clone https://github.com/Agent-Universe/wx_utils.git cd wx_utils -
Install the required Python packages:
pip install fastapi uvicorn requests python-dotenv apscheduler
-
Create a
.envfile in the root directory of the project and add your WeChat AppID and AppSecret:APP_ID=your_app_id APP_SECRET=your_app_secret
-
Ensure that your server's IP address is added to the IP whitelist in the WeChat public platform settings.
-
Start the FastAPI application:
uvicorn getAccessToken:app --reload
-
The API will be available at
http://127.0.0.1:8000.
- URL:
/access_token - Method:
GET - Response:
{ "access_token": "your_access_token" }
- URL:
/refresh_token - Method:
POST - Response:
{ "message": "Access token refreshed successfully", "access_token": "your_new_access_token" }
- Logs are stored in the
.log/directory. - Log files are named
access_token.logand are rotated weekly. - Log entries include timestamps, log levels, and messages.
Contributions are welcome! Please feel free to submit a pull request or open an issue.
This project is licensed under the MIT License. See the LICENSE file for details.
For any questions or support, please contact L4Walk.