cmbYouku_Api/app/middleware/ValidateOpenId.php

34 lines
1.1 KiB
PHP

<?php
namespace app\middleware;
use app\exception\LogicException;
use app\model\User;
use app\service\CmbService;
use app\service\util\CmbLifeUtils;
use think\Response;
use think\Request;
class ValidateOpenId
{
public function handle(Request $request, \Closure $next): Response
{
$openId = $request->param('open_id', '');
if (empty($openId)) {
return $next($request);
}
// $openIdRes = CmbLifeUtils::decrypt($openId, config('cmb.merchant_sm2_pri_key'));
// $openId = $openIdRes['open_id'] ?? '';
$request->open_id = $openId;
$user = User::getUserByOpenId($openId);
if ($user->isEmpty()) {
throw new LogicException('用户不存在' . $openId);
}
$request->user_id = $user->id;
// $res = CmbService::checkAccessToken($user);
// if ($res['respCode'] == 1000) {
// $request->user_id = $user->id;
// } else {
// return json(['code' => 403, 'message' => '登录超时,请重新登录!', 'data' => []], 401);
// }
return $next($request);
}
}