feat : wx login
This commit is contained in:
30
app/Service/Api/User/BindPhoneByWxService.php
Normal file
30
app/Service/Api/User/BindPhoneByWxService.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\User;
|
||||
|
||||
use App\Exception\ErrException;
|
||||
use App\Service\Api\BaseService;
|
||||
use App\Service\ServiceTrait\Api\GetUserInfoTrait;
|
||||
use App\Service\ServiceTrait\Api\WxMiniTrait;
|
||||
|
||||
class BindPhoneByWxService extends BaseService
|
||||
{
|
||||
use GetUserInfoTrait,WxMiniTrait;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->checkBindPhone($this->userId);
|
||||
|
||||
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
}
|
||||
60
app/Service/ServiceTrait/Api/GetUserInfoTrait.php
Normal file
60
app/Service/ServiceTrait/Api/GetUserInfoTrait.php
Normal 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('该账户已绑定手机号,无需重新绑定。若需更换手机号,请联系客服重置后再绑定');
|
||||
}
|
||||
}
|
||||
@@ -76,4 +76,9 @@ trait WxMiniTrait
|
||||
throw new ErrException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function jsCodeGetPhoneNumber(string $code): mixed
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user