feat: Add CreateWeChatUser API

This commit is contained in:
AnonymousDotNet 2024-12-12 17:11:26 +08:00
parent 1857cc66e4
commit af95a6e1b2

View file

@ -10,4 +10,31 @@ public partial class MongoRepository
return weChatUser != null ? weChatUser.ToWeChatUser() : null;
}
public WeChatUser? CreateWeChatUser(WeChatUser weChatUser)
{
if (weChatUser == null) return null;
var weChatUserInfo = new WeChatUserDocument
{
Id = weChatUser.Id ?? Guid.NewGuid().ToString(),
OpenId = weChatUser.OpenId,
SessionKey = weChatUser.SessionKey,
UnionId = weChatUser.UnionId,
Sex = weChatUser.Sex,
Province = weChatUser.Province,
City = weChatUser.City,
NickName = weChatUser.NickName,
Headimgurl = weChatUser.Headimgurl,
PhoneNumber = weChatUser.PhoneNumber,
Country = weChatUser.Country,
Privilege = weChatUser.Privilege,
CreatedAt = DateTime.UtcNow,
};
_dc.WeChatUsers.InsertOne(weChatUserInfo);
return weChatUserInfo.ToWeChatUser();
}
}