feat : wx login

This commit is contained in:
2024-11-25 18:02:40 +08:00
parent 865ff6eb7e
commit 9c175fdb78
8 changed files with 175 additions and 9 deletions

View File

@@ -0,0 +1,60 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
*/
declare(strict_types=1);
namespace App\Service\ServiceTrait\Api;
use App\Exception\ErrException;
use App\Model\User;
use Hyperf\Context\Context;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Model;
use Hyperf\Di\Annotation\Inject;
trait GetUserInfoTrait
{
/**
* @var User 注入用户模型
*/
#[Inject]
protected User $userModel;
/**
* 单例获取用户信息
* @param $userId
* @return false|Builder|Model|mixed|string
*/
protected function getUserInfo($userId): mixed
{
$key = 'user_id:' . $userId;
if (Context::has($key)) {
return Context::get($key, false);
}
$userInfo = $this->userModel->getInfoById($userId);
if (!$userInfo) {
return false;
}
Context::set($key, $userInfo);
return $userInfo;
}
/**
* @param $userId
* @return void
*/
protected function checkBindPhone($userId): void
{
$userInfo = $this->getUserInfo($userId);
if (!empty($userInfo->phone)) throw new ErrException('该账户已绑定手机号,无需重新绑定。若需更换手机号,请联系客服重置后再绑定');
}
}

View File

@@ -76,4 +76,9 @@ trait WxMiniTrait
throw new ErrException($e->getMessage());
}
}
public function jsCodeGetPhoneNumber(string $code): mixed
{
}
}