Commit 05763a49 authored by 黄奎's avatar 黄奎

新增UnionId解析

parent 4f11ca23
...@@ -58,6 +58,14 @@ namespace Mall.Common ...@@ -58,6 +58,14 @@ namespace Mall.Common
set; set;
} }
/// <summary>
/// UnionId
/// </summary>
public string Unoinid
{
get;set;
}
/// <summary> /// <summary>
/// ///
/// ///
......
...@@ -165,5 +165,10 @@ namespace Mall.Common ...@@ -165,5 +165,10 @@ namespace Mall.Common
/// 用户OpenId /// 用户OpenId
/// </summary> /// </summary>
public string UserOpenId { get; set; } public string UserOpenId { get; set; }
/// <summary>
/// 用户UnionId
/// </summary>
public string UserUnoinid { get; set; }
} }
} }
...@@ -40,10 +40,10 @@ namespace Mall.Common.Plugin ...@@ -40,10 +40,10 @@ namespace Mall.Common.Plugin
/// <param name="AppSecret"></param> /// <param name="AppSecret"></param>
/// <param name="Code"></param> /// <param name="Code"></param>
/// <returns></returns> /// <returns></returns>
public static string GetWeChatOpenId(string AppId, string AppSecret, string Code) public static MiniAppUserCache GetWeChatOpenId(string AppId, string AppSecret, string Code)
{ {
MiniAppUserCache miniAppUserCache = new MiniAppUserCache();
string result = ""; string result = "";
string openid = "";
try try
{ {
//请求路径 //请求路径
...@@ -52,7 +52,8 @@ namespace Mall.Common.Plugin ...@@ -52,7 +52,8 @@ namespace Mall.Common.Plugin
if (result != null && !string.IsNullOrEmpty(result)) if (result != null && !string.IsNullOrEmpty(result))
{ {
JObject jObj = JObject.Parse(result); JObject jObj = JObject.Parse(result);
openid = jObj["openid"].ToString(); miniAppUserCache.UserOpenId = jObj["openid"].ToString();
miniAppUserCache.UserUnoinid = jObj["unionid"].ToString();
} }
} }
catch (Exception ex) catch (Exception ex)
...@@ -64,9 +65,11 @@ namespace Mall.Common.Plugin ...@@ -64,9 +65,11 @@ namespace Mall.Common.Plugin
Common.Plugin.LogHelper.Write(ex, string.Format("GetWeChatOpenId:result={0}&&Code={1}", result, Code)); Common.Plugin.LogHelper.Write(ex, string.Format("GetWeChatOpenId:result={0}&&Code={1}", result, Code));
} }
} }
return openid; return miniAppUserCache;
} }
/// <summary> /// <summary>
/// 验证OpenId是否有效 /// 验证OpenId是否有效
/// </summary> /// </summary>
......
...@@ -264,5 +264,10 @@ namespace Mall.Model.Entity.User ...@@ -264,5 +264,10 @@ namespace Mall.Model.Entity.User
/// 查看次数 /// 查看次数
/// </summary> /// </summary>
public int LookTimes { get; set; } public int LookTimes { get; set; }
/// <summary>
/// UnionId唯一Id
/// </summary>
public string Unoinid { get; set; }
} }
} }
...@@ -312,6 +312,30 @@ namespace Mall.Module.User ...@@ -312,6 +312,30 @@ namespace Mall.Module.User
return result; return result;
} }
/// <summary>
/// 更新用户UnionId
/// </summary>
/// <param name="UnionId"></param>
/// <param name="Id"></param>
/// <returns></returns>
public bool UpdateMemberUserUnionId(string UnionId, int Id)
{
Dictionary<string, object> fileds = new Dictionary<string, object>()
{
{nameof(RB_Member_User_Extend.Unoinid),UnionId }
};
List<WhereHelper> wheres = new List<WhereHelper>()
{
new WhereHelper(){
FiledName=nameof(RB_Member_User.Id),
FiledValue=Id,
OperatorEnum=OperatorEnum.Equal
}
};
bool flag = member_UserRepository.Update(fileds, wheres);
return flag;
}
/// <summary> /// <summary>
/// 验证用户是否存在 /// 验证用户是否存在
/// </summary> /// </summary>
......
...@@ -714,20 +714,16 @@ namespace Mall.WebApi.Controllers.MallBase ...@@ -714,20 +714,16 @@ namespace Mall.WebApi.Controllers.MallBase
{ {
JObject parms = JObject.Parse(RequestParm.msg.ToString()); JObject parms = JObject.Parse(RequestParm.msg.ToString());
string code = parms.GetStringValue("Code"); string code = parms.GetStringValue("Code");
string openId = ""; MiniAppUserCache miniAppUserCache = new MiniAppUserCache();
if (RequestParm.MiniAppId != null && !string.IsNullOrWhiteSpace(RequestParm.MiniAppId)) if (RequestParm.MiniAppId != null && !string.IsNullOrWhiteSpace(RequestParm.MiniAppId))
{ {
var miniProgram = programModule.GetMiniProgramModule(new Model.Extend.User.RB_MiniProgram_Extend() { MiniAppId = RequestParm.MiniAppId }); var miniProgram = programModule.GetMiniProgramModule(new Model.Extend.User.RB_MiniProgram_Extend() { MiniAppId = RequestParm.MiniAppId });
if (miniProgram != null && miniProgram.MallBaseId > 0) if (miniProgram != null && miniProgram.MallBaseId > 0)
{ {
openId = Common.Plugin.WeiXinHelper.GetWeChatOpenId(miniProgram.MiniAppId, miniProgram.MiniAppSecret, code); miniAppUserCache = Common.Plugin.WeiXinHelper.GetWeChatOpenId(miniProgram.MiniAppId, miniProgram.MiniAppSecret, code);
} }
} }
var newGuid ="MiniAppOpenId_"+Guid.NewGuid().ToString(); var newGuid ="MiniAppOpenId_"+Guid.NewGuid().ToString();
var miniAppUserCache = new MiniAppUserCache()
{
UserOpenId= openId
};
UserReidsCache.SetMiniAppUsetOpenId(newGuid, miniAppUserCache); UserReidsCache.SetMiniAppUsetOpenId(newGuid, miniAppUserCache);
return ApiResult.Success(data: newGuid); return ApiResult.Success(data: newGuid);
} }
......
...@@ -136,6 +136,7 @@ namespace Mall.WebApi.Controllers.User ...@@ -136,6 +136,7 @@ namespace Mall.WebApi.Controllers.User
{ {
UserReidsCache.DeleteMiniAppUsetOpenId(demodel.OpenId); UserReidsCache.DeleteMiniAppUsetOpenId(demodel.OpenId);
demodel.OpenId = opcache.UserOpenId; demodel.OpenId = opcache.UserOpenId;
demodel.Unoinid = opcache.UserUnoinid;
} }
else else
{ {
...@@ -282,6 +283,7 @@ namespace Mall.WebApi.Controllers.User ...@@ -282,6 +283,7 @@ namespace Mall.WebApi.Controllers.User
TenantId = demodel.TenantId, TenantId = demodel.TenantId,
Name = demodel.Name, Name = demodel.Name,
OpenId = demodel.OpenId, OpenId = demodel.OpenId,
Unoinid=demodel.Unoinid,
Photo = demodel.Photo, Photo = demodel.Photo,
MemberGradeId = demodel.MemberGrade ?? 0, MemberGradeId = demodel.MemberGrade ?? 0,
Source = demodel.Source, Source = demodel.Source,
...@@ -356,11 +358,15 @@ namespace Mall.WebApi.Controllers.User ...@@ -356,11 +358,15 @@ namespace Mall.WebApi.Controllers.User
{ {
return ApiResult.Failed("账号已被冻结,请联系运营商"); return ApiResult.Failed("账号已被冻结,请联系运营商");
} }
//更新用户UnionId
if (string.IsNullOrEmpty(umodel.Unoinid) && !string.IsNullOrEmpty(demodel.Unoinid))
{
userModule.UpdateMemberUserUnionId(demodel.Unoinid, umodel.Id);
}
//自动发放新人优惠券 2020-12-31 Add By:W //自动发放新人优惠券 2020-12-31 Add By:W
if (demodel.CounponPassword == 5 && !string.IsNullOrWhiteSpace(demodel.KeyWord)) if (demodel.CounponPassword == 5 && !string.IsNullOrWhiteSpace(demodel.KeyWord))
{ {
couponResult = couponModule.AutoCoupon(new Model.Extend.MarketingCenter.RB_DiscountCoupon_Extend { UserId = umodel.Id, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId, TriggerType = 5, KeyWord = demodel.KeyWord }); couponResult = couponModule.AutoCoupon(new Model.Extend.MarketingCenter.RB_DiscountCoupon_Extend { UserId = umodel.Id, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId, TriggerType = 5, KeyWord = demodel.KeyWord });
if (couponResult != null && couponResult.ID > 0) if (couponResult != null && couponResult.ID > 0)
{ {
couponName = couponResult.Name; couponName = couponResult.Name;
...@@ -385,6 +391,7 @@ namespace Mall.WebApi.Controllers.User ...@@ -385,6 +391,7 @@ namespace Mall.WebApi.Controllers.User
TenantId = umodel.TenantId, TenantId = umodel.TenantId,
Name = umodel.Name, Name = umodel.Name,
OpenId = umodel.OpenId, OpenId = umodel.OpenId,
Unoinid=!string.IsNullOrEmpty(umodel.Unoinid)?umodel.Unoinid:demodel.Unoinid,
Photo = umodel.Photo, Photo = umodel.Photo,
MemberGradeId = umodel.MemberGrade ?? 0, MemberGradeId = umodel.MemberGrade ?? 0,
Source = demodel.Source, Source = demodel.Source,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment