TcpController.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Http\Controllers;
  3. use GatewayWorker\Lib\Gateway;
  4. use GuzzleHttp\Client;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Log\Logger;
  7. use Illuminate\Support\Facades\Log;
  8. use App\Models\ModelsInfoLog;
  9. class TcpController extends Controller
  10. {
  11. public function Accept($client_id,$string){
  12. Log::info($string);
  13. die();
  14. $infos=new ModelsInfoLog();
  15. $infos->string=$string;
  16. $infos->save();
  17. $result=mb_strpos($string,'http');
  18. $m=mb_strpos($string,'CL');
  19. if ($result === false) {
  20. Gateway::sendToClient($client_id,$string);
  21. die();
  22. }else{
  23. if ($m===false){
  24. Gateway::sendToClient($client_id,$string);
  25. die();
  26. }
  27. }
  28. Log::info($result);
  29. try {
  30. $file_name=public_path().'/txtlog/'.date('y-m-d').'.txt';
  31. if (file_exists($file_name)){
  32. $file = fopen($file_name, "a");
  33. $content = $string . PHP_EOL; // 添加换行符
  34. fwrite($file, $content);
  35. fclose($file);
  36. }else{
  37. $filename =$file_name;
  38. $file = fopen($filename, "w");
  39. if ($file) {
  40. // 更改文件权限为可读可写
  41. chmod($filename, 0666);
  42. $content = $string . PHP_EOL; // 添加换行符
  43. $file = fopen($file_name, "a");
  44. fwrite($file, $content);
  45. fclose($file);
  46. echo "文件已创建并写入内容,并更改权限为可读可写。";
  47. } else {
  48. echo "无法创建文件。";
  49. }
  50. }
  51. }catch (\Exception $exception){
  52. $file_name=public_path().'/txtlog/2023-06-20.txt';
  53. $file = fopen($file_name, "a");
  54. $content = '异常'.$string . PHP_EOL; // 添加换行符
  55. fwrite($file, $content);
  56. fclose($file);
  57. }
  58. $url='http://fangw.jiuweiyun.cn/api/getinfo';
  59. $client=new Client();
  60. $data = [
  61. 'sign' => 'AD253SghasdklasSdafAGAdsa541',
  62. 'string' => $string,
  63. ];
  64. $re=$client->post($url,[
  65. 'form_params' => $data,
  66. ]);
  67. $re=$re->getBody()->getContents();
  68. $re=json_decode($re);
  69. if ($re->status==0){
  70. Log::error($re->message);
  71. Gateway::sendToClient($client_id,json_encode(['msg'=>'失败了','code'=>0000]));
  72. }else{
  73. $infos->status=1;
  74. $infos->save();
  75. }
  76. }
  77. }