chore: 更新示例
This commit is contained in:
parent
9d13324545
commit
140fb486f6
@ -1,23 +1,50 @@
|
||||
<?php
|
||||
|
||||
|
||||
try {
|
||||
$obj = new WxworkFinanceSdk("wwd08coe7d775abaaa", "zJ6k0naVVQ--gt9PUSSEvs03zW_nlDVmjAkPOTAfrew", [
|
||||
"proxy_password" => "world",
|
||||
"timeout" => -2,
|
||||
]);
|
||||
// 私钥地址
|
||||
$privateKey = file_get_contents('private.pem');
|
||||
|
||||
$chats = json_decode($obj->getChatData(0, 100), true);
|
||||
var_dump($chats);
|
||||
foreach ($chats['chatdata'] as $val) {
|
||||
$decryptRandKey = null;
|
||||
openssl_private_decrypt(base64_decode($val['encrypt_random_key']), $decryptRandKey, $privateKey, OPENSSL_PKCS1_PADDING);
|
||||
$obj->downloadMedia($sdkFileId, "/tmp/download/文件新名称.后缀");
|
||||
gc_enable();
|
||||
$startMemUsed = memory_get_usage();
|
||||
function cal_mem()
|
||||
{
|
||||
global $startMemUsed;
|
||||
echo "memory,", ceil((memory_get_usage() - $startMemUsed) / 1024), 'KB', PHP_EOL;
|
||||
}
|
||||
echo "start mypid=", getmypid(), PHP_EOL;
|
||||
sleep(2);
|
||||
$sdk = new WxworkFinanceSdk("1", "2");
|
||||
$privateKey = <<<EOF
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
|
||||
-----END RSA PRIVATE KEY-----
|
||||
EOF;
|
||||
$seq = 0;
|
||||
$str = str_repeat('X', 1024 * 1024);
|
||||
|
||||
}catch(\WxworkFinanceSdkException $e) {
|
||||
var_dump($e->getMessage(), $e->getCode());
|
||||
}
|
||||
do{
|
||||
|
||||
echo "sync seq={$seq} ==>", cal_mem(), PHP_EOL;
|
||||
gc_mem_caches();
|
||||
gc_collect_cycles();
|
||||
$wxChat = $sdk->getChatData($seq, 100);
|
||||
$chats = json_decode($wxChat, true);
|
||||
$chatRows = $chats['chatdata'];
|
||||
foreach ($chatRows as $val) {
|
||||
$decryptRandKey = null;
|
||||
$decryptData = openssl_private_decrypt(base64_decode($val['encrypt_random_key']), $decryptRandKey, $privateKey, OPENSSL_PKCS1_PADDING);
|
||||
$decryptChatRawContent = $sdk->decryptData($decryptRandKey, $val['encrypt_chat_msg']);
|
||||
$j2 = json_decode($decryptChatRawContent, true);
|
||||
$msgType = $j2['msgtype'];
|
||||
if (in_array($msgType, ['image', 'video'])) {
|
||||
try {
|
||||
$sdk->downloadMedia($j2[$msgType]['sdkfileid'], "/tmp/download/{$j2[$msgType]['md5sum']}");
|
||||
}catch(\Exception $e) {
|
||||
var_dump($e);
|
||||
var_dump($e->getMessage(), $e->getCode());
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
unset($decryptRandKey);
|
||||
}
|
||||
echo "loop done ===>", cal_mem();
|
||||
unset($chatRows, $wxChat, $chats);
|
||||
gc_collect_cycles();gc_collect_cycles();
|
||||
$seq = $val['seq'];
|
||||
}while(true);
|
||||
cal_mem();
|
||||
Loading…
x
Reference in New Issue
Block a user