本文整理汇总了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);
}
}