domain(); //thinkphp5获取系统的域名,如 baidu.com 去除 https或 http }else{ $domain = request()->domain() . '/app/index.php'; } $domain = preg_replace('/^(http|https):\/\//i', '', $domain); $options = [ 'base_uri' => 'https://www.tuzhi.ltd/', 'timeout' => 1000, 'connect_timeout' => 300, 'verify' => false, 'http_errors' => false, 'headers' => [ 'X-REQUESTED-WITH' => 'XMLHttpRequest', 'Referer' => $domain, ] ]; static $client; if (empty($client)) { $client = new GuzzleHttpClient($options); } return $client; } public static function request($url,$params = []){ $license_token = input('license_token'); $data = false; try { $params['token'] = $license_token; $client = self::getClient(); $response = $client->request("POST",$url,[ 'form_params'=>$params ]); $body = $response->getBody(); $data = $body->getContents(); } catch (\Exception $e) { throw new \Exception('请求授权服务器异常,请刷新重试'); } if(!$data){ throw new \Exception('请求失败,请刷新重试'); } $data = json_decode($data,true); if(!$data){ throw new \Exception('请求授权服务器数据错误,请刷新重试'); } if($data['code'] !=1){ throw new \Exception($data['msg']); } return $data['data']; } }