Install PowerWeChat v3
release/3.4.0Install the PowerWeChat SDK using Go modules:
go get -u github.com/ArtisanCloud/PowerWeChat/v3repository·release/3.4.0·Indexed 23 days ago
https://github.com/artisancloud/powerwechatA Golang-based SDK framework designed to simplify WeChat development. It provides abstractions for Mini Programs, WeChat Official Accounts, WeChat Pay, WeCom (Enterprise WeChat), Open Platform, and Open Work. The SDK handles complex tasks such as AES encryption, signature verification, callback decryption, and token management. Version 3 introduces context support and updated token refresh behavior.
Install the PowerWeChat SDK using Go modules:
go get -u github.com/ArtisanCloud/PowerWeChat/v3When upgrading from version 2 to version 3, note the following breaking changes:
context.Context parameter.The dataCube.Client provides access to WeChat Official Account analytics data, including user growth, article engagement, message distribution, and interface usage. Most methods require a context.Context and a date range defined by from and to strings (typically in YYYY-MM-DD format).
Methods are categorized by the type of data they retrieve:
The express.Client provides an interface to interact with WeChat Mini Program logistics APIs, including order management, account binding, and tracking. It requires a *kernel.BaseClient to handle the underlying HTTP communication with WeChat servers.
Key capabilities include:
broadcasting.Client provides methods to send mass messages (broadcasts) to WeChat Official Accounts (both Subscription and Service accounts). It supports sending by tags, specific users, or to all users, as well as previewing, deleting, and checking the status of broadcasted messages.security.Client provides methods to interact with WeChat Mini Program security APIs, including image security checks, asynchronous media content verification, and text content security checks. It requires a BaseClient to handle the underlying HTTP communication.wxaCode.Client provides methods to generate and manage WeChat Mini Program QR codes, including standard QR codes, single QR codes, and unlimited QR codes (for high-volume scenarios). It uses a BaseClient to handle the underlying HTTP requests to WeChat's servers.For large files (videos up to 500MB, covers up to 10MB), use the three-step chunked upload process:
ApplyMediaUploadId to get a unique upload_id for the session.ApplyMediaChunkUpload multiple times (up to 100 chunks, max 5MB each) using the upload_id and a part_number. Chunks can be uploaded out of order.UploadMediaChunkComplete to merge all chunks. You must provide the part_number and etag for every chunk to verify integrity.func (comp *Client) ApplyMediaUploadId(ctx context.Context, in *request.VideoApplyChunkUploadByIdRequest) (result *response.VideoApplyChunkUploadByIdResponse, err error)
func (comp *Client) ApplyMediaChunkUpload(ctx context.Context, in *request.VideoApplyChunkUploadRequest) (result *response.VideoApplyChunkUploadResponse, err error)
func (comp *Client) UploadMediaChunkComplete(ctx context.Context, in *request.VideoChunkUploadCompleteRequest) (result *response.VideoChunkUploadCompleteResponse, err error)The SubscribeAndServe method is the recommended way to run an AIBot. It performs the following lifecycle steps:
botID and secret.Listen for incoming messages and pass them to your MessageHandler.Heartbeat (ping) every 30 seconds to keep the connection alive.If an error occurs in either the listener or the heartbeat loop, the connection is closed and the error is returned.
To use the SDK, initialize an application instance using NewMiniProgram with a UserConfig object, then use the sub-modules (like Auth) to call WeChat APIs.
Key configuration fields in miniProgram.UserConfig:
AppID: The AppID for the Mini Program, Official Account, or WeCom.Secret: The AppSecret.HttpDebug: Boolean to enable HTTP debugging.Debug: Boolean to enable debug mode.The BaseClient reads several configuration keys from the ApplicationInterface to set up the underlying HTTP transport. Use these keys in your application configuration:
http.base_uri: The base URL for requests (defaults to /).http.proxy_uri: The proxy URI to use.http.timeout: Request timeout in seconds (defaults to 5).http.transport: An http.RoundTripper implementation for custom transport logic.http.proxy: An alternative proxy configuration key.debug: Boolean to enable debug mode (adds debug=1 to queries).http_debug: Boolean to enable HTTP debug logging.If you need to sign requests using WeChat Pay's RSA mechanism, provide the following configuration keys in your application config. If all three are present, a SHA256WithRSASigner is automatically initialized in the BaseClient:
mch_id: The Merchant ID.serial_no: The Certificate Serial Number.key_path: The file path to the private key.