本文整理匯總了PHP中app\Auth::findByAccessToken方法的典型用法代碼示例。如果您正苦於以下問題:PHP Auth::findByAccessToken方法的具體用法?PHP Auth::findByAccessToken怎麽用?PHP Auth::findByAccessToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\Auth
的用法示例。
在下文中一共展示了Auth::findByAccessToken方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: send
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: show
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);
}
}