コード例 #1
0
 public function send(Request $request)
 {
     $accessToken = $request->input('access_token');
     try {
         $auth = \App\Auth::findByAccessToken($accessToken);
         $auth->telegram_user = $auth->telegramUser()->first();
         $app = $auth->app()->first();
         $text = 'Send on behalf of: [' . $app->client_id . '] ' . $app->name . PHP_EOL . PHP_EOL;
         $text .= 'Message: ' . PHP_EOL;
         $text .= $request->input('text') . PHP_EOL . PHP_EOL;
         $text .= 'Note: If you don\'t want to receive further updates from [' . $app->client_id . '] ' . $app->name;
         $text .= ', you can revoke access via the /revoke command';
         $params = array('chat_id' => $auth->telegram_user->telegram_id, 'text' => $text);
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, 'https://api.telegram.org/bot' . env('BOT_TOKEN') . '/sendMessage');
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
         $json = curl_exec($ch);
         $result = json_decode($json, true);
         if ($result['ok']) {
             return response()->json(array('ok' => true));
         } else {
             return response()->json($result);
         }
     } catch (ModelNotFoundException $e) {
         return response()->json(['error' => 'No active user found.'], 404);
     }
 }
コード例 #2
0
 public function show(Request $request)
 {
     $accessToken = $request->input('access_token');
     try {
         $auth = \App\Auth::findByAccessToken($accessToken);
         $auth->telegram_user = $auth->telegramUser()->first();
         return response()->json($auth);
     } catch (ModelNotFoundException $e) {
         return response()->json(['error' => 'No active user found.'], 404);
     }
 }