2017-09-09 43 views
0

我想獲得symfony中getChat方法的回覆電報,但是如何使用它? https://api.telegram.org/bottoken/[email protected] 這是郵遞員的迴應:因爲我用這種但是對於得到我不知道該怎麼辦發送消息使用電報中的獲取方法

{ 
"ok": true, 
"result": { 
    "id": -1001000737610, 
    "title": "کانال ", 
    "username": "gizmiztel", 
    "type": "channel", 
    "description": "ارسال سوژه @alogizmiz\n\nتبلیغات @gizmiz_ad\n\nاینستاگرام instagram.com/_u/gizmiztel\n\nسایت gizmiz.com", 
    "photo": { 
     "small_file_id": "AQADBAATOIVnGQAElEEaamARX9hoWgIAAQI", 
     "big_file_id": "AQADBAATOIVnGQAE21YqJKH-YwZqWgIAAQI" 
    } 
} 
} 

$result = [ 
      'method' => 'sendMessage', 
      'chat_id' => $chatId, 
      'text' => 'خطای سرور' 
     ]; 
return new JsonResponse($result, Response::HTTP_OK); 
+0

你嘗試過改變「方法」字段設置爲「getChat」和在$ result中去掉「文本」字段? –

+0

是的,但我在郵遞員得到的迴應,我想在我的代碼處理 –

+0

對不起,我不明白你是什麼意思的郵遞員也許我沒有聽說過。 還是你的意思是在json?你需要將json響應轉換爲變量,以便在代碼中使用它嗎? –

回答

1

您可以使用GuzzlePHP Curl爲從任何HTTP客戶端獲取結果。

對於使用狂飲HTTP客戶端:

Reqire 「guzzlehttp /狂飲」:在你的package.json和運行作曲家update命令 「版本」。

然後你可以使用它像這樣:

<?php 

    namespace Foo\BarBundle\Driver; 

    use GuzzleHttp\Client; 

    class GetResultFromTelegram 
    { 
     protected client; 

     public function getInfoOfChannel() 
     { 
      $baseUrl = 'https://api.telegram.org/bottoken/[email protected]'; 
      $this->client = new Client(); 

      $res = $this->client->request('GET', $baseUrl); 
      // Convert response to array. 
      return json_decode($res->getBody(), true); 
     } 
    } 
+0

謝謝我解決了捲曲 –

+0

@ amini.swallow沒問題。祝你好運。 –

相關問題