コード例 #1
0
        public ActionResult OnSetWXInfo(string sessionId, string nickName, int gender, string kindergartenName)
        {
            StatusReport sr = new StatusReport();

            if (string.IsNullOrEmpty(sessionId))
            {
                sr.status     = "Fail";
                sr.result     = "sessionId不存在";
                sr.parameters = sessionId;
                return(Json(sr));
            }
            SessionBag sessionBag = null;

            sessionBag = SessionContainer.GetSession(sessionId);
            if (sessionBag == null)
            {
                sr.status = "Fail";
                sr.result = "session已失效";
                return(Json(sr));
            }
            string openId = sessionBag.OpenId;

            sr = WXUserDal.SetWXInfo(openId, nickName, gender, kindergartenName);
            return(Json(sr));
        }
コード例 #2
0
        public ActionResult OnGetMyInfo(string kindergartenName, string sessionId)
        {
            StatusReport sr = new StatusReport();

            if (string.IsNullOrEmpty(kindergartenName))
            {
                sr.status = "Fail";
                sr.result = "未指定幼儿园";
                return(Json(sr));
            }
            if (string.IsNullOrEmpty(sessionId))
            {
                sr.status     = "Fail";
                sr.result     = "sessionId不存在";
                sr.parameters = sessionId;
                return(Json(sr));
            }
            SessionBag sessionBag = null;

            sessionBag = SessionContainer.GetSession(sessionId);
            if (sessionBag == null)
            {
                sr.status = "Fail";
                sr.result = "session已失效";
                return(Json(sr));
            }
            string openId = sessionBag.OpenId;

            sr = WXUserDal.GetMyInfo(kindergartenName, openId);
            return(Json(sr));
        }
コード例 #3
0
        public ActionResult OnBindUser(string userName, string password, string sessionId)
        {
            StatusReport sr         = new StatusReport();
            SessionBag   sessionBag = null;

            sessionBag = SessionContainer.GetSession(sessionId);
            if (sessionBag == null)
            {
                sr.status = "Fail";
                sr.result = "session已失效";
                return(Json(sr));
            }
            string openId = sessionBag.OpenId;
            //string openId = "oTTDy0KN71B2XLMXobrapvhqlHcY";
            int    id   = EmployeeDal.CheckEmployeeExist(userName, password);
            string temp = id > 0 ? "存在" : "不存在";

            if (id > 0)
            {
                sr = EmployeeDal.BindEmployee(id, openId);
                return(Json(sr));
            }
            else
            {
                var data = new
                {
                    msg      = "hello world",
                    username = userName,
                    password = password,
                    isExist  = temp
                };
                return(Json(data));
            }
        }
コード例 #4
0
        private string GetOpenid(string sessionKey)
        {
            SessionBag sessionBag = SessionContainer.GetSession(sessionKey);
            string     opeinId    = sessionBag.OpenId;

            return(opeinId);
        }
コード例 #5
0
ファイル: StudioServices.cs プロジェクト: dorucioclea/Studio
        private HttpWebRequest CreateSiteWebRequest(SiteInfo siteInfo, string url)
        {
            var req         = (HttpWebRequest)WebRequest.Create(url);
            var siteSession = SessionBag.Get <SiteSession>();

            if (siteSession != null)
            {
                if (siteSession.BearerToken != null)
                {
                    req.AddBearerToken(siteSession.BearerToken);
                }
                else if (siteSession.SessionId != null)
                {
                    var overrideParam = "X-" + Keywords.SessionId;
                    req.Headers[overrideParam] = siteSession.SessionId;
                }
                else if (siteSession.UserName != null && siteSession.Password != null)
                {
                    req.AddBasicAuth(siteSession.UserName, siteSession.Password);
                }
                else if (siteSession.AuthSecret != null)
                {
                    var overrideParam = HttpHeaders.XParamOverridePrefix + Keywords.AuthSecret;
                    req.Headers[overrideParam] = siteSession.AuthSecret;
                }
            }
            return(req);
        }
