예제 #1
0
        public async Task <IActionResult> Login(int businessId, [FromServices] ISessionDataRepository sessionService, [FromServices] IHostingEnvironment env)
        {
            var code     = Request.Headers["X-WX-Code"];
            var business = Service.Set <Business>().First(a => a.ID == businessId);
            var session  = await GetOpenId(code, business);

            if (string.IsNullOrEmpty(session.OpenId))
            {
                throw new Exception("未能得到用户OpenId,请检查小程序AppId与Secret配置");
            }
            var user = Service.Get(session.OpenId);

            if (user == null)
            {
                user = new User {
                    OpenId = session.OpenId, BusinessId = businessId
                };
                Service.Add(user);
            }
            var sessData = sessionService.SetSession(new SessionData {
                SessionKey = session.Session_Key, UserId = user.ID
            });

            user.Skey = sessData.ID;

            return(Ok(new WxRetInfo
            {
                Data = new WxUserData
                {
                    Skey = sessData.ID,
                    Userinfo = user,
                    Business = business
                }
            }));
        }
예제 #2
0
        public IActionResult PostAddress(int id, [FromBody] Address address, [FromServices] ISessionDataRepository sessionService)
        {
            var result = new JsonData();
            var user   = sessionService.GetSession(id).User;

            address.User       = user;
            address.ModifyTime = DateTime.Now;
            Service.Set <Address>().Add(address);
            result.Success = Service.Commit() > 0;
            result.Msg     = "ok";
            result.Data    = address;
            return(Json(result));
        }
 public SessionDataService(ISessionDataRepository repository)
 {
     this.repository = repository ?? throw new ArgumentNullException(nameof(repository));
 }