Ejemplo n.º 1
0
        /// <summary>
        /// Action执行中触发委托
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string code      = filterContext.HttpContext.Request.Query["code"].ToString();
            var    wxPubInfo = MemoryCacheHelper.GetCache <Wx_PublicInfo>("WxPubInfo");

            if (null != code && code.Length > 0)
            {
                ModelWxUserInfo mWxUserInfo = WXOAuthApiHelper.GetUserInfo(wxPubInfo.AppId, wxPubInfo.AppSecret, code);
                if (mWxUserInfo != null)
                {
                    filterContext.HttpContext.Response.Cookies.Append(ComConst.Wx_ModelWxUserInfo, JsonHelper.ToJson(mWxUserInfo), ComHelper.GetCookieOpetion());
                    filterContext.HttpContext.Session.SetString(ComConst.Wx_ModelWxUserInfo, JsonHelper.ToJson(mWxUserInfo));
                }
            }
            else
            {
                if (filterContext.HttpContext.Request.Cookies.TryGetValue(ComConst.Wx_ModelWxUserInfo, out string value))
                {
                    filterContext.HttpContext.Response.Cookies.Append(ComConst.Wx_ModelWxUserInfo, value, ComHelper.GetCookieOpetion());
                    filterContext.HttpContext.Session.SetString(ComConst.Wx_ModelWxUserInfo, value);
                }
                else
                {
                    var rst = new ContentResult();
                    rst.Content          = "登录过期,请退出重新进入";
                    filterContext.Result = rst;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 学校公众号入口
        /// </summary>
        /// <param name="sId"></param>
        public ActionResult SchoolPortal(int sId)
        {
            glbSchoolId = sId;

            ModelWxSetting mWxSetting = JsonFileProvider.Instance.GetSettings <ModelWxSetting>();
            var            wxPubInfo  = Service.GetWx_PublicInfo(2, sId);
            // 生成重定向URL
            String redirectUrl = mWxSetting.PubUrl_Host + mWxSetting.PubUrl_WxHome;
            String authUrl     = WXOAuthApiHelper.GetAuthorizeUrl(wxPubInfo.AppId, redirectUrl, "State", EnumOAuthScope.snsapi_userinfo);

            MemoryCacheHelper.SetCache("WxPubInfo", wxPubInfo);
            // 验证跳转
            Response.Redirect(authUrl);

            return(Content("已完成跳转"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 陪绮在线自有公众号入口
        /// </summary>
        public ActionResult Index()
        {
            ModelWxSetting mWxSetting = JsonFileProvider.Instance.GetSettings <ModelWxSetting>();

            var wxPubInfo = Service.GetWx_PublicInfo(1);

            // 生成重定向URL
#if DEBUG
            mWxSetting.PubUrl_Host = mWxSetting.PubUrl_Host.Replace("https", "http");
#endif
            String redirectUrl = mWxSetting.PubUrl_Host + mWxSetting.PubUrl_WxHome;
            String authUrl     = WXOAuthApiHelper.GetAuthorizeUrl(wxPubInfo.AppId, redirectUrl, "State", EnumOAuthScope.snsapi_userinfo);
            MemoryCacheHelper.SetCache("WxPubInfo", wxPubInfo);
            // 验证跳转

            Response.Redirect(authUrl);

            return(Content("已完成跳转"));
        }
Ejemplo n.º 4
0
        private int UpdateWxToken()
        {
            var sleep = 1000 * 60 * 30;//30min

            try
            {
                var dbContext  = new PinkOneMngSysContext();
                var wxPubInfos = dbContext.Wx_PublicInfo.Where(x => true).ToList();
                foreach (var wpi in wxPubInfos)
                {
                    ModelWxToken token = WXOAuthApiHelper.GetWxToken(wpi.AppId, wpi.AppSecret);
                    if (null != token && token.access_token != null)
                    {
                        ModelWxJsTicket ticket = WXOAuthApiHelper.GetWxJsTicket(token);
                        if (null != ticket)
                        {
                            string sql = "update Wx_PublicInfo set UpdateTime='{0}', AccessToken='{1}', JsApiTicket='{2}' where ID=" + wpi.ID;
                            sql = string.Format(sql, DateTime.Now, token.access_token, ticket.ticket);
                            var isOK = adoHelper.ExecuteNonQueryCmd(sql);
                            if (isOK > 0)
                            {
                                Console.WriteLine("UpdateWxToken:" + DateTime.Now + " " + wpi.AppName + "Token更新成功");
                            }
                        }
                        //sleep = token.expires_in * 60;
                    }
                    else
                    {
                        Console.WriteLine("UpdateWxToken:" + DateTime.Now + " " + wpi.AppName + "Token更新失败,原因->" + token.errmsg);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("UpdateWxToken:" + DateTime.Now + " " + "出现错误," + e.Message);
                //LogHelper.Error(e.Message);
            }
            return(sleep);
        }
Ejemplo n.º 5
0
        public ModelJsonRet UploadAttFromApp(int schoolId, long stuId, byte attType, byte attWay, byte isSendMsg)
        {
            _mjr.errMsg = "未找到匹配的项";
            var school = UnitOfWork.Repository <SYS_School>().GetEntitiesAsync(x => x.ID == schoolId).Result.FirstOrDefault();
            var stuObj = UnitOfWork.Repository <SYS_Student>().GetEntitiesAsync(x => x.SchoolId == schoolId && x.ID == stuId && x.Status == (byte)StuStatus.正常).Result.FirstOrDefault();

            if (null == stuObj)
            {
                _mjr.errMsg = "未找到学生ID";
                return(_mjr);
            }
            var currentAttStatus = CurrentAttStatus.在校;

            //判断是签入还是签出
            if (attType == (byte)AttType.签出)
            {
                currentAttStatus = CurrentAttStatus.离校;
            }

            SYS_StudentAttRecord stuAttRecord = new SYS_StudentAttRecord
            {
                SchoolId   = stuObj.SchoolId,
                MasterId   = stuId,
                AttWay     = attWay,
                AttType    = (byte)attType,
                AttTime    = DateTime.Now,
                AttTimeStr = DateTime.Now.ToString("yyyyMMddHHmmssfff"),
            };

            UnitOfWork.Repository <SYS_StudentAttRecord>().AddEntity(stuAttRecord);
            var addOk = UnitOfWork.CommitAsync().Result;

            if (addOk > 0)
            {
                _mjr.code    = 1;
                _mjr.errMsg  = "";
                _mjr.content = "OK";

                //更新学生当前考勤状态
                stuObj.AttStatus = (byte)currentAttStatus;
                UnitOfWork.Repository <SYS_Student>().UpdateEntity(stuObj);

                if (isSendMsg > 0)
                {
                    //推送考勤消息
                    List <FK_Stu_Parent> fks = UnitOfWork.Repository <FK_Stu_Parent>().GetEntitiesAsync(x => x.SchoolId == stuObj.SchoolId && x.StuId == stuObj.ID).Result;//查找学生家长
                    if (null != fks && fks.Count > 0)
                    {
                        var pWxPInfo  = UnitOfWork.Repository <Wx_PublicInfo>().GetEntitiesAsync(x => x.Type == 1).Result.FirstOrDefault();
                        var wxpInfoId = pWxPInfo == null ? 0 : pWxPInfo.ID;
                        if (school.WxPublicInfoId != null && school.WxPublicInfoId > 0)
                        {
                            wxpInfoId = (int)school.WxPublicInfoId;
                        }
                        var wxPubInfo = UnitOfWork.Repository <Wx_PublicInfo>().GetEntitiesAsync(x => x.ID == wxpInfoId).Result.FirstOrDefault();
                        foreach (var fk in fks)
                        {
                            //推送消息
                            if (null != wxPubInfo)
                            {
                                // 需要从Cookie中获取
                                ModelWxMsg <ModelWmAttendance> wxMsg = new ModelWxMsg <ModelWmAttendance>();
                                wxMsg = JsonFileProvider.Instance.GetSettings <ModelWxMsg <ModelWmAttendance> >();
                                wxMsg.data.first.value = string.Format(wxMsg.data.first.value, (AttType)attType);
                                wxMsg.url    = mWxSetting.PubUrl_Host + "/WxRelated/Center/AttDetail?attId=" + stuAttRecord.ID;
                                wxMsg.touser = fk.OpenId;
                                wxMsg.data.keyword1.value = stuObj.StuName;
                                wxMsg.data.keyword2.value = DateTime.Now.ToString();
                                wxMsg.data.keyword3.value = school.SchoolName;
                                ModelWmResult wmResult = WXOAuthApiHelper.SendTmplMessage(wxPubInfo.AccessToken, wxMsg);
                                if (null == wmResult || wmResult.msgid <= 0)
                                {
                                    LogHelper.Error("推送错误:" + wmResult.errmsg);
                                }
                            }
                        }
                    }
                }
            }
            return(_mjr);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 手动添加考勤记录
        /// </summary>
        public int AddStuAttManually(long stuId, byte attType, string attTime, string attTemp, string attRemark, byte isSendWxMsg = 1)
        {
            var res = 0;
            List <SYS_Student> allStus = (List <SYS_Student>)GetSchoolEntities("stu");
            SYS_Student        sObj    = allStus.Where(x => x.ID == stuId).FirstOrDefault();

            if (sObj != null)
            {
                DateTime             aTime = DateTime.Parse(attTime);
                SYS_StudentAttRecord sar   = new SYS_StudentAttRecord()
                {
                    SchoolId    = mlUser.School.ID,
                    MasterId    = stuId,
                    AttType     = attType,
                    AttTime     = aTime,
                    AttTimeStr  = aTime.ToString("yyyyMMddHHmmssfff"),
                    AttWay      = (byte)AttWay.手动添加,
                    Temperature = attTemp,
                    Remark      = attRemark
                };
                UnitOfWork.Repository <SYS_StudentAttRecord>().AddEntity(sar);
                var addOk = UnitOfWork.CommitAsync().Result;
                if (addOk > 0)
                {
                    //修改考勤状态
                    if (attType == (byte)AttType.签出)
                    {
                        sObj.AttStatus = (byte)CurrentAttStatus.离校;
                    }
                    else
                    {
                        sObj.AttStatus = (byte)CurrentAttStatus.在校;
                    }
                    UnitOfWork.Repository <SYS_Student>().UpdateEntity(sObj);

                    //推送
                    if (isSendWxMsg == 1)
                    {
                        //查找学生家长
                        List <FK_Stu_Parent> fks = UnitOfWork.Repository <FK_Stu_Parent>().GetEntitiesAsync(x => x.SchoolId == sObj.SchoolId && x.StuId == sObj.ID).Result;
                        if (null != fks && fks.Count > 0)
                        {
                            var pWxPInfo  = UnitOfWork.Repository <Wx_PublicInfo>().GetEntitiesAsync(x => x.Type == 1).Result.FirstOrDefault();
                            var wxpInfoId = pWxPInfo == null ? 0 : pWxPInfo.ID;
                            if (mlUser.School.WxPublicInfoId != null && mlUser.School.WxPublicInfoId > 0)
                            {
                                wxpInfoId = (int)mlUser.School.WxPublicInfoId;
                            }
                            var wxPubInfo = UnitOfWork.Repository <Wx_PublicInfo>().GetEntitiesAsync(x => x.ID == wxpInfoId).Result.FirstOrDefault();
                            foreach (var fk in fks)
                            {
                                //推送消息
                                if (null != wxPubInfo)
                                {
                                    // 需要从Cookie中获取
                                    ModelWxMsg <ModelWmAttendance> wxMsg = new ModelWxMsg <ModelWmAttendance>();
                                    wxMsg = JsonFileProvider.Instance.GetSettings <ModelWxMsg <ModelWmAttendance> >();
                                    wxMsg.data.first.value = string.Format(wxMsg.data.first.value, (AttType)attType);
                                    wxMsg.touser           = fk.OpenId;
                                    wxMsg.url = mWxSetting.PubUrl_Host + "/WxRelated/Center/AttDetail?attId=" + sar.ID;
                                    wxMsg.data.keyword1.value = sObj.StuName;
                                    wxMsg.data.keyword2.value = DateTime.Now.ToString();
                                    wxMsg.data.keyword3.value = mlUser.School.SchoolName;
                                    ModelWmResult wmResult = WXOAuthApiHelper.SendTmplMessage(wxPubInfo.AccessToken, wxMsg);
                                    if (null == wmResult || wmResult.msgid <= 0)
                                    {
                                        LogHelper.Error("推送错误:" + wmResult.errmsg);
                                    }
                                }
                            }
                        }
                    }
                }
                res = addOk + UnitOfWork.CommitAsync().Result;
            }
            return(res);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 上传考勤数据
        /// </summary>
        /// <param name="token"></param>
        /// <param name="personType">人员类型1:学生,2:职工</param>
        /// <param name="attWay">考勤方式1:刷卡,2:二维码</param>
        public ModelJsonRet UploadAtt(int schoolId, byte personType, long personId, byte attWay, string cardNo, string dateTime, string deviceId, out long attId)
        {
            attId = 0;
            var res = 0;
            //byte[] byteArray = Convert.FromBase64String(token);
            //string tokenStr= Encoding.Default.GetString(byteArray);
            //var schoolId = int.Parse(tokenStr.Split(',')[0]);
            var school = UnitOfWork.Repository <SYS_School>().GetEntitiesAsync(x => x.ID == schoolId && x.Status == 1).Result.FirstOrDefault();

            if (school == null)
            {
                _mjr.errMsg = "验证失败或学校id不存在或该学校已注销";
                return(_mjr);
            }
            var attTime    = DateTime.ParseExact(dateTime, "yyyyMdHHmmssfff", System.Globalization.CultureInfo.InvariantCulture);
            var todayStart = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));

            if (personType == 1)//学生考勤
            {
                var stuObj = UnitOfWork.Repository <SYS_Student>().GetEntitiesAsync(x => x.SchoolId == schoolId && x.ID == personId).Result.FirstOrDefault();
                if (null == stuObj)
                {
                    _mjr.errMsg = "未找到学生ID";
                    return(_mjr);
                }
                var attType          = AttType.签入;
                var currentAttStatus = CurrentAttStatus.在校;
                //判断是签入还是签出
                var todayAttRecords = UnitOfWork.Repository <SYS_StudentAttRecord>().GetEntitiesAsync(x => x.AttTime > todayStart).Result;
                if (todayAttRecords.Count > 0 && todayAttRecords.Count % 2 == 1)
                {
                    attType          = AttType.签出;
                    currentAttStatus = CurrentAttStatus.离校;
                }

                SYS_StudentAttRecord stuAttRecord = new SYS_StudentAttRecord
                {
                    SchoolId   = school.ID,
                    MasterId   = personId,
                    AttWay     = attWay,
                    AttType    = (byte)attType,
                    AttTime    = attTime,
                    AttTimeStr = dateTime,
                };
                UnitOfWork.Repository <SYS_StudentAttRecord>().AddEntity(stuAttRecord);
                var addOk = UnitOfWork.CommitAsync().Result;
                if (addOk > 0)
                {
                    res   = addOk;
                    attId = stuAttRecord.ID;
                    //更新学生当前考勤状态
                    stuObj.AttStatus = (byte)currentAttStatus;
                    UnitOfWork.Repository <SYS_Student>().UpdateEntity(stuObj);

                    //推送考勤消息
                    List <FK_Stu_Parent> fks = UnitOfWork.Repository <FK_Stu_Parent>().GetEntitiesAsync(x => x.SchoolId == stuObj.SchoolId && x.StuId == stuObj.ID).Result;//查找学生家长
                    if (null != fks && fks.Count > 0)
                    {
                        var pWxPInfo  = UnitOfWork.Repository <Wx_PublicInfo>().GetEntitiesAsync(x => x.Type == 1).Result.FirstOrDefault();
                        var wxpInfoId = pWxPInfo == null?0: pWxPInfo.ID;
                        if (school.WxPublicInfoId != null && school.WxPublicInfoId > 0)
                        {
                            wxpInfoId = (int)school.WxPublicInfoId;
                        }
                        var wxPubInfo = UnitOfWork.Repository <Wx_PublicInfo>().GetEntitiesAsync(x => x.ID == wxpInfoId).Result.FirstOrDefault();
                        foreach (var fk in fks)
                        {
                            //推送消息
                            if (null != wxPubInfo)
                            {
                                // 需要从Cookie中获取
                                ModelWxMsg <ModelWmAttendance> wxMsg = new ModelWxMsg <ModelWmAttendance>();
                                wxMsg = JsonFileProvider.Instance.GetSettings <ModelWxMsg <ModelWmAttendance> >();
                                wxMsg.data.first.value = string.Format(wxMsg.data.first.value, (AttType)attType);
                                wxMsg.url    = mWxSetting.PubUrl_Host + "/WxRelated/Center/AttDetail?attId=" + stuAttRecord.ID;
                                wxMsg.touser = fk.OpenId;
                                wxMsg.data.keyword1.value = stuObj.StuName;
                                wxMsg.data.keyword2.value = attTime.ToString();
                                wxMsg.data.keyword3.value = school.SchoolName;
                                ModelWmResult wmResult = WXOAuthApiHelper.SendTmplMessage(wxPubInfo.AccessToken, wxMsg);
                                if (null == wmResult || wmResult.msgid <= 0)
                                {
                                    LogHelper.Error("推送错误:" + wmResult.errmsg);
                                }
                            }
                        }
                    }
                }
            }
            else if (personType == 2)//职工考勤
            {
                var staffObj = UnitOfWork.Repository <SYS_Staff>().GetEntitiesAsync(x => x.SchoolId == schoolId && x.ID == personId).Result.FirstOrDefault();
                if (null == staffObj)
                {
                    _mjr.errMsg = "未找到职工ID";
                    return(_mjr);
                }
                var attType          = AttType.签入;
                var currentAttStatus = CurrentAttStatus.在校;
                //判断是签入还是签出

                var todayAttRecords = UnitOfWork.Repository <SYS_StaffAttRecord>().GetEntitiesAsync(x => x.AttTime > todayStart).Result.ToList();
                if (todayAttRecords.Count > 0 && todayAttRecords.Count % 2 == 1)
                {
                    attType          = AttType.签出;
                    currentAttStatus = CurrentAttStatus.离校;
                }
                SYS_StaffAttRecord stuAttRecord = new SYS_StaffAttRecord
                {
                    SchoolId   = school.ID,
                    MasterId   = (int)personId,
                    AttWay     = attWay,
                    AttType    = (byte)attType,
                    AttTime    = attTime,
                    AttTimeStr = dateTime,
                };
                UnitOfWork.Repository <SYS_StaffAttRecord>().AddEntity(stuAttRecord);
                var addOk = UnitOfWork.CommitAsync().Result;
                if (addOk > 0)
                {
                    res   = addOk;
                    attId = stuAttRecord.ID;
                    //更新当前考勤状态
                    staffObj.AttStatus = (byte)currentAttStatus;
                    UnitOfWork.Repository <SYS_Staff>().UpdateEntity(staffObj);

                    //推送考勤消息
                    var pWxPInfo  = UnitOfWork.Repository <Wx_PublicInfo>().GetEntitiesAsync(x => x.Type == 1).Result.FirstOrDefault();
                    var wxpInfoId = pWxPInfo == null ? 0 : pWxPInfo.ID;
                    if (school.WxPublicInfoId != null && school.WxPublicInfoId > 0)
                    {
                        wxpInfoId = (int)school.WxPublicInfoId;
                    }
                    var wxPubInfo = UnitOfWork.Repository <Wx_PublicInfo>().GetEntitiesAsync(x => x.ID == wxpInfoId).Result.FirstOrDefault();
                    if (null != wxPubInfo && staffObj.OpenId != null && staffObj.OpenId.Length > 6)
                    {
                        // 需要从Cookie中获取
                        ModelWxMsg <ModelWmAttendance> wxMsg = new ModelWxMsg <ModelWmAttendance>();
                        wxMsg = JsonFileProvider.Instance.GetSettings <ModelWxMsg <ModelWmAttendance> >();
                        wxMsg.data.first.value = (AttType)attType + " 成功";
                        //wxMsg.url = mWxSetting.PubUrl_Host + "/WxRelated/Center/AttDetail?attId=" + stuAttRecord.ID;
                        wxMsg.touser = staffObj.OpenId;
                        wxMsg.data.keyword1.value = staffObj.StaffName;
                        wxMsg.data.keyword2.value = attTime.ToString();
                        wxMsg.data.keyword3.value = school.SchoolName;
                        ModelWmResult wmResult = WXOAuthApiHelper.SendTmplMessage(wxPubInfo.AccessToken, wxMsg);
                        if (null == wmResult || wmResult.msgid <= 0)
                        {
                            LogHelper.Error("推送错误:" + wmResult.errmsg);
                        }
                    }
                }
            }
            if (res > 0)
            {
                _mjr.code    = 1;
                _mjr.content = "ok";
                //RefreshEntities("stu");
                //RefreshEntities("staff");
            }
            return(_mjr);
        }