/** * Execute the console command. * * @return mixed */ public function fire() { try { $api = new Api(); $customers = Customer::all(); foreach ($customers as $customer) { $customerId = $customer->agbis_id; $card = PaymentCloud::getCustomerAutopayCard($customerId); if ($card) { $phone = '+7' . $customer->phone; $password = $customer->credential->agbis_password; $user = $api->Login_con($phone, $password); $key = $user->key; $orders = $api->Orders($key)['orders']; foreach ($orders as $order) { if ($this->isNotPaidOrder($customerId, $order['id'])) { if ($api->IsGoodOrder($order['id'], $customerId)) { $api->payByToken($order['id'], $card->token, $order['amount'], $order['doc_number'], $key); } } } } } } catch (ApiException $e) { } }
public function fire() { $api = new Api(); $list = Customer::whereEmail('')->get()->all(); $this->line('Найдено клиентов без email: ' . count($list)); foreach ($list as $customer) { $phone = '+7' . $customer->phone; $password = $customer->credential->agbis_password; try { $auth = $api->Login_con($phone, $password); $key = $auth->key; $this->update($key, $api, $customer); } catch (ApiException $e) { $this->error('Ошибка авторизации в Агбис: ' . $e->getMessage()); } } }
/** * @param Customer $customer * @param $password * @param $key * * @return array */ public function initSessionKey(Customer $customer, $password, $key) { $api = new Api(); $user = $api->Login_con('+7' . $customer->get()->phone, $password); $sessionId = $user->key; Cache::put($key, $sessionId, 500); $this->log('get new session', ['customer' => $customer->get()->id, 'session' => $sessionId]); return $sessionId; }
/** * авторизация * @return \Response */ public function login() { Validation::prepareInput(['phone']); $phone = \Input::get('phone'); $password = \Input::get('password'); $selfPassword = null; $validator = Validation::validator(['phone', 'password']); if ($validator->fails()) { Reporter::loginFailValidate($validator); return $this->responseError($validator, 'Некорректные данные'); } Reporter::loginStart($phone, $password); // ключ который мы должны в итоге выдать фронтенду $key = null; // находим у себя $customer = Customer::instance()->initByPhone($phone); if ($customer) { Reporter::loginFoundSelf($customer->get()->agbis_id); // авторизуем по своему паролю if ($customer->checkPassword($password)) { Reporter::loginPasswordSelf($customer->get()->agbis_id); // наш пароль $selfPassword = $password; // в агбис будем входить по внешнему паролю $password = $customer->getExternalPassword(); } } // получаем сессию агбиса try { $api = new Api(); $user = $api->Login_con($phone, $password); $api->memory($user); // запомним отдельно в сессии api if (Input::get('remember')) { $cookie = Customer::instance()->getForeverCookie(); } else { $cookie = Customer::instance()->getTemporaryCookie(); } Reporter::loginExternal($user->id, $phone); // для нас - новый человек if (!$customer) { // пробуем найти по id агбиса $customer = Customer::instance()->initByExternalId($user->id); if ($customer) { // если нашли, это значит изменился телефон, обновим всю информацию $customer->updateCustomerByExternal($phone, $password); } else { // создадим нового $customer = Customer::instance()->createCustomerByExternal($user->id, $phone, $password); } } // устанавливаем пароль в соответствии с успешным входом $customer->doChangePasswordSoft($password, $selfPassword); // по итогу, у нас есть "наш" человек // и мы начинам свою сессию $key = $customer->startSession(); Reporter::loginNewKey($customer->get()->id, $key); $invite = new InviteComponent(); $invite->registerInvite($customer->get()); // обновляем дату-время последнего входа $customer->renewRegisterAt(); // и именно наш ключ отдаем клиенту $response = $this->responseSuccess(['key' => $key], 'Успешная авторизация')->withCookie($cookie); return $response; } catch (\Exception $e) { Reporter::loginFailException($e); return $this->responseException($e, 'Ошибка авторизации', null, 401); } }