From 3fbaffe9a2a16c4c3a7e705f3e1858ef6e366173 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com>
Date: Sat, 9 Nov 2024 01:20:53 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E8=B4=A6=E5=8F=B7?=
=?UTF-8?q?=E7=BB=91=E5=AE=9A=E9=80=BB=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../WeChatMiniProgramAccountService.cs | 32 +++++++++++++------
1 file changed, 23 insertions(+), 9 deletions(-)
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 5e178198..38a689f8 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
@@ -69,11 +69,9 @@ public class WeChatMiniProgramAccountService : ApplicationService
///
///
[HttpPost("wechat/mini-program/account/bind")]
- [Authorize]
+ // [Authorize]
public async Task PostBindAsync(BindInput input)
{
- var userId = CurrentUser.GetId();
-
//验证手机号
await _accountService.ValidationPhoneCaptchaAsync(ValidationPhoneTypeEnum.Bind, input.Phone, input.Code);
//校验手机号与验证码
@@ -88,20 +86,36 @@ public class WeChatMiniProgramAccountService : ApplicationService
//验证手机号的验证码
var openId = (await _weChatMiniProgramManager.Code2SessionAsync(new Code2SessionInput(input.JsCode))).openid;
-
+
+ //是否已经授权过绑定过auth
+ bool isAuthed =true;
+ //如果openId没有绑定过,代表第一次进入,否则就是临时账号进行绑定
+ var authInfo= await _authService.TryGetByOpenIdAsync(openId,AuthTypeConst.WeChatMiniProgram);
+ //从来没绑定过
+ if (authInfo is null)
+ {
+ isAuthed = false;
+ }
+ //账号绑定,不管什么情况,都将jscode与phone用户建立关系即可
await PostBindToAuthAsync(userInfo.User.Id, openId, userInfo.User.UserName);
//发送账号绑定的事件,不同领域对账号数据进行迁移
//bbs:钱钱 (累加),禁用临时账号(修改)
//dc: 价值、积分 (累加)
- await _localEventBus.PublishAsync(new BindAccountEto
+
+ //只有之前授权绑定过,才需要将临时账号进行账号数据转移,
+ if (isAuthed)
{
- NewUserId = userInfo.User.Id,
- OldUserId = userId
- },false);
+ await _localEventBus.PublishAsync(new BindAccountEto
+ {
+ NewUserId = userInfo.User.Id,
+ OldUserId =authInfo.UserId
+ },false);
+ }
+
}
-
+
private async Task PostBindToAuthAsync(Guid userId, string openId, string? name = null)
{
await _authService.CreateAsync(new AuthCreateOrUpdateInputDto