コード例 #6
0
        public ActionResult OnGetUserInfo(string sessionId)
        {
            StatusReport sr = new StatusReport();

            if (string.IsNullOrEmpty(sessionId))//如果sessionId为空,则返回错误信息
            {
                sr.status     = "Fail";
                sr.result     = "sessionId不存在";
                sr.parameters = sessionId;
                return(Json(sr));
            }
            SessionBag sessionBag = null;

            sessionBag = SessionContainer.GetSession(sessionId);
            if (sessionBag == null)
            {
                sr.status = "Fail";
                sr.result = "session已失效";
                return(Json(sr));
            }
            string openId = sessionBag.OpenId;

            sr = ProprietorDal.CheckOpenIdExist(openId);
            //if (sr.data != null)
            //{
            //    var o = JsonConvert.DeserializeObject(sr.data);
            //    return Json(new { status = "Success", result = "成功", data = o });
            //}
            //else
            //{
            return(Json(sr));
            //}
        }
コード例 #7
0
ファイル: StudioServices.cs プロジェクト: dorucioclea/Studio
        private JsonServiceClient CreateSiteClient(SiteInfo siteInfo)
        {
            var client      = new JsonServiceClient(siteInfo.BaseUrl);
            var siteSession = SessionBag.Get <SiteSession>();

            if (siteSession != null)
            {
                if (siteSession.BearerToken != null)
                {
                    client.BearerToken = siteSession.BearerToken;
                }
                else if (siteSession.SessionId != null)
                {
                    client.RequestFilter = req =>
                                           req.Headers["X-" + Keywords.SessionId] = siteSession.SessionId;
                }
                else if (siteSession.UserName != null && siteSession.Password != null)
                {
                    client.SetCredentials(siteSession.UserName, siteSession.Password);
                }
                else if (siteSession.AuthSecret != null)
                {
                    client.RequestFilter = req =>
                                           req.Headers[HttpHeaders.XParamOverridePrefix + Keywords.AuthSecret] = siteSession.AuthSecret;
                }
            }
            return(client);
        }
 public object Any(GetSession request)
 {
     return(new GetSessionResponse
     {
         Result = SessionAs <CustomUserSession>(),
         UnAuthInfo = SessionBag.Get <UnAuthInfo>(typeof(UnAuthInfo).Name),
     });
 }
コード例 #9
0
ファイル: PaymentBuss.cs プロジェクト: jangocheng/O2O-SERVER
        public object Do_Payment(object param)
        {
            PaymentParam paymentParam = JsonConvert.DeserializeObject <PaymentParam>(param.ToString());

            if (paymentParam == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }

            try
            {
                SessionBag sessionBag = SessionContainer.GetSession(paymentParam.token);
                var        openId     = sessionBag.OpenId;
                var        billId     = this.createBill(openId, paymentParam);
                var        totalPrice = this.getBillPrice(paymentParam);
                if (totalPrice == 0)
                {
                    throw new ApiException(CodeMessage.PaymentTotalPriceZero, "PaymentTotalPriceZero");
                }
                var timeStamp   = TenPayV3Util.GetTimestamp();
                var nonceStr    = TenPayV3Util.GetNoncestr();
                var product     = paymentParam.product;
                var xmlDataInfo =
                    new TenPayV3UnifiedorderRequestData(
                        tenPayV3Info.AppId,
                        tenPayV3Info.MchId,
                        product,
                        billId,
                        totalPrice,
                        "127.0.0.1",
                        tenPayV3Info.TenPayV3Notify,
                        TenPayV3Type.JSAPI,
                        openId,
                        tenPayV3Info.Key,
                        nonceStr);

                var result = TenPayV3.Html5Order(xmlDataInfo);
                pDao.writePrePayId(billId, result.prepay_id);
                var package = string.Format("prepay_id={0}", result.prepay_id);
                var paySign = TenPayV3.GetJsPaySign(tenPayV3Info.AppId, timeStamp, nonceStr, package, tenPayV3Info.Key);

                PaymentResults paymentResults = new PaymentResults();
                paymentResults.appId     = tenPayV3Info.AppId;
                paymentResults.nonceStr  = nonceStr;
                paymentResults.package   = package;
                paymentResults.paySign   = paySign;
                paymentResults.timeStamp = timeStamp;
                paymentResults.product   = product;
                paymentResults.billId    = billId;

                return(paymentResults);
            }
            catch (Exception ex)
            {
                throw new ApiException(CodeMessage.PaymentError, "PaymentError");
            }
        }
コード例 #10
0
        public static string GetOpenID(string token)
        {
            SessionBag sessionBag = SessionContainer.GetSession(token);

            if (sessionBag == null)
            {
                return(null);
            }
            return(sessionBag.OpenId);
        }
コード例 #11
0
        public object Any(HelloRequest request)
        {
            SessionBag.Set(HelloServiceCounterKey, SessionBag.Get <int>(HelloServiceCounterKey) + 1);
            var userSession = SessionAs <CustomUserSession>();
            var roles       = string.Join(", ", userSession.Roles.ToArray());

            return(new HelloResponse {
                Result = "Hello, " + request.Name + ", your role(s): " + roles
            });
        }
コード例 #12
0
        /// <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());
            }
        }
コード例 #13
0
ファイル: StudioServices.cs プロジェクト: dorucioclea/Studio
        public object Any(SiteAuthenticate request)
        {
            var siteInfo    = AssertSite(request.Slug);
            var siteSession = SessionBag.Get <SiteSession>();

            if (siteSession?.User != null && request.provider != AuthenticateService.LogoutAction && request.provider == null)
            {
                return(siteSession.User);
            }

            try
            {
                var client      = CreateSiteClient(siteInfo);
                var authRequest = request.ConvertTo <Authenticate>();

                if (request.AccessToken?.IndexOf(':') >= 0)                            //required for AuthProviders needing both Access+Secret (e.g. twitter)
                {
                    authRequest.AccessTokenSecret = request.AccessToken.LeftPart(':'); //secret is first part when both provided
                    authRequest.AccessToken       = request.AccessToken.RightPart(':');
                }

                if (nonProviders.Contains(request.provider))
                {
                    authRequest.provider = null;
                    if (request.provider == "bearer")
                    {
                        client.BearerToken = request.AccessToken;
                    }
                    else if (request.provider == "session")
                    {
                        client.SetSessionId(request.AccessToken);
                    }
                    else if (request.provider == "authsecret")
                    {
                        client.Headers[HttpHeaders.XParamOverridePrefix + Keywords.AuthSecret] = request.AccessToken;
                    }
                }

                var response = client.Post(authRequest);
                siteSession = SiteSession.Create(request, response);
                SessionBag.Set(siteSession);
            }
            finally
            {
                if (request.provider == AuthenticateService.LogoutAction)
                {
                    SessionBag.Remove <SiteSession>();
                    siteSession = null;
                }
            }

            return(siteSession?.User);
        }
コード例 #14
0
        public ActionResult OnBindUser(string userName, string phoneNumber, string sessionId)
        {
            StatusReport sr         = new StatusReport();
            SessionBag   sessionBag = null;

            sessionBag = SessionContainer.GetSession(sessionId);
            //string sessionCode = (string)sessionBag.Name;
            //string sessionCode =(string)HttpContext.Session[phoneNumber];

            if (sessionBag == null)//如果sessionId失效,返回失败信息
            {
                sr.status = "Fail";
                sr.result = "session已失效";
                return(Json(sr, JsonRequestBehavior.AllowGet));
            }

            //if (string.IsNullOrEmpty(sessionCode))//如果sessionCode失效,返回失败信息
            //{
            //    sr.status = "Fail";
            //    sr.result = "codeSession已失效";
            //    sr.parameters = phoneNumber;
            //    return Json(sr,JsonRequestBehavior.AllowGet);
            //}

            //if (code != sessionCode)//如果验证码与用户收到的验证码不一致,返回失败信息
            //{
            //    sr.status = "Fail";
            //    sr.result = "code错误";
            //    return Json(sr, JsonRequestBehavior.AllowGet);
            //}

            string openId = sessionBag.OpenId;
            int    id     = ProprietorDal.CheckProprietorExist(userName, phoneNumber);
            string temp   = id != 0 ? "存在" : "不存在";

            if (id != 0)
            {
                sr = ProprietorDal.BindProprietor(Math.Abs(id), userName, phoneNumber, openId, id > 0 ? true : false);
                return(Json(sr, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var data = new
                {
                    msg         = "hello world",
                    username    = userName,
                    phoneNumber = phoneNumber,
                    isExist     = temp
                };
                return(Json(data, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #15
0
        public ActionResult OnSetKanyuanData(string kindergartenName, string name, string gender, string birth,
                                             string relateName, string relation, string phoneNumber, string address, string isYoueryuan,
                                             string desire, string joinLottery, string ruyuanDate, string isAppointment, string appointmentDate,
                                             string relateGender, string haveReceiver, string receiverName, string needSchoolBus, string sessionId)
        {
            StatusReport sr = new StatusReport();

            //如果未指定幼儿园,返回错误信息
            if (string.IsNullOrEmpty(kindergartenName))
            {
                sr.status = "Fail";
                sr.result = "未指定幼儿园";
                return(Json(sr));
            }

            //如果姓名或联系方式为空,返回错误信息
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(phoneNumber))
            {
                sr.status = "Fail";
                sr.result = "姓名和联系电话不能为空";
                return(Json(sr));
            }

            if (string.IsNullOrEmpty(sessionId))
            {
                sr.status     = "Fail";
                sr.result     = "sessionId不存在";
                sr.parameters = sessionId;
                return(Json(sr));
            }
            SessionBag sessionBag = null;

            sessionBag = SessionContainer.GetSession(sessionId);
            if (sessionBag == null)
            {
                sr.status = "Fail";
                sr.result = "session已失效";
                return(Json(sr));
            }
            string openId = sessionBag.OpenId;

            sr = WXUserDal.SetUserInfo(openId, relateName, phoneNumber, kindergartenName, name, relation);

            //如果提交的数据满足条件,调用KanyuanDataDal.SetKanyuanData方法,将数据存入数据库中
            sr = KanyuanDataDal.SetKanyuanData(kindergartenName, name, gender, birth, relateName, relation, phoneNumber,
                                               address, isYoueryuan, desire, joinLottery, ruyuanDate, isAppointment, appointmentDate, relateGender,
                                               haveReceiver, receiverName, needSchoolBus, openId);


            return(Json(sr));
        }
コード例 #16
0
        /// <summary>
        /// 扩展生成3rd_sessioin
        /// </summary>
        /// <param name="sessionId==openid"></param>
        /// <param name="sessionKey"></param>
        /// <param name="unionId"></param>
        /// <returns></returns>
        public static SessionBag UpdateSession(string sessionId, string sessionKey, string unionId)
        {
            SessionBag bag = new SessionBag()
            {
                Key        = sessionId,
                SessionKey = sessionKey,
                UnionId    = unionId,
                OpenId     = sessionId,
                ExpireTime = Tools.GetExpireTime()
            };

            redisCache.Write(sessionId, bag, Tools.GetExpireTime());
            return(bag);
        }
コード例 #17
0
        /// <summary>
        /// 检查token判断执行权限
        /// </summary>
        /// <param name="apiType"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        private bool CheckToken(ApiType apiType, string token)
        {
            bool b = true;

#if !DEBUG
            if (apiType != ApiType.UserApi)
            {
                SessionBag sessionBag = SessionContainer.GetSession(token);
                if (sessionBag == null)
                {
                    b = false;
                }
            }
#endif
            return(b);
        }
コード例 #18
0
ファイル: OrderBuss.cs プロジェクト: server-llwell/o3o-s6r
        public object Do_GetOrder(object param)
        {
            OrderListParam orderListParam = JsonConvert.DeserializeObject <OrderListParam>(param.ToString());

            if (orderListParam == null || orderListParam.orderId == "" || orderListParam.orderId == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }
            SessionBag sessionBag = SessionContainer.GetSession(orderListParam.token);
            var        openId     = sessionBag.OpenId;

            OrderDao      orderDao      = new OrderDao();
            OrderListItem orderListItem = orderDao.getOrder(openId, orderListParam.orderId);

            return(orderListItem);
        }
コード例 #19
0
        public static string GetMemberID(string token)
        {
            SessionBag sessionBag = SessionContainer.GetSession(token);

            if (sessionBag == null)
            {
                return(null);
            }
            SessionUser sessionUser = JsonConvert.DeserializeObject <SessionUser>(sessionBag.Name);

            if (sessionUser == null)
            {
                return(null);
            }
            return(sessionUser.memberId);
        }
コード例 #20
0
        public object Do_ShopUserReg(BaseApi baseApi)
        {
            StoreUserRegParam storeUserRegParam = JsonConvert.DeserializeObject <StoreUserRegParam>(baseApi.param.ToString());

            if (storeUserRegParam == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }

            SessionBag sessionBag = SessionContainer.GetSession(baseApi.token);

            if (sessionBag == null)
            {
                throw new ApiException(CodeMessage.InvalidToken, "InvalidToken");
            }

            OpenDao   openDao   = new OpenDao();
            string    openID    = Utils.GetOpenID(baseApi.token);
            StoreUser storeUser = openDao.GetStoreUser(openID);

            if (storeUser != null)
            {
                throw new ApiException(CodeMessage.StoreUserExist, "StoreUserExist");
            }

            string storeId = openDao.GetStoreId(storeUserRegParam.storeCode);

            if (storeId == "")
            {
                throw new ApiException(CodeMessage.InvalidStoreCode, "InvalidStoreCode");
            }

            if (!openDao.StoreUserReg(storeUserRegParam, openID, storeId))
            {
                throw new ApiException(CodeMessage.StoreUserRegError, "StoreUserRegError");
            }
            storeUser = openDao.GetStoreUser(openID);
            SessionUser sessionUser = JsonConvert.DeserializeObject <SessionUser>(sessionBag.Name);

            sessionUser.openid      = sessionBag.OpenId;
            sessionUser.storeUserId = storeUser.storeUserId;
            sessionUser.userType    = "STORE";
            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("");
        }
コード例 #21
0
        public ActionResult OnBindUser(string userName, string password, string sessionId)
        {
            StatusReport sr         = new StatusReport();
            SessionBag   sessionBag = null;

            sessionBag = SessionContainer.GetSession(sessionId);
            if (sessionBag == null)
            {
                sr.status = "Fail";
                sr.result = "session已失效";
                return(Json(sr));
            }
            string openId = sessionBag.OpenId;

            sr = EmployeeDal.BindUser(userName, password, openId);
            return(Json(sr));
        }
コード例 #22
0
        public ActionResult OnLogin(string code)
        {
            JsCode2JsonResult jsonResult = SnsApi.JsCode2Json(Comman.Appid, Comman.AppSecret, code);

            if (jsonResult.errcode == Senparc.Weixin.ReturnCode.请求成功)
            {
                SessionBag sessionBag = SessionContainer.UpdateSession(null, jsonResult.openid, jsonResult.session_key);
                Session[sessionBag.Key] = jsonResult;
                Session.Timeout         = 60;
                StatusReport sr = EmployeeDal.CheckOpenIdExist(jsonResult.openid);
                return(Json(new { success = true, msg = "OK", sessionId = sessionBag.Key, userInfo = sr }));
            }
            else
            {
                return(Json(new { success = false, mag = jsonResult.errmsg, result = jsonResult }));
            }
        }
コード例 #23
0
        public ActionResult OnUnifiedOrder(string sessionId, double totalCharge, string dataBag)
        {
            StatusReport sr         = new StatusReport();
            SessionBag   sessionBag = null;

            sessionBag = SessionContainer.GetSession(sessionId);
            if (sessionBag == null)
            {
                sr.status = "Fail";
                sr.result = "session已失效";
                return(Json(sr));
            }
            string openId = sessionBag.OpenId;

            sr = WXPayDal.UnifiedOrder(openId, totalCharge, dataBag);
            return(Json(sr));
        }
コード例 #24
0
        public object Do_UserReg(BaseApi baseApi)
        {
            UserRegParam userRegParam = JsonConvert.DeserializeObject <UserRegParam>(baseApi.param.ToString());

            if (userRegParam == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }

            SessionBag sessionBag = SessionContainer.GetSession(baseApi.token);

            if (sessionBag == null)
            {
                throw new ApiException(CodeMessage.InvalidToken, "InvalidToken");
            }

            OpenDao openDao = new OpenDao();
            string  openID  = Utils.GetOpenID(baseApi.token);
            User    user    = openDao.GetUser(openID);

            if (user != null)
            {
                throw new ApiException(CodeMessage.UserExist, "UserExist");
            }

            if (!openDao.GetUserCode(userRegParam.userCode))
            {
                throw new ApiException(CodeMessage.InvalidUserCode, "InvalidUserCode");
            }

            if (!openDao.UserReg(userRegParam, openID))
            {
                throw new ApiException(CodeMessage.UserRegError, "UserRegError");
            }
            user = openDao.GetUser(openID);
            SessionUser sessionUser = JsonConvert.DeserializeObject <SessionUser>(sessionBag.Name);

            sessionUser.openid   = sessionBag.OpenId;
            sessionUser.userId   = user.userId;
            sessionUser.userType = "USER";
            sessionBag.Name      = JsonConvert.SerializeObject(sessionUser);
            SessionContainer.Update(sessionBag.Key, sessionBag);

            return("");
        }
コード例 #25
0
ファイル: SessionService.cs プロジェクト: cody82/DownSite
        public object Any(Session request)
        {
            var untyped = SessionBag["untyped"] as CustomSession ?? new CustomSession();
            var typed   = SessionBag.Get <CustomSession>("typed") ?? new CustomSession();

            untyped.Counter++;
            typed.Counter++;

            SessionBag["untyped"] = untyped;
            SessionBag.Set("typed", typed);

            var response = new SessionResponse {
                Typed   = typed,
                UnTyped = untyped,
            };

            return(response);
        }
コード例 #26
0
        public object Do_CheckCode(BaseApi baseApi)
        {
            CheckCodeParam checkCodeParam = JsonConvert.DeserializeObject <CheckCodeParam>(baseApi.param.ToString());

            if (checkCodeParam == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }
            string tSms = Utils.GetCache <string>(baseApi.token);

            if (tSms != null)
            {
                throw new ApiException(CodeMessage.SmsCodeError, "SmsCodeError");
            }

            Utils.SetCache(baseApi.token, "sms", 0, 0, 30);

            string      code        = new Random().Next(999999).ToString().PadLeft(6, '0');
            SessionBag  sessionBag  = SessionContainer.GetSession(baseApi.token);
            SessionUser sessionUser = JsonConvert.DeserializeObject <SessionUser>(sessionBag.Name);

            if (sessionUser == null)
            {
                throw new ApiException(CodeMessage.InvalidToken, "InvalidToken");
            }
            sessionUser.checkCode  = code;
            sessionUser.checkPhone = checkCodeParam.phone;
            sessionBag.Name        = JsonConvert.SerializeObject(sessionUser);
            SessionContainer.Update(sessionBag.Key, sessionBag, new TimeSpan(1, 0, 0));
            StringBuilder builder = new StringBuilder();

            builder.AppendFormat(Global.SMS_CODE_URL, Global.SMS_CODE, Global.SMS_TPL, code, checkCodeParam.phone);
            string url = builder.ToString();
            string res = Utils.GetHttp(url);

            SmsCodeRes smsCodeRes = JsonConvert.DeserializeObject <SmsCodeRes>(res);

            if (smsCodeRes == null || smsCodeRes.error_code != 0)
            {
                throw new ApiException(CodeMessage.SmsCodeError, (smsCodeRes == null ? "SmsCodeError" : smsCodeRes.reason));
            }

            return("");
        }
コード例 #27
0
        public object Any(UpdateSession request)
        {
            var session = SessionAs <CustomUserSession>();

            session.CustomName = request.CustomName;

            var unAuthInfo = SessionBag.Get <UnAuthInfo>() ?? new UnAuthInfo();

            unAuthInfo.CustomInfo = request.CustomName + " - CustomInfo";
            SessionBag.Set(unAuthInfo);

            this.SaveSession(session);

            return(new GetSessionResponse
            {
                Result = SessionAs <CustomUserSession>(),
                UnAuthInfo = unAuthInfo,
            });
        }
コード例 #28
0
        public ActionResult OnGetKanyuanData(string kindergartenName, string sessionId)
        {
            StatusReport sr = new StatusReport();

            //如果未指定幼儿园,返回错误信息
            if (string.IsNullOrEmpty(kindergartenName))
            {
                sr.status = "Fail";
                sr.result = "未指定幼儿园";
                return(Json(sr));
            }

            //如果姓名或联系方式为空,返回错误信息
            //if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(phoneNumber))
            //{
            //    sr.status = "Fail";
            //    sr.result = "姓名和联系电话不能为空";
            //    return Json(sr);
            //}

            if (string.IsNullOrEmpty(sessionId))
            {
                sr.status     = "Fail";
                sr.result     = "sessionId不存在";
                sr.parameters = sessionId;
                return(Json(sr));
            }
            SessionBag sessionBag = null;

            sessionBag = SessionContainer.GetSession(sessionId);
            if (sessionBag == null)
            {
                sr.status = "Fail";
                sr.result = "session已失效";
                return(Json(sr));
            }
            string openId = sessionBag.OpenId;

            //如果提交的数据满足条件,调用KanyuanDataDal.GetKanyuanData方法,在数据库中获取满足条件的数据
            sr = KanyuanDataDal.GetKanyuanData(kindergartenName, openId);

            return(Json(sr));
        }
コード例 #29
0
        /// <summary>
        /// 验证令牌
        /// </summary>
        /// <param name="baseApi">传入参数</param>
        /// <param name="route">API路径</param>
        /// <returns>验证结果,null为通过</returns>
        private Message CheckToken(BaseApi baseApi, bool needLogin, string route)
        {
            Message msg = null;

            if (baseApi.token != null)
            {
                SessionBag sessionBag = SessionContainer.GetSession(baseApi.token);
                if (sessionBag == null)
                {
                    msg = new Message(CodeMessage.InvalidToken, "InvalidToken");
                }
                else
                {
                    if (sessionBag.Name == null)
                    {
                        msg = new Message(CodeMessage.InvalidToken, "InvalidToken");
                    }
                    else
                    {
                        SessionUser sessionUser = JsonConvert.DeserializeObject <SessionUser>(sessionBag.Name);
                        if (sessionUser == null)
                        {
                            msg = new Message(CodeMessage.InvalidToken, "InvalidToken");
                        }


                        if (needLogin)
                        {
                            if (sessionUser.openid != sessionBag.OpenId)
                            {
                                msg = new Message(CodeMessage.NeedLogin, "NeedLogin");
                            }
                        }
                    }
                }
            }
            else
            {
                msg = new Message(CodeMessage.InvalidToken, "InvalidToken");
            }
            return(msg);
        }
コード例 #30
0
        /// <summary>
        /// 申请登陆
        /// </summary>
        /// <param name="name">账户名</param>
        /// <param name="password">登陆密码</param>
        /// <param name="effectiveTime">保存时间</param>
        /// <param name="isAdmin">是否管理员登陆</param>
        /// <returns></returns>
        private EnumLoginState ApplyLogin(string name, string password, int effectiveTime, bool isAdmin)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(EnumLoginState.AccountError);
            }
            Users user = new Users();

            if (name.Contains("@"))
            {
                user = UsersAccessor.GetByEmail(name);
            }
            else
            {
                user = UsersAccessor.GetByMobile(name);
            }
            if (user == null)
            {
                return(EnumLoginState.AccountError);
            }
            if (!string.Equals(user.Password, Strings.PasswordEncrypt(password)))
            {
                return(EnumLoginState.PasswordError);
            }


            UserId           = user.UserId;
            Password         = user.Password;
            Username         = user.Username;
            Mobile           = user.Mobile;
            Email            = user.Email;
            CurrentLoginTime = DateTime.Now;
            PermissionCode   = user.PermissionCode;

            SaveLogin(this, effectiveTime);
            SessionBag.Refresh();
            SessionBag.CopyValue();
            //更新用户登陆次数
            //更新在线数据
            return(EnumLoginState.Succeed);
        }