_get_wechat_access_token
- ValueError: If credentials are missing or token retrieval fails.
- References:
- https: //developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html
_make_wechat_request
- method (
Literal["GET", "POST"]
): HTTP method (‘GET’ or ‘POST’). - endpoint (str): API endpoint path. **kwargs: Additional arguments for requests.
- requests.exceptions.RequestException: If request fails.
- ValueError: If API returns an error.
WeChatOfficialToolkit
- Documentation: https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Overview.html
- Test Account: https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login
init
send_customer_message
- openid (str): The user’s OpenID.
- content (str): Message content or media_id for non-text messages.
- msgtype (str): Message type: “text”, “image”, “voice”, “video”.
get_user_info
- openid (str): The user’s OpenID.
- lang (str): Response language. Common values: “zh_CN”, “zh_TW”, “en”. (default: “zh_CN”)
get_followers_list
- next_openid (str): Starting OpenID for pagination. (default: "") (default:
""
)
upload_wechat_media
- media_type (str): Media type: “image”, “voice”, “video”, “thumb”.
- file_path (str): Local file path.
- permanent (bool): Whether to upload as permanent media. (default: :obj:
False
) - description (Optional[str]): Video description in JSON format for permanent upload. (default: :obj:
None
)
- Temporary: https://developers.weixin.qq.com/doc/offiaccount/ Asset_Management/Adding_Temporary_Assets.html
- Permanent: https://developers.weixin.qq.com/doc/offiaccount/ Asset_Management/Adding_Permanent_Assets.html
get_media_list
- media_type (str): Media type: “image”, “voice”, “video”, “news”.
- offset (int): Starting position. (default: :obj:
0
) (default: 0) - count (int): Number of items (1-20). (default: :obj:
20
) (default: 20)
send_mass_message_to_all
- content (str): For text, the message content; for non-text, the media_id.
- msgtype (
Literal["text","image","voice","video"]
): Message type. For “video”, the mass API expects “mpvideo” internally. - clientmsgid (Optional[str]): Idempotency key to avoid duplicate mass jobs.
- send_ignore_reprint (Optional[int]): Whether to continue when a news article is judged as a reprint (reserved; applies to news/mpnews).
- batch_size (int): Max OpenIDs per request (WeChat limit is up to 10000 per batch).
- Mass send by OpenID list: https://developers.weixin.qq.com/doc/service/api/notify/message/ api_masssend.html