1. Go to this page and download the library: Download bangbangda/wecomarchive library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bangbangda / wecomarchive example snippets
// Initialize with your credentials. private_key accepts either PEM content or a file path
// (auto-detected — values starting with "-----BEGIN " are treated as PEM content).
$archive = new WeComArchive([
'corpid' => 'your_corp_id',
'secret' => 'your_secret',
'private_key' => '/path/to/private.pem', // or raw PEM string
]);
// Fetch chat data
$response = $archive->getChatData(seq: 0, limit: 100);
$data = json_decode($response, true);
if ($data['errcode'] === 0) {
foreach ($data['chatdata'] as $chat) {
// Decrypt message
$message = $archive->decryptData(
$chat['encrypt_random_key'],
$chat['encrypt_chat_msg']
);
$msgData = json_decode($message, true);
print_r($msgData);
}
}