Skip to content

Agent-Universe/wx_utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wx_utils

微信相关接口


WeChat Access Token API

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.

Table of Contents

Features

  • 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.

Prerequisites

  • Python 3.7 or higher
  • Pip (Python package installer)

Installation

  1. Clone the repository:

    git clone https://github.com/Agent-Universe/wx_utils.git
    cd wx_utils
  2. Install the required Python packages:

    pip install fastapi uvicorn requests python-dotenv apscheduler

Configuration

  1. Create a .env file in the root directory of the project and add your WeChat AppID and AppSecret:

    APP_ID=your_app_id
    APP_SECRET=your_app_secret
  2. Ensure that your server's IP address is added to the IP whitelist in the WeChat public platform settings.

Usage

  1. Start the FastAPI application:

    uvicorn getAccessToken:app --reload
  2. The API will be available at http://127.0.0.1:8000.

API Endpoints

Get Current Access Token

  • URL: /access_token
  • Method: GET
  • Response:
    {
      "access_token": "your_access_token"
    }

Manually Refresh Access Token

  • URL: /refresh_token
  • Method: POST
  • Response:
    {
      "message": "Access token refreshed successfully",
      "access_token": "your_new_access_token"
    }

Logging

  • Logs are stored in the .log/ directory.
  • Log files are named access_token.log and are rotated weekly.
  • Log entries include timestamps, log levels, and messages.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue.

License

This project is licensed under the MIT License. See the LICENSE file for details.


For any questions or support, please contact L4Walk.

About

微信相关接口

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages