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

新增UnionId解析

parent 4f11ca23
......@@ -58,6 +58,14 @@ namespace Mall.Common
set;
}
/// <summary>
/// UnionId
/// </summary>
public string Unoinid
{
get;set;
}
/// <summary>
///
///
......
......@@ -165,5 +165,10 @@ namespace Mall.Common
/// 用户OpenId
/// </summary>
public string UserOpenId { get; set; }
/// <summary>
/// 用户UnionId
/// </summary>
public string UserUnoinid { get; set; }
}
}
......@@ -40,10 +40,10 @@ namespace Mall.Common.Plugin
/// <param name="AppSecret"></param>
/// <param name="Code"></param>
/// <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 openid = "";
try
{
//请求路径
......@@ -52,7 +52,8 @@ namespace Mall.Common.Plugin
if (result != null && !string.IsNullOrEmpty(result))
{
JObject jObj = JObject.Parse(result);
openid = jObj["openid"].ToString();
miniAppUserCache.UserOpenId = jObj["openid"].ToString();
miniAppUserCache.UserUnoinid = jObj["unionid"].ToString();
}
}
catch (Exception ex)
......@@ -64,9 +65,11 @@ namespace Mall.Common.Plugin
Common.Plugin.LogHelper.Write(ex, string.Format("GetWeChatOpenId:result={0}&&Code={1}", result, Code));
}
}
return openid;
return miniAppUserCache;
}
/// <summary>
/// 验证OpenId是否有效
/// </summary>
......
......@@ -264,5 +264,10 @@ namespace Mall.Model.Entity.User
/// 查看次数
/// </summary>
public int LookTimes { get; set; }
/// <summary>
/// UnionId唯一Id
/// </summary>
public string Unoinid { get; set; }
}
}
......@@ -312,6 +312,30 @@ namespace Mall.Module.User
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>
......
......@@ -714,20 +714,16 @@ namespace Mall.WebApi.Controllers.MallBase
{
JObject parms = JObject.Parse(RequestParm.msg.ToString());
string code = parms.GetStringValue("Code");
string openId = "";
MiniAppUserCache miniAppUserCache = new MiniAppUserCache();
if (RequestParm.MiniAppId != null && !string.IsNullOrWhiteSpace(RequestParm.MiniAppId))
{
var miniProgram = programModule.GetMiniProgramModule(new Model.Extend.User.RB_MiniProgram_Extend() { MiniAppId = RequestParm.MiniAppId });
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 miniAppUserCache = new MiniAppUserCache()
{
UserOpenId= openId
};
UserReidsCache.SetMiniAppUsetOpenId(newGuid, miniAppUserCache);
return ApiResult.Success(data: newGuid);
}
......
......@@ -136,6 +136,7 @@ namespace Mall.WebApi.Controllers.User
{
UserReidsCache.DeleteMiniAppUsetOpenId(demodel.OpenId);
demodel.OpenId = opcache.UserOpenId;
demodel.Unoinid = opcache.UserUnoinid;
}
else
{
......@@ -282,6 +283,7 @@ namespace Mall.WebApi.Controllers.User
TenantId = demodel.TenantId,
Name = demodel.Name,
OpenId = demodel.OpenId,
Unoinid=demodel.Unoinid,
Photo = demodel.Photo,
MemberGradeId = demodel.MemberGrade ?? 0,
Source = demodel.Source,
......@@ -356,11 +358,15 @@ namespace Mall.WebApi.Controllers.User
{
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
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 });
if (couponResult != null && couponResult.ID > 0)
{
couponName = couponResult.Name;
......@@ -385,6 +391,7 @@ namespace Mall.WebApi.Controllers.User
TenantId = umodel.TenantId,
Name = umodel.Name,
OpenId = umodel.OpenId,
Unoinid=!string.IsNullOrEmpty(umodel.Unoinid)?umodel.Unoinid:demodel.Unoinid,
Photo = umodel.Photo,
MemberGradeId = umodel.MemberGrade ?? 0,
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