/**
 * [api]
 * @author Foreach
 * @param  string  $method   [请求方式]
 * @param  string  $url      [地址]
 * @param  array   $params   [参数]
 * @return
 */
function api($method = 'POST', $url = '', $params = array())
{
    $client = new Client([
        'base_uri' => config('app.url')
    ]);

    $headers = ['Accept' => 'application/json', 'Authorization' => 'Bearer '. Session::get('token')];
    $data['headers'] = $headers;
    if ($method == 'GET') {
        $data['query'] = $params;
    } else {
        $data['form_params'] = $params;
    }
    $data['http_errors'] = false;

    // try {
        $response = $client->request($method, $url, $data);
    // } catch (TransferException $e) {
    //     abort(500);
    // }

    return json_decode($response->getBody(), true);
}

调用(pc端):

laravel API

 

相关文章:

  • 2021-10-23
  • 2021-11-01
  • 2021-05-21
  • 2021-09-17
  • 2022-12-23
  • 2021-11-28
  • 2021-08-17
  • 2022-02-20
猜你喜欢
  • 2022-01-09
  • 2021-07-30
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2022-03-05
  • 2021-11-22
相关资源
相似解决方案