<?php

namespace app\product\controller;

use app\product\model\Product as PoductModel;

class KillOut
{
    public function list()
    {
        
        $product_model = new PoductModel;
        $qiangzi = $product_model->getOne(['Id'=>1]);
        $xunlian = $product_model->getOne(['Id'=>2]);
        $huohu = $product_model->getOne(['Id'=>19]);

        $header[] = $qiangzi['Token'];
        $url = 'http://47.92.116.14:2222/agent/clientOnlineList';
        $content = '';
        $result = [];
        $content = linkcurl($url,'GET',false,$header);

        preg_match_all("/<table(.*?)<\/table>/is", $content, $result);
        echo str_replace('/agent/clientDisconnect?','/product/killOut/kill?priduct=1&',$result[0][0]);

        $header2[] = $xunlian['Token'];
        $url2 = 'http://47.92.65.184:2223/agent/clientOnlineList';
        $content2 = '';
        $result2 = [];
        $content2 = linkcurl($url2,'GET',false,$header2);

        preg_match_all("/<table(.*?)<\/table>/is", $content2, $result2);
        echo str_replace('/agent/clientDisconnect?','/product/killOut/kill?priduct=2&',$result2[0][0]);

        $header3[] = $huohu['Token'];
        $url3 = 'http://106.52.152.33:8899/agent/clientOnlineList';
        $content3 = '';
        $result3 = [];
        $content3 = linkcurl($url3,'GET',false,$header3);

        preg_match_all("/<table(.*?)<\/table>/is", $content3, $result3);
        echo str_replace('/agent/clientDisconnect?','/product/killOut/kill?priduct=19&',$result3[0][0]);
    }

    public function kill()
    {
        $data = $_GET;
        if($data['priduct'] == 1){
            $url = 'http://47.92.116.14:2222/agent/clientDisconnect?token='.$data['token'];
            $product_model = new PoductModel;
            $product = $product_model->getOne(['Id'=>1]);

            $header[] = $product['Token'];
            linkcurl($url,'GET',false,$header);
        } elseif($data['priduct'] == 2) {
            $url = 'http://47.92.65.184:2223/agent/clientDisconnect?token='.$data['token'];
            $product_model = new PoductModel;
            $product = $product_model->getOne(['Id'=>2]);

            $header[] = $product['Token'];
            linkcurl($url,'GET',false,$header);
        } else  {
            $url = 'http://106.52.152.33:8899/agent/clientDisconnect?token='.$data['token'];
            $product_model = new PoductModel;
            $product = $product_model->getOne(['Id'=>19]);

            $header[] = $product['Token'];
            linkcurl($url,'GET',false,$header);
        }

        header("refresh:3;url=https://php-api.juip.com/product/killOut/list");
        print('踢线成功，请稍等...<br>3秒后返回。');
    }
}
