13 changed files with 179 additions and 5 deletions
-
2Envoy.blade.php
-
22app/Constants/v3/ErrorCode.php
-
5app/Constants/v3/Shipping.php
-
5app/Constants/v3/SsdbKeys.php
-
3app/Controller/v3/OrderOnlineController.php
-
40app/Controller/v3/ParamsTokenController.php
-
1app/Request/v3/OrderOnlineRequest.php
-
12app/Service/v3/Implementations/OrderOnlineService.php
-
68app/Service/v3/Implementations/ParamsTokenSsdbService.php
-
2app/Service/v3/Interfaces/OrderOnlineServiceInterface.php
-
20app/Service/v3/Interfaces/ParamsTokenServiceInterface.php
-
2config/autoload/dependencies.php
-
2config/routes.php
@ -0,0 +1,40 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Controller\v3; |
||||
|
|
||||
|
use App\Service\v3\Interfaces\ParamsTokenServiceInterface; |
||||
|
use Hyperf\Di\Annotation\Inject; |
||||
|
|
||||
|
/** |
||||
|
* 参数token控制器 |
||||
|
* Class ParamsTokenController |
||||
|
* @package App\Controller |
||||
|
*/ |
||||
|
class ParamsTokenController extends BaseController |
||||
|
{ |
||||
|
/** |
||||
|
* @Inject |
||||
|
* @var ParamsTokenServiceInterface |
||||
|
*/ |
||||
|
protected $paramsTokenService; |
||||
|
|
||||
|
/** |
||||
|
* 生成token存储对应参数数据 |
||||
|
* @return \Psr\Http\Message\ResponseInterface |
||||
|
*/ |
||||
|
public function generate() |
||||
|
{ |
||||
|
$token = $this->paramsTokenService->generate($this->request->all()); |
||||
|
return $this->success(['token' => $token]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 解析token获取对应参数数据 |
||||
|
* @return \Psr\Http\Message\ResponseInterface |
||||
|
*/ |
||||
|
public function analyze() |
||||
|
{ |
||||
|
$params = $this->paramsTokenService->analyze($this->request->input('token')); |
||||
|
return $this->success($params); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,68 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Service\v3\Implementations; |
||||
|
|
||||
|
use App\Constants\v3\ErrorCode; |
||||
|
use App\Constants\v3\LogLabel; |
||||
|
use App\Constants\v3\SsdbKeys; |
||||
|
use App\Exception\ErrorCodeException; |
||||
|
use App\Service\v3\Interfaces\ParamsTokenServiceInterface; |
||||
|
use Hyperf\Utils\ApplicationContext; |
||||
|
use App\TaskWorker\SSDBTask; |
||||
|
use Hyperf\Di\Annotation\Inject; |
||||
|
use App\Commons\Log; |
||||
|
|
||||
|
class ParamsTokenSsdbService implements ParamsTokenServiceInterface |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @Inject |
||||
|
* @var Log |
||||
|
*/ |
||||
|
protected $log; |
||||
|
|
||||
|
/** |
||||
|
* 生成token并存储对应数据 |
||||
|
* @param $params |
||||
|
*/ |
||||
|
public function generate($params) |
||||
|
{ |
||||
|
$token = $params['token_name'] ?? md5(json_encode($params)); |
||||
|
|
||||
|
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); |
||||
|
|
||||
|
$kvs = []; |
||||
|
foreach ($params as $key => $value) { |
||||
|
$kvs[] = $key; |
||||
|
$kvs[] = $value; |
||||
|
} |
||||
|
|
||||
|
if(false === $ssdb->exec('multi_hset', SsdbKeys::PARAMS_TOKEN.$token, $kvs)) { |
||||
|
throw new ErrorCodeException(ErrorCode::TOKEN_GENERATE_ERROR, 'token生成失败'); |
||||
|
} |
||||
|
|
||||
|
return $token; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 解析token获取对应数据参数 |
||||
|
* @param $token |
||||
|
*/ |
||||
|
public function analyze($token) |
||||
|
{ |
||||
|
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); |
||||
|
$params = $ssdb->exec('hgetall', SsdbKeys::PARAMS_TOKEN.$token); |
||||
|
|
||||
|
if (false === $params) { |
||||
|
|
||||
|
throw new ErrorCodeException(ErrorCode::TOKEN_ANALYZE_ERROR, 'token解析失败'); |
||||
|
} |
||||
|
|
||||
|
if (empty($params)) { |
||||
|
throw new ErrorCodeException(ErrorCode::TOKEN_NOT_EXISTS, 'token不存在'); |
||||
|
} |
||||
|
|
||||
|
return $params; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Service\v3\Interfaces; |
||||
|
|
||||
|
interface ParamsTokenServiceInterface |
||||
|
{ |
||||
|
/** |
||||
|
* 生成并存储token |
||||
|
* @param $params |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function generate($params); |
||||
|
|
||||
|
/** |
||||
|
* 通过token解析返回参数 |
||||
|
* @param $token |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function analyze($token); |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue