|
@@ -21,11 +21,78 @@ use support\Response;
|
|
|
class Auth extends Base
|
|
class Auth extends Base
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
- protected array $noNeedLogin = ["log2mobile","log2nickname"];
|
|
|
|
|
|
|
+ protected array $noNeedLogin = ["log2mobile","log2nickname","loginMobileAuth",'loginNicknameAuth'];
|
|
|
|
|
|
|
|
#[Inject]
|
|
#[Inject]
|
|
|
protected SaasUserOpen $model;
|
|
protected SaasUserOpen $model;
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 授权获取手机号-非登录
|
|
|
|
|
+ * @param Request $request
|
|
|
|
|
+ * @return Response
|
|
|
|
|
+ */
|
|
|
|
|
+ #[PostMapping("mobile/auth")]
|
|
|
|
|
+ public function loginMobileAuth(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $param = $this->_valid([
|
|
|
|
|
+ "login.require" => trans("empty.require"),
|
|
|
|
|
+ "code.require" => trans("empty.require"),
|
|
|
|
|
+ ],$request->method());
|
|
|
|
|
+ if (!is_array($param)) return error($param);
|
|
|
|
|
+ $sessionKey = (new Crypt)->config($this->getDyConfig())->getSessionKey($param['login']);
|
|
|
|
|
+ if (empty($sessionKey)) return error("授权登录失败");
|
|
|
|
|
+ $mobileStr = (new Crypt)->config($this->getDyConfig())->token()->getMobile($param['code']);
|
|
|
|
|
+ if (empty($mobileStr)) return error("授权信息获取失败");
|
|
|
|
|
+ return $this->encode("success",['mobile' => $mobileStr,'openid' => $sessionKey['openid']]);
|
|
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
|
|
+ return error($throwable->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 授权昵称等信息-实际登录
|
|
|
|
|
+ * @param Request $request
|
|
|
|
|
+ * @return Response
|
|
|
|
|
+ */
|
|
|
|
|
+ #[PostMapping("nickname/auth")]
|
|
|
|
|
+ public function loginNicknameAuth(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $param = $this->_valid([
|
|
|
|
|
+ "avatar.require" => trans("empty.require"),
|
|
|
|
|
+ "nickname.require" => trans("empty.require"),
|
|
|
|
|
+ "mobile.require" => trans("empty.require"),
|
|
|
|
|
+ ],$request->method());
|
|
|
|
|
+ if (!is_array($param)) return error($param);
|
|
|
|
|
+ $mobileData = json_decode($param['mobile'],true);
|
|
|
|
|
+ $mobile = [];
|
|
|
|
|
+ if (!empty($param['mobile'])) {
|
|
|
|
|
+ if (!isset($mobileData['openid'])) return error("授权失败");
|
|
|
|
|
+ $mobile = $this->decrypt2code(sConf('wechat.min_private_key'), $mobileData['mobile']);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (empty($mobile)) return error("授权登录失败");
|
|
|
|
|
+ $userInfo = [
|
|
|
|
|
+ "openid" => $mobileData['openid'],
|
|
|
|
|
+ "nickname" => $param['nickname'],
|
|
|
|
|
+ "avatar" => $param['avatar']
|
|
|
|
|
+ ];
|
|
|
|
|
+ $map = ["openid" => $mobileData['openid']];
|
|
|
|
|
+ if (!empty($mobile['purePhoneNumber'])) {
|
|
|
|
|
+ $userInfo['mobile'] = $mobile['purePhoneNumber'];
|
|
|
|
|
+ }
|
|
|
|
|
+ $user = $this->model->where($map)->findOrEmpty();
|
|
|
|
|
+ if ($user->isEmpty()) {
|
|
|
|
|
+ $userInfo["create_ip"] = $request->getRealIp();
|
|
|
|
|
+ $user->insertGetId($userInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+ $userAuth = get_object_vars(AuthFacade::guard("user")->login(['openid' => $mobileData['openid']]));
|
|
|
|
|
+ return success("ok",$userAuth);
|
|
|
|
|
+
|
|
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
|
|
+ return error($throwable->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
#[PostMapping("nickname")]
|
|
#[PostMapping("nickname")]
|
|
|
public function log2nickname(Request $request): Response
|
|
public function log2nickname(Request $request): Response
|