本文整理汇总了PHP中app\App::findByClientId方法的典型用法代码示例。如果您正苦于以下问题:PHP App::findByClientId方法的具体用法?PHP App::findByClientId怎么用?PHP App::findByClientId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\App
的用法示例。
在下文中一共展示了App::findByClientId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUser
private function getUser($code, $state)
{
$app = App::findByClientId(314159265);
$params = array('code' => $code, 'client_id' => $app->client_id, 'client_secret' => $app->client_secret);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, env('URL') . '/code');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$json = curl_exec($ch);
$result = json_decode($json, true);
if (!array_key_exists('access_token', $result)) {
app()->abort($result['error'], $result['description']);
}
if (array_key_exists('active', $result) && !$result['active']) {
app()->abort($result['error'], $result['description']);
}
$tg = TelegramUser::findByTelegramId($result['telegram_user']['telegram_id']);
if ($tg->status != $state) {
app()->abort(403, 'Invalid state.');
}
$tg->status = 'access_granted';
$tg->save();
try {
$user = User::findByTelegramId($result['telegram_user']['telegram_id']);
} catch (ModelNotFoundException $e) {
$user = new User();
$user->email = $result['email'];
$user->telegram_id = $result['telegram_user']['telegram_id'];
}
$user->access_token = $result['access_token'];
$user->name = $result['telegram_user']['name'];
$user->username = $result['telegram_user']['username'];
$user->save();
return $user;
}
示例2: generateToken
public function generateToken(Request $request, $clientId)
{
$app = App::findByClientId($clientId);
$token = $this->createToken($app);
$query = str_replace($request->url(), '', $request->fullUrl());
if ($query && strlen($query)) {
$token->query_string = substr($query, 1);
$token->save();
}
return redirect('https://telegram.me/' . env('BOT_NAME') . '?start=' . $token->token);
}
示例3: commandReply
private function commandReply($message)
{
$telegramId = $message['from']['id'];
$tg = TelegramUser::findByTelegramId($telegramId);
$params = array('chat_id' => $telegramId);
if ($tg->status == 'revoke_access') {
$clientId = preg_replace('/[^0-9,.]/', '', $message['text']);
try {
$app = App::findByClientId($clientId);
$auth = Auth::findByAppAndTelegramUser($app, $tg);
$auth->active = false;
$auth->save();
$text = 'Access to this app has been revoked.';
$tg->status = 'access_revoked';
$params['reply_markup'] = json_encode(['hide_keyboard' => true]);
} catch (ModelNotFoundException $e) {
$text = 'Unknown app. Please choose an app from the given list:';
}
} else {
$text = 'Unknown command.';
$tg->status = 'unknown_command';
$params['reply_markup'] = json_encode(['hide_keyboard' => true]);
}
$params['text'] = $text;
$this->send($params);
$tg->save();
}