Commit 071b043f authored by hj's avatar hj

更新提交

parent 9ff6584a
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Services\Api;
use App\Repositories\Contracts\PlatformCustomerRepository;
use App\Services\CustomerService;
use App\Support\Traits\Helpers;
class AuthService
{
use Helpers;
public function __construct(PlatformCustomerRepository $platformCustomerRepository)
{
$this->platformCustomerRepository = $platformCustomerRepository;
}
/**
* 获取token
* @param $requestParams
* @return array
* @throws \Exception
*/
public function getToken($requestParams)
{
return app(CustomerService::class)->getToken($requestParams);
}
}
......@@ -228,4 +228,37 @@ class CustomerService
}
}
/**
* 获取token
* @param $requestParams
* @return array
* @throws \Exception
*/
public function getToken($requestParams)
{
$platformCustomer = $this->platformCustomerRepository->findWhere([
'token' => $requestParams['customer_token']
]);
if(!$platformCustomer->toArray()){
throw new \Exception('token无效',500);
}
$platformCustomer = current($platformCustomer->toArray());
if($platformCustomer['cus_type'] == 'chemsite'){
$token['company_token'] = $requestParams['customer_token'];
$token['cus_number'] = $requestParams['cus_number'] ?? '';
}else{
$token['customer_token'] = $requestParams['customer_token'];
}
$newToken = base64_encode(implode(',', $token));
$expTimestamp = strtotime(date('Y-m-d H:i:s', strtotime('+1 day')));
$jwtToken = $this->generateToken($newToken);
return [
'token' => $jwtToken,
'ttl' => $expTimestamp
];
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment