Download the PHP package bangbangda/wecomarchive without Composer
On this page you can find all versions of the php package bangbangda/wecomarchive. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bangbangda/wecomarchive
More information about bangbangda/wecomarchive
Files in bangbangda/wecomarchive
Package wecomarchive
Short Description PHP extension for WeCom (WeChat Work) Chat Archive functionality. Provides object-oriented interface to fetch chat messages, decrypt content, and download media files.
License PHP-3.01
Homepage https://github.com/bangbangda/wecomarchive
Informations about the package wecomarchive
wecomarchive
English | 简体中文
📖 中国用户请查看 中文文档 →
PHP extension for WeCom (WeChat Work) Chat Archive functionality.
Install with PIE:
pie install bangbangda/wecomarchive
Features
- Automatic SDK Download: WeCom SDK is automatically downloaded during installation
- Object-Oriented Interface: Clean, modern PHP API for chat archive operations
- Full Functionality: Fetch messages, decrypt content, download media files
- Flexible Configuration: Support for custom SDK paths and proxy settings
Requirements
- PHP >= 8.0
- Linux (x86_64 or ARM64)
- OpenSSL >= 1.1.0
Installation
Method 1: PIE (Recommended)
PIE is the modern way to install PHP extensions.
Basic Installation (Automatic):
The WeCom SDK will be automatically downloaded during installation to /usr/local/lib/.
Advanced Configuration:
If you need to customize the SDK path or the automatic download fails:
Note: If automatic download fails due to permission issues, you may need to run:
Method 2: Manual Installation
-
Download and extract the source:
- Build the extension (SDK will be downloaded automatically during configure):
The WeCom SDK will be automatically downloaded to /usr/local/lib/ during the ./configure step.
If you want to use a custom SDK path:
If automatic download fails, you can manually download the SDK first:
- Enable the extension in php.ini:
Configuration
| INI Setting | Default | Description |
|---|---|---|
wecomarchive.sdk_lib_path |
/usr/local/lib/libWeWorkFinanceSdk_C.so |
Path to the WeCom SDK library |
Usage
Basic Example
Multi-version Private Keys (Recommended)
WeCom supports rotating the chat-archive private key. Each chat item carries a publickey_ver
field. Configure private_keys and use decryptChatItem() to let the extension auto-select
the correct private key for each item:
If publickey_ver cannot be matched in private_keys, a clear exception is thrown
naming the missing version.
Download Media Files
Using Proxy
Custom SDK Library Path
API Reference
WeComArchive Class
Constructor
Options:
corpid(required): Your WeCom Corp IDsecret(required): Chat archive secretprivate_key(optional): A single RSA private key. Accepts either PEM content or a file path (auto-detected). Used bydecryptData()private_keys(optional): Multi-version key map[publickey_ver => PEM-or-path]. Used bydecryptChatItem()for auto-selectionlib_path(optional): Custom path to SDK library
Detection rule: a value is treated as raw PEM content if it spans multiple lines (PEM bodies always contain newlines, file paths do not) or starts with
-----BEGIN. Single-line values without the PEM header are treated as a file path. This tolerates PEM exports that have leading metadata (e.g.Bag Attributeslines fromopenssl pkcs12).private_keyandprivate_keysmay both be set — the former acts as a fallback fordecryptChatItem().
getChatData
Fetch chat messages.
Parameters:
$seq: Starting sequence number (0 for first fetch)$limit: Maximum messages to fetch (1-1000)$options: Optional settings (proxy, passwd, timeout)
Returns: JSON string with chat data
decryptData
Decrypt a chat message using the private_key provided at construction time.
Parameters:
$encryptRandomKey: Theencrypt_random_keyfrom chat data$encryptChatMsg: Theencrypt_chat_msgfrom chat data
Returns: Decrypted message as JSON string
Throws: WECOM_ERR_PRIKEY if no private_key was configured.
decryptChatItem
Decrypt one chatdata item, auto-selecting the private key from private_keys by its publickey_ver.
Parameters:
$chatItem: One element from thechatdataarray returned bygetChatData(). Must containencrypt_random_keyandencrypt_chat_msg; ifpublickey_veris present it is used to pick the matching key fromprivate_keys
Returns: Decrypted message as JSON string
Throws:
WECOM_ERR_PRIKEY— no key configured at all (neitherprivate_keysnorprivate_key)WECOM_ERR_PRIKEY—publickey_vernot found inprivate_keys(error message names the missing version)WECOM_ERR_PARAM— chat item is missing required fields
getMediaData
Download media file content.
Parameters:
$sdkFileId: Thesdkfileidfrom message$options: Optional settings (proxy, passwd, timeout)
Returns: Binary content of the media file
getSdkVersion
Get the SDK version.
Error Codes
| Code | Constant | Description |
|---|---|---|
| 10000 | WECOM_ERR_PARAM |
Parameter error |
| 10001 | WECOM_ERR_NETWORK |
Network error |
| 10002 | WECOM_ERR_PARSE |
Data parse failed |
| 10003 | WECOM_ERR_SYSTEM |
System error |
| 10004 | WECOM_ERR_ENCRYPT |
Encryption failed |
| 10005 | WECOM_ERR_FILEID |
Invalid file ID |
| 10006 | WECOM_ERR_DECRYPT |
Decryption failed |
| 10007 | WECOM_ERR_PRIKEY |
Private key not found |
| 10008 | WECOM_ERR_ENCKEY |
Encrypt key parse error |
| 10009 | WECOM_ERR_IP |
IP not allowed |
| 10010 | WECOM_ERR_EXPIRED |
Data expired |
| 10011 | WECOM_ERR_CERT |
Certificate error |
License
PHP License 3.01