diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Account/LoginOutput.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Account/LoginOutput.cs
index 0fa342e2..b99624a6 100644
--- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Account/LoginOutput.cs
+++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Account/LoginOutput.cs
@@ -8,6 +8,4 @@ public class LoginOutput
/// 后端访问token
///
public string? Token { get; set; }
-
- public LoginResultEnum Result{ get; set; }
}
\ No newline at end of file
diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Account/RegisterInput.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Account/RegisterInput.cs
index 2f8609d8..88be3592 100644
--- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Account/RegisterInput.cs
+++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application.Contracts/Dtos/Account/RegisterInput.cs
@@ -2,42 +2,6 @@
public class RegisterInput
{
-
- //电话号码,根据code的表示来获取
-
- ///
- /// 账号
- ///
- public string UserName { get; set; }
-
- ///
- /// 密码
- ///
- public string Password { get; set; }
-
- ///
- /// 唯一标识码
- ///
- public string? Uuid { get; set; }
-
- ///
- /// 验证码
- ///
- public string? Code { get; set; }
-
- ///
- /// 电话
- ///
- public long Phone { get; set; }
-
-
-
- ///
- /// 昵称
- ///
- public string? Nick{ get; set; }
-
-
///
/// 微信小程序code
///
diff --git a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/Account/WeChatMiniProgramAccountService.cs b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/Account/WeChatMiniProgramAccountService.cs
index 42658ede..7523553a 100644
--- a/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/Account/WeChatMiniProgramAccountService.cs
+++ b/Yi.Abp.Net8/module/digital-collectibles/Yi.Framework.DigitalCollectibles.Application/Services/Account/WeChatMiniProgramAccountService.cs
@@ -40,17 +40,17 @@ public class WeChatMiniProgramAccountService : ApplicationService
//判断wxid中是否有对应的userid关系
//果然有,直接根据userid返回该用户token
//如果没有,返回结果即可
- var openId = (await _weChatMiniProgramManager.Code2SessionAsync(new Code2SessionInput(intput.JsCode))).openid;
+ var openId = (await _weChatMiniProgramManager.Code2SessionAsync(new Code2SessionInput(intput.JsCode)))
+ .openid;
var authInfo = await _authService.TryGetByOpenIdAsync(openId, AuthTypeConst.WeChatMiniProgram);
if (authInfo is null)
{
- output.Result = LoginResultEnum.Error;
+ throw new UserFriendlyException("该小程序没有绑定任何账号", "1000", "Auth未找到对应关系");
}
//根据用户id获取到用户信息
var result = await _accountService.PostLoginAsync(authInfo.UserId);
- output.Result = LoginResultEnum.Success;
output.Token = result.Token;
return output;
@@ -65,7 +65,8 @@ public class WeChatMiniProgramAccountService : ApplicationService
[HttpPost("wechat/mini-program/account/bind")]
public async Task PostBindAsync(BindInput input)
{
- _accountService.ValidationImageCaptcha(input.Uuid,input.Code);
+ //验证手机号
+ await _accountService.ValidationPhoneCaptchaAsync(ValidationPhoneTypeEnum.Bind, input.Phone, input.Code);
//校验手机号与验证码
//根据手机号查询用户信息
//根据code去获取wxid
@@ -77,17 +78,12 @@ public class WeChatMiniProgramAccountService : ApplicationService
}
//验证手机号的验证码
- await _accountService.PostCaptchaPhoneAsync(ValidationPhoneTypeEnum.Register, new PhoneCaptchaImageDto
- {
- Phone = input.Phone.ToString()
- });
-
var openId = (await _weChatMiniProgramManager.Code2SessionAsync(new Code2SessionInput(input.JsCode))).openid;
-
+
await PostBindToAuthAsync(userInfo.User.Id, openId, userInfo.User.UserName);
}
-
+
private async Task PostBindToAuthAsync(Guid userId, string openId, string? name = null)
{
await _authService.CreateAsync(new AuthCreateOrUpdateInputDto
@@ -106,19 +102,34 @@ public class WeChatMiniProgramAccountService : ApplicationService
[HttpPost("wechat/mini-program/account/register")]
public async Task PostRegisterAsync(RegisterInput input)
{
+ //先校验code,openId
+ var openId = (await _weChatMiniProgramManager.Code2SessionAsync(new Code2SessionInput(input.JsCode))).openid;
+
//走普通注册流程
//同时再加一个小程序绑定即可
- await _accountService.PostRegisterAsync(new RegisterDto
+ var userName = GenerateRandomString(6);
+ await _accountService.PostTempRegisterAsync(new RegisterDto
{
- UserName = input.UserName,
- Password = input.Password,
- Uuid = input.Uuid,
- Phone = input.Phone,
- Code = input.Code,
- Nick = input.Nick
+ UserName =$"ls-{userName}",
+ Password = GenerateRandomString(20),
+ Nick = $"临时账号-{userName}"
});
- var userInfo = await _accountService.GetAsync(input.UserName, null);
- var openId = (await _weChatMiniProgramManager.Code2SessionAsync(new Code2SessionInput(input.JsCode))).openid;
+ var userInfo = await _accountService.GetAsync(userName, null);
+
await PostBindToAuthAsync(userInfo.User.Id, openId, userInfo.User.UserName);
}
+
+ private string GenerateRandomString(int length)
+ {
+ const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ Random random = new Random();
+ char[] stringChars = new char[length];
+
+ for (int i = 0; i < length; i++)
+ {
+ stringChars[i] = chars[random.Next(chars.Length)];
+ }
+
+ return new string(stringChars);
+ }
}
\ No newline at end of file
diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/IServices/IAccountService.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/IServices/IAccountService.cs
index 6ce1b936..e06151a8 100644
--- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/IServices/IAccountService.cs
+++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/IServices/IAccountService.cs
@@ -28,15 +28,16 @@ namespace Yi.Framework.Rbac.Application.Contracts.IServices
Task GetAsync(string? userName,long? phone);
///
- /// 手机验证码
+ /// 校验电话验证码,需要与电话号码绑定
///
- ///
- Task