-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathwxwork_finance_sdk.php
50 lines (47 loc) · 1.78 KB
/
wxwork_finance_sdk.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
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);
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();