<?php

use App\Base\Base;
use Api\PhpUtils\Http\Request;

class RequestController extends Base
{
    public function GetAction()
    {
        $url = 'http://10.103.17.132:8007/adserver/goodsAds';
        $options = [
            'query' => [
                'docIdList' => '0SQ0d3dH',
                'appId' => 'pro',
                'platform' => 0
            ],
            'timeout' => 0.5 //自定义超时秒数，覆盖默认值
        ];
        $request = new Request();
        $ret = $request->get($url, $options);
        var_dump($ret);
        exit;
    }

    public function PostAction(){
        $url = 'http://sso.dengwei4378.com/api/master/getInfoByMasterName';
        $options = [
            'form_params' => [
                "masterName" => 'dengwei4378',
                "system" => 'rbac'
            ],
            'timeout' => 1 //自定义超时秒数，覆盖默认值
        ];
        $request = new Request();
        $post_ret = $request->post($url, $options);
        var_dump($post_ret);
        exit;
    }

    /**
     * 并发GET
     */
    public function ConGetAction(){
        $params = [
            0 => [
                'url' => 'http://sso.dengwei4378.com',
                'timeout' => 3 //自定义超时秒数，覆盖默认值
            ],
            1 => [
                'url' => 'https://api.github.com/',
                'timeout' => 3 //自定义超时秒数，覆盖默认值
            ],
        ];
        $request = new Request();
        $ret = $request->concurrencyGet($params);
        var_dump($ret);
        exit;
    }

    public function ConPostAction(){
        $params = [
            0 => [
                'url' => 'http://lock-screen-push.int.yidian-inc.com/lock-screen/list',
                'headers' => [
                    'Content-type' => 'application/json',
                    'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36'
                ],
                'json' => [  //json格式
                    "bizid" => "YDZX",
                    "uid" => "765073697",
                    "platform" => "1",
                    "appid" => "hipu"
                ],
                'timeout' => 0.1 //自定义超时秒数，覆盖默认值
            ],
            1 => [
                'url' => 'http://sso.dengwei4378.com/api/master/getInfoByMasterName',
                'form_params' => [  //表单格式
                    "masterName" => 'dengwei4378',
                    "system" => 'rbac'
                ],
                'timeout' => 0.2 //自定义超时秒数，覆盖默认值
            ],
        ];
        $request = new Request();
        $ret = $request->concurrencyPost($params);
        var_dump($ret);
        exit;
    }
}
