mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2024-11-01 22:20:30 +08:00
新增uni一键手机号登录
This commit is contained in:
parent
b4152eb183
commit
4166eaafe5
@ -46,6 +46,18 @@ export class AppUserLoginController extends BaseController {
|
||||
return this.ok(await this.userLoginService.phone(phone, smsCode));
|
||||
}
|
||||
|
||||
@CoolTag(TagTypes.IGNORE_TOKEN)
|
||||
@Post('/uniPhone', { summary: '一键手机号登录' })
|
||||
async uniPhone(
|
||||
@Body('access_token') access_token: string,
|
||||
@Body('openid') openid: string,
|
||||
@Body('appId') appId: string
|
||||
) {
|
||||
return this.ok(
|
||||
await this.userLoginService.uniPhone(access_token, openid, appId)
|
||||
);
|
||||
}
|
||||
|
||||
@CoolTag(TagTypes.IGNORE_TOKEN)
|
||||
@Get('/captcha', { summary: '图片验证码' })
|
||||
async captcha(
|
||||
|
@ -80,6 +80,31 @@ export class UserLoginService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号一键登录
|
||||
* @param access_token
|
||||
* @param openid
|
||||
*/
|
||||
async uniPhone(access_token, openid, appId) {
|
||||
const instance = await this.pluginService.getInstance('uniphone');
|
||||
const phone = await instance.getPhone(access_token, openid, appId);
|
||||
if (phone) {
|
||||
let user: any = await this.userInfoEntity.findOneBy({ phone });
|
||||
if (!user) {
|
||||
user = {
|
||||
phone,
|
||||
unionid: phone,
|
||||
loginType: 2,
|
||||
nickName: phone.replace(/^(\d{3})\d{4}(\d{4})$/, '$1****$2'),
|
||||
};
|
||||
await this.userInfoEntity.insert(user);
|
||||
}
|
||||
return this.token({ id: user.id });
|
||||
} else {
|
||||
throw new CoolCommException('获得手机号失败,请检查配置');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 公众号登录
|
||||
* @param code
|
||||
|
Loading…
Reference in New Issue
Block a user