public object Do_Login(BaseApi baseApi) { LoginParam loginParam = JsonConvert.DeserializeObject <LoginParam>(baseApi.param.ToString()); if (loginParam == null) { throw new ApiException(CodeMessage.InvalidParam, "InvalidParam"); } var jsonResult = SnsApi.JsCode2Json(Global.APPID, Global.APPSECRET, loginParam.code); if (jsonResult.errcode == Senparc.Weixin.ReturnCode.请求成功) { AccessTokenContainer.Register(Global.APPID, Global.APPSECRET); var sessionBag = SessionContainer.UpdateSession(null, jsonResult.openid, jsonResult.session_key); SessionUser sessionUser = new SessionUser(); sessionUser.userType = ""; sessionUser.openid = sessionBag.OpenId; sessionBag.Name = JsonConvert.SerializeObject(sessionUser); SessionContainer.Update(sessionBag.Key, sessionBag); return(new { token = sessionBag.Key, isReg = true }); } else { throw new ApiException(CodeMessage.SenparcCode, jsonResult.errmsg); } }
/// <summary> /// 登陆 /// </summary> /// <param name="baseApi"></param> /// <returns></returns> public object Do_GetToken(BaseApi baseApi) { LoginParam loginParam = JsonConvert.DeserializeObject <LoginParam>(baseApi.param.ToString()); if (loginParam == null) { throw new ApiException(CodeMessage.InvalidParam, "InvalidParam"); } if (loginParam.code == Global.XCSECRET) { SessionBag sessionBagX = SessionContainer.GetSession(Global.XCOPENID); if (sessionBagX != null) { if (sessionBagX.Name != "") { SessionContainer.RemoveFromCache(sessionBagX.OpenId); } } AccessTokenContainer.Register(Global.APPID, Global.APPSECRET); var sessionBag = SessionContainer.UpdateSession(null, Global.XCOPENID, Global.XCOPENID); OpenDao openDao = new OpenDao(); SessionUser sessionUser = new SessionUser(); Member member = openDao.GetMember(Utils.GetOpenID(sessionBag.Key)); if (member == null) { throw new ApiException(CodeMessage.SenparcCode, CodeMessage.SenparcCode.ToString()); } else { sessionUser.userType = "MEMBER"; sessionUser.openid = sessionBag.OpenId; sessionUser.memberId = member.memberId; sessionBag.Name = JsonConvert.SerializeObject(sessionUser); SessionContainer.Update(sessionBag.Key, sessionBag); SessionBag bag = new SessionBag(); bag.Name = sessionBag.Key; SessionContainer.UpdateSession(Global.XCOPENID, sessionBag.Key, sessionBag.Key); return(new { token = sessionBag.Key }); } } else { throw new ApiException(CodeMessage.SenparcCode, CodeMessage.SenparcCode.ToString()); } }
public object Do_ShopUserLogin(BaseApi baseApi) { LoginParam loginParam = JsonConvert.DeserializeObject <LoginParam>(baseApi.param.ToString()); if (loginParam == null) { throw new ApiException(CodeMessage.InvalidParam, "InvalidParam"); } var jsonResult = SnsApi.JsCode2Json(Global.STOREAPPID, Global.STOREAPPSECRET, loginParam.code); if (jsonResult.errcode == Senparc.Weixin.ReturnCode.请求成功) { AccessTokenContainer.Register(Global.STOREAPPID, Global.STOREAPPSECRET); var sessionBag = SessionContainer.UpdateSession(null, jsonResult.openid, jsonResult.session_key, jsonResult.unionid); OpenDao openDao = new OpenDao(); SessionUser sessionUser = new SessionUser(); StoreUser storeUser = openDao.GetStoreUser(Utils.GetOpenID(sessionBag.Key)); if (storeUser == null) { sessionUser.userType = "UNKWON"; sessionBag.Name = JsonConvert.SerializeObject(sessionUser); SessionContainer.Update(sessionBag.Key, sessionBag, new TimeSpan(Global.SESSION_EXPIRY_H, Global.SESSION_EXPIRY_M, Global.SESSION_EXPIRY_S)); return(new { token = sessionBag.Key, isReg = false }); } else { sessionUser.userType = "STORE"; sessionUser.openid = sessionBag.OpenId; sessionUser.storeUserId = storeUser.storeUserId; sessionBag.Name = JsonConvert.SerializeObject(sessionUser); SessionContainer.Update(sessionBag.Key, sessionBag, new TimeSpan(Global.SESSION_EXPIRY_H, Global.SESSION_EXPIRY_M, Global.SESSION_EXPIRY_S)); return(new { token = sessionBag.Key, isReg = true, storeUser.storeId, storeUser.storeUserId, storeUser.storeUserName, storeUser.storeUserImg, storeUser.storeUserPhone, storeUser.storeUserSex }); } } else { throw new ApiException(CodeMessage.SenparcCode, jsonResult.errmsg); } }
/// <summary> /// 登陆 /// </summary> /// <param name="baseApi"></param> /// <returns></returns> public object Do_Login(BaseApi baseApi) { LoginParam loginParam = JsonConvert.DeserializeObject <LoginParam>(baseApi.param.ToString()); if (loginParam == null) { throw new ApiException(CodeMessage.InvalidParam, "InvalidParam"); } var jsonResult = SnsApi.JsCode2Json(Global.APPID, Global.APPSECRET, loginParam.code); if (jsonResult.errcode == Senparc.Weixin.ReturnCode.请求成功) { AccessTokenContainer.Register(Global.APPID, Global.APPSECRET); var sessionBag = SessionContainer.UpdateSession(null, jsonResult.openid, jsonResult.session_key); OpenDao openDao = new OpenDao(); SessionUser sessionUser = new SessionUser(); Member member = openDao.GetMember(Utils.GetOpenID(sessionBag.Key)); if (member == null) { sessionUser.userType = "GUEST"; sessionBag.Name = JsonConvert.SerializeObject(sessionUser); SessionContainer.Update(sessionBag.Key, sessionBag); return(new { token = sessionBag.Key, isReg = false }); } else { sessionUser.userType = "MEMBER"; sessionUser.openid = sessionBag.OpenId; sessionUser.memberId = member.memberId; sessionBag.Name = JsonConvert.SerializeObject(sessionUser); SessionContainer.Update(sessionBag.Key, sessionBag); return(new { token = sessionBag.Key, isReg = true, member.memberId, member.memberName, member.memberImg, member.memberPhone, member.memberSex, member.scanCode }); } } else { throw new ApiException(CodeMessage.SenparcCode, jsonResult.errmsg); } }
public object Do_Login(BaseApi baseApi) { LoginParam loginParam = JsonConvert.DeserializeObject <LoginParam>(baseApi.param.ToString()); if (loginParam == null) { throw new ApiException(CodeMessage.InvalidParam, "InvalidParam"); } var jsonResult = SnsApi.JsCode2Json(Global.APPID, Global.APPSECRET, loginParam.code); if (jsonResult.errcode == Senparc.Weixin.ReturnCode.请求成功) { AccessTokenContainer.Register(Global.APPID, Global.APPSECRET); var sessionBag = SessionContainer.UpdateSession(null, jsonResult.openid, jsonResult.session_key, jsonResult.unionid); OpenDao openDao = new OpenDao(); SessionUser sessionUser = new SessionUser(); if (loginParam.tempOpenId != null && loginParam.tempOpenId.StartsWith("3rd-")) { Member member1 = openDao.GetMember(Utils.GetOpenID(sessionBag.Key)); if (member1 == null) { openDao.UpdateMemberOpenID(Utils.GetOpenID(sessionBag.Key), loginParam.tempOpenId); } else { Member member2 = openDao.GetMember(loginParam.tempOpenId); if (member1.openid != member2.openid) { openDao.MoveMember(member1.memberId, member2.memberId, member2.heart); } } } Member member = openDao.GetMember(Utils.GetOpenID(sessionBag.Key)); if (member == null) { sessionUser.userType = "GUEST"; sessionBag.Name = JsonConvert.SerializeObject(sessionUser); SessionContainer.Update(sessionBag.Key, sessionBag, new TimeSpan(Global.SESSION_EXPIRY_H, Global.SESSION_EXPIRY_M, Global.SESSION_EXPIRY_S)); return(new { token = sessionBag.Key, isReg = false }); } else { sessionUser.userType = "MEMBER"; sessionUser.openid = sessionBag.OpenId; sessionUser.memberId = member.memberId; sessionBag.Name = JsonConvert.SerializeObject(sessionUser); SessionContainer.Update(sessionBag.Key, sessionBag, new TimeSpan(Global.SESSION_EXPIRY_H, Global.SESSION_EXPIRY_M, Global.SESSION_EXPIRY_S)); openDao.AddMemberHeartCommit(member); return(new { token = sessionBag.Key, isReg = true, member.memberId, member.memberName, member.memberImg, member.memberPhone, member.memberSex, member.scanCode }); } } else { throw new ApiException(CodeMessage.SenparcCode, jsonResult.errmsg); } }