{
"require": {
"zhouyl/apiclient": "dev-master"
}
}
$api = new \ZhouYL\Api\Client([
'gateway' => 'http://127.0.0.1',
'headers' => array(
'Host: api.fanqie88.com',
),
'port' => 9433,
'timeout' => 10,
]);
参数说明:
gateway: URL请求网关
port: 端口,默认自动识别
headers: CURL请求附加头信息
timeout: 超时时间,默认不限制
$json = $api->request('Api/xxx', array('key' => 'xxx', 'uid' => 12345), 'POST');
$json = $api->request('Api/xxx');
// or
$json = $api->get('Api/xxx');
$data = array(
'key' => 'xxx',
'uid' => 12345,
);
$json = $api->request('Api/xxx', $data, 'POST');
// or
$json = $api->post('Api/xxx', $data);
Client 将尝试将响应数据转换进行 json_decode 转换,如果失败则返回 false
$api->request('Api/xxx');
$json = $api->response();
$raw = $api->rawResponse();