123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace App\Http\Controllers;
- use GatewayWorker\Lib\Gateway;
- use GuzzleHttp\Client;
- use Illuminate\Http\Request;
- use Illuminate\Log\Logger;
- use Illuminate\Support\Facades\Log;
- use App\Models\ModelsInfoLog;
- class TcpController extends Controller
- {
- public function Accept($client_id,$string){
- Log::info($string);
- die();
- $infos=new ModelsInfoLog();
- $infos->string=$string;
- $infos->save();
- $result=mb_strpos($string,'http');
- $m=mb_strpos($string,'CL');
- if ($result === false) {
- Gateway::sendToClient($client_id,$string);
- die();
- }else{
- if ($m===false){
- Gateway::sendToClient($client_id,$string);
- die();
- }
- }
- Log::info($result);
- try {
- $file_name=public_path().'/txtlog/'.date('y-m-d').'.txt';
- if (file_exists($file_name)){
- $file = fopen($file_name, "a");
- $content = $string . PHP_EOL; // 添加换行符
- fwrite($file, $content);
- fclose($file);
- }else{
- $filename =$file_name;
- $file = fopen($filename, "w");
- if ($file) {
- // 更改文件权限为可读可写
- chmod($filename, 0666);
- $content = $string . PHP_EOL; // 添加换行符
- $file = fopen($file_name, "a");
- fwrite($file, $content);
- fclose($file);
- echo "文件已创建并写入内容,并更改权限为可读可写。";
- } else {
- echo "无法创建文件。";
- }
- }
- }catch (\Exception $exception){
- $file_name=public_path().'/txtlog/2023-06-20.txt';
- $file = fopen($file_name, "a");
- $content = '异常'.$string . PHP_EOL; // 添加换行符
- fwrite($file, $content);
- fclose($file);
- }
- $url='http://fangw.jiuweiyun.cn/api/getinfo';
- $client=new Client();
- $data = [
- 'sign' => 'AD253SghasdklasSdafAGAdsa541',
- 'string' => $string,
- ];
- $re=$client->post($url,[
- 'form_params' => $data,
- ]);
- $re=$re->getBody()->getContents();
- $re=json_decode($re);
- if ($re->status==0){
- Log::error($re->message);
- Gateway::sendToClient($client_id,json_encode(['msg'=>'失败了','code'=>0000]));
- }else{
- $infos->status=1;
- $infos->save();
- }
- }
- }
|