usersig($sdkappid,$sdkappkey); $random = rand(10000000,99999999); $url = 'https://console.tim.qq.com/v4/open_msg_svc/get_history?sdkappid='.$sdkappid.'&identifier=administrator&usersig='.$usersig.'&random='.$random.'&contenttype=json'; $data = [ 'ChatType' => 'Group', 'ChatType' => 'C2C', // 'MsgTime' => date('YmdH',strtotime('-1 Days')), 'MsgTime' => date('YmdH',strtotime('-20 Hours')), ]; dump($data); $jsonStr = json_encode($data); $header = array( 'Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen($jsonStr) ); $rs = curl_post($url,$jsonStr,$header); $rs = json_decode($rs,true); dump($rs); if(is_array($rs) && isset($rs['ErrorCode']) && $rs['ErrorCode'] == 0){ //正常的,可以下载了 if(isset($rs['File']) && !empty($rs['File'])){ foreach($rs['File'] as $key => $val){ //下载 $newgz = downloadfile($val['URL'],$data['ChatType'],$data['MsgTime'].'_'.$data['ChatType'].'.json.gz'); echo $newgz; //解压 //分析 //入库 } } } } //测试下载gz public function test11(){ $data = [ 'ChatType' => 'C2C', 'MsgTime' => date('YmdH',strtotime('-20 Hours')), ]; $url = 'https://download.tim.qq.com/msg_history/v2/e9c80dce105d880ab8f62f0d267983c0edf3aff49031f5b06204c3402ddbdaf63a7b2aed.gz'; $newgz = downloadfile($url,$data['ChatType'],$data['MsgTime'].'_'.$data['ChatType'].'.json.gz'); } private function usersig($sdkappid,$key){ $api = new TLSSigAPIv2($sdkappid,$key ); $sig = $api->genUserSig('administrator'); return $sig; } public function test_redis(){ $redis = new Redis(); $redisconfig = config("redis"); $redis->connect($redisconfig["host"], $redisconfig["port"]); if ($redisconfig['redis_pwd']) { $redis->auth($redisconfig['redis_pwd']); } if($redisconfig['redis_selectdb'] > 0){ $redis->select($redisconfig['redis_selectdb']); } $party_id = 141; $res = $redis->hGetAll("online_".$party_id); dump($res); } }