我有代码
public function getClient(){
$token = getenv('TELEGRAM_TOKEN');
$uri = 'https://api.telegram.org/bot'.$token.'/';
$client = new Client(['base_url' => $uri]);
return $client;
}
public function getMyBot(){
$client = $this->getClient();
$response = $client->get( '/getMe' );
dd($response);
}
但是,我没有像docs中所说的那样返回用户对象,而是显示了一个“回复”#39;而不是对象。
Response {#188 ▼
-reasonPhrase: "OK"
-statusCode: 200
-effectiveUrl: "https://core.telegram.org/bots"
-headers: array:9 [▼
"server" => array:1 [▶]
"date" => array:1 [▶]
"content-type" => array:1 [▶]
"content-length" => array:1 [▶]
"connection" => array:1 [▶]
"pragma" => array:1 [▶]
"cache-control" => array:1 [▶]
"x-frame-options" => array:1 [▶]
"strict-transport-security" => array:1 [▶]
]
-headerNames: array:9 [▼
"server" => "Server"
"date" => "Date"
"content-type" => "Content-Type"
"content-length" => "Content-Length"
"connection" => "Connection"
"pragma" => "Pragma"
"cache-control" => "Cache-control"
"x-frame-options" => "X-Frame-Options"
"strict-transport-security" => "Strict-Transport-Security"
]
-body: Stream {#189 ▼
-stream: :stream {@280 ▶}
-size: null
-seekable: true
-readable: true
-writable: true
-uri: "php://temp"
-customMetadata: []
}
-protocolVersion: "1.1"
}
无论如何要获取用户对象?我使用的是带有Guzzle 5.3的php 5.4和laravel 5.0。
编辑:我尝试使用getBody()方法以及getBody-> getContents()方法,但它不起作用,getBody只显示响应的流部分,getContents将给出一个奇怪的HTML文件。
JSON_DECODE也不起作用,它返回错误代码4,即JSON_ERROR_SYNTAX。响应应该是JSON表单吗?
答案 0 :(得分:2)
你需要显示身体的颜色。
dd($response->getBody()->getContents())
顺便说一句,您可以使用unofficial laravel reqady SDK,这也适用于Guzzle。