Test.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace app\index\controller;
  3. use think\Controller;
  4. use \GatewayWorker\Lib\Gateway;
  5. use app\common\library\Tlssigapiv2;
  6. class Test extends Controller
  7. {
  8. public function test(){
  9. $Gateway = new Gateway();
  10. $Gateway::$registerAddress = '127.0.0.1:2345';
  11. $Gateway::sendToAll('来自服务端的主动推送'.date('Y-m-d H:i:s'));
  12. }
  13. public function ip(){
  14. $ipaddress = ip_to_address();
  15. echo $ipaddress;
  16. }
  17. public function newip(){
  18. $ipaddress = newip_to_address();
  19. echo $ipaddress;
  20. }
  21. public function im(){
  22. $sdkappid = '1400818730';
  23. $sdkappkey = 'f31aa80a36cef72829fbcdcb10aa2aadcea2944787f2b268d46021e67711326b';
  24. $usersig = $this->usersig($sdkappid,$sdkappkey);
  25. $random = rand(10000000,99999999);
  26. $url = 'https://console.tim.qq.com/v4/open_msg_svc/get_history?sdkappid='.$sdkappid.'&identifier=administrator&usersig='.$usersig.'&random='.$random.'&contenttype=json';
  27. $data = [
  28. 'ChatType' => 'Group',
  29. 'ChatType' => 'C2C',
  30. // 'MsgTime' => date('YmdH',strtotime('-1 Days')),
  31. 'MsgTime' => date('YmdH',strtotime('-20 Hours')),
  32. ];
  33. dump($data);
  34. $jsonStr = json_encode($data);
  35. $header = array(
  36. 'Content-Type: application/json; charset=utf-8',
  37. 'Content-Length: ' . strlen($jsonStr)
  38. );
  39. $rs = curl_post($url,$jsonStr,$header);
  40. $rs = json_decode($rs,true);
  41. dump($rs);
  42. if(is_array($rs) && isset($rs['ErrorCode']) && $rs['ErrorCode'] == 0){
  43. //正常的,可以下载了
  44. if(isset($rs['File']) && !empty($rs['File'])){
  45. foreach($rs['File'] as $key => $val){
  46. //下载
  47. $newgz = downloadfile($val['URL'],$data['ChatType'],$data['MsgTime'].'_'.$data['ChatType'].'.json.gz');
  48. echo $newgz;
  49. //解压
  50. //分析
  51. //入库
  52. }
  53. }
  54. }
  55. }
  56. //测试下载gz
  57. public function test11(){
  58. $data = [
  59. 'ChatType' => 'C2C',
  60. 'MsgTime' => date('YmdH',strtotime('-20 Hours')),
  61. ];
  62. $url = 'https://download.tim.qq.com/msg_history/v2/e9c80dce105d880ab8f62f0d267983c0edf3aff49031f5b06204c3402ddbdaf63a7b2aed.gz';
  63. $newgz = downloadfile($url,$data['ChatType'],$data['MsgTime'].'_'.$data['ChatType'].'.json.gz');
  64. }
  65. private function usersig($sdkappid,$key){
  66. $api = new TLSSigAPIv2($sdkappid,$key );
  67. $sig = $api->genUserSig('administrator');
  68. return $sig;
  69. }
  70. public function test_redis(){
  71. $redis = new Redis();
  72. $redisconfig = config("redis");
  73. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  74. if ($redisconfig['redis_pwd']) {
  75. $redis->auth($redisconfig['redis_pwd']);
  76. }
  77. if($redisconfig['redis_selectdb'] > 0){
  78. $redis->select($redisconfig['redis_selectdb']);
  79. }
  80. $party_id = 141;
  81. $res = $redis->hGetAll("online_".$party_id);
  82. dump($res);
  83. }
  84. }