首次提交 Laravel 專案
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace App\Services;
|
||||
class TgApi{
|
||||
|
||||
public static function GetChatInfo($msg){
|
||||
$ApiUrl= "https://api.telegram.org/bot{$msg['token']}/getChat?chat_id={$msg['message_chat_id']}";
|
||||
|
||||
$ch = curl_init(); // 初始化 cURL
|
||||
curl_setopt($ch, CURLOPT_URL, $ApiUrl); // 設定請求網址
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 回傳而不是直接輸出
|
||||
|
||||
$response = curl_exec($ch); // 執行請求
|
||||
$err = curl_error($ch); // 捕捉錯誤
|
||||
curl_close($ch); // 關閉 cURL
|
||||
|
||||
if ($err) {
|
||||
return ['ok' => false, 'error' => $err];
|
||||
}
|
||||
|
||||
$result = json_decode($response, true);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user