香洲二院小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
mini_xzey/app/Utils/Traits/MiniProgramAuth.php

36 lines
815 B

<?php
declare(strict_types = 1);
namespace App\Utils\Traits;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Support\Facades\Redis;
trait MiniProgramAuth
{
public string $open_id;
public string $union_id;
public string $session_key;
/**
* MiniProgramAuth initialize
* @throws AuthenticationException
*/
public function authInitialize(): void
{
$token = request()->header('authorization');
$info = Redis::get(substr($token, 7));
if(empty($info)) {
throw new AuthenticationException('Unauthenticated.');
}
$info = json_decode($info, true);
$this->open_id = $info['open_id'] ?? '';
$this->union_id = $info['union_id'] ?? '';
$this->session_key = $info['session_key'] ?? '';
}
}