Ejemplo n.º 1
0
 /// <summary>
 /// 微信认证
 /// https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx24e47efa56c2e554&redirect_uri=http%3a%2f%2fmap.lywenkai.cn%2fWeChatManage%2fWeiXinHome%2fRedirect&response_type=code&scope=snsapi_userinfo&state=http%3a%2f%2fmap.lywenkai.cn%2fWeChatManage%2fLogin%2fIndex#wechat_redirect
 /// </summary>
 /// <param name="code">snsapi_userinfo</param>
 /// <param name="state">回调url</param>
 /// <returns></returns>
 public ActionResult Redirect(string code, string state)
 {
     LogHelper.AddLog($"微信认证请求地址:{System.Web.HttpContext.Current.Request.Url.ToString()}  参数code: {code},参数state: {state}");
     //若用户禁止授权,则重定向后不会带上code参数
     if (string.IsNullOrEmpty(code))
     {
         return(Redirect(state));
     }
     else
     {
         WeixinToken token = new WeixinToken();
         //判断是否保存微信token,用户网页授权,不限制
         if (Session[WebSiteConfig.WXTOKEN_SESSION_NAME] != null)
         {
             token = Session[WebSiteConfig.WXTOKEN_SESSION_NAME] as WeixinToken;
         }
         else
         {
             string tokenUrl = string.Format(WeixinConfig.GetTokenUrl2, code);
             LogHelper.AddLog($"请求tokenUrl地址: {tokenUrl}");
             token = AnalyzeHelper.Get <WeixinToken>(tokenUrl);
             if (token.errcode != null)
             {
                 return(Content("网页授权Error:" + token.errcode + ":" + token.errmsg));
             }
             Session[WebSiteConfig.WXTOKEN_SESSION_NAME] = token;
         }
         Session["OpenId"] = token.openid;//进行登录
         LogHelper.AddLog($"token.openid: {Session["OpenId"]}");
         //查询用户是否存在
         var userEntity = wechatUserBll.GetEntity(token.openid);
         if (userEntity == null)
         {
             string userInfoUrl = string.Format(WeixinConfig.GetUserInfoUrl2, token.access_token, token.openid);
             var    userInfo    = AnalyzeHelper.Get <WeixinUserInfo>(userInfoUrl);
             if (userInfo.errcode != null)
             {
                 Response.Write(userInfo.errcode + ":" + userInfo.errmsg);
                 Response.End();
             }
             else
             {
                 userEntity = new WeChat_UsersEntity()
                 {
                     City       = userInfo.city,
                     Country    = userInfo.country,
                     HeadimgUrl = userInfo.headimgurl,
                     NickName   = userInfo.nickname,
                     OpenId     = userInfo.openid,
                     Province   = userInfo.province,
                     Sex        = userInfo.sex,
                     AppName    = Config.GetValue("AppName2")
                 };
                 wechatUserBll.SaveForm("", userEntity);
             }
         }
         Session[WebSiteConfig.WXUSER_SESSION_NAME] = userEntity;
         return(Redirect(state));
     }
 }
Ejemplo n.º 2
0
        //跳转
        public ActionResult Redirect(string code, string state)
        {
            //若用户禁止授权,则重定向后不会带上code参数
            if (string.IsNullOrEmpty(code))
            {
                return(Redirect(state));
            }
            else
            {
                WeixinToken token = new WeixinToken();

                //判断是否保存微信token
                if (Session[WebSiteConfig.WXTOKEN_SESSION_NAME] != null)
                {
                    token = Session[WebSiteConfig.WXTOKEN_SESSION_NAME] as WeixinToken;
                }
                else
                {
                    string tokenUrl = string.Format(WeixinConfig.GetTokenUrl, code);
                    token = AnalyzeHelper.Get <WeixinToken>(tokenUrl);
                    if (token.errcode != null)
                    {
                        return(Content(token.errcode + ":" + token.errmsg));
                    }
                    Session[WebSiteConfig.WXTOKEN_SESSION_NAME] = token;
                }
                //查询用户是否存在
                var userEntity = userBll.GetEntity(token.openid);
                if (userEntity == null)
                {
                    string userInfoUrl = string.Format(WeixinConfig.GetUserInfoUrl, token.access_token, token.openid);
                    var    userInfo    = AnalyzeHelper.Get <WeixinUserInfo>(userInfoUrl);
                    if (userInfo.errcode != null)
                    {
                        Response.Write(userInfo.errcode + ":" + userInfo.errmsg);
                        Response.End();
                    }
                    else
                    {
                        userEntity = new WeChat_UsersEntity()
                        {
                            City       = userInfo.city,
                            Country    = userInfo.country,
                            HeadimgUrl = userInfo.headimgurl,
                            NickName   = userInfo.nickname,
                            OpenId     = userInfo.openid,
                            Province   = userInfo.province,
                            Sex        = userInfo.sex,
                            AppName    = WeixinConfig.AppName
                        };
                        userBll.SaveForm("", userEntity);
                    }
                }
                Session[WebSiteConfig.WXUSER_SESSION_NAME] = userEntity;
                return(Redirect(state));
            }
        }
Ejemplo n.º 3
0
        public ActionResult Audit(POS_ApplyEntity entity)
        {
            //推荐人
            if (string.IsNullOrEmpty(entity.RecommenderId) && !string.IsNullOrEmpty(entity.Recommender))
            {
                UserEntity user = userBLL.GetEntityByName(entity.Recommender);
                if (user != null)
                {
                    entity.RecommenderId = user.UserId;
                    //更新微信用户表中的姓名和ID

                    if (!string.IsNullOrEmpty(CurrentWxUser.OpenId))
                    {
                        WeChat_UsersEntity wechatUser = wechatUserBll.GetEntity(CurrentWxUser.OpenId);
                        wechatUser.UserId   = user.UserId;
                        wechatUser.UserName = entity.Recommender;
                        wechatUserBll.SaveForm(CurrentWxUser.OpenId, wechatUser);
                    }
                }
            }
            entity.PassMark   = 0;
            entity.CreateTime = DateTime.Now;
            //插入实名认证表
            posApplyBll.SaveForm("", entity);


            //通知指定的微信客服
            //#region 获取access_token
            //string apiurl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx24e47efa56c2e554&secret=1f8de99c6304d13e5a65efa418638ee4";
            //WebRequest req = WebRequest.Create(@apiurl);
            //req.Method = "POST";
            //WebResponse response = req.GetResponse();
            //Stream stream = response.GetResponseStream();
            //Encoding encode = Encoding.UTF8;
            //StreamReader reader = new StreamReader(stream, encode);
            //string detail = reader.ReadToEnd();
            //var jd = JsonConvert.DeserializeObject<WXApi>(detail);
            //string token = (String)jd.access_token;
            //#endregion

            //string url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + token;

            //string touser = ConfigurationManager.AppSettings["touser"];
            //string message = "{\"touser\":\"" + touser + "\"," +
            //    "\"msgtype\":\"text\"," +
            //    "\"text\": " +
            //    "{\"content\":\"有客户提交了实名认证资料" +
            //    "\n手机号:" + entity.mobileNumber +
            //    "\n客户名称:" + entity.custName +
            //    "\n身份证:" + entity.custCertCode +
            //    "\n地址:" + entity.custCertAddress +
            //    " \"} }";
            //string str = GetResponseData(message, @url);
            return(Content("true"));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 保存表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="entity">实体对象</param>
 /// <returns></returns>
 public void SaveForm(string keyValue, WeChat_UsersEntity entity)
 {
     try
     {
         service.SaveForm(keyValue, entity);
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 个人中心
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            WeChat_UsersEntity entity = wechatUserBll.GetEntity(CurrentWxUser.OpenId);
            DataTable          dt     = kuCompanyBll.GetFollowState();

            ViewBag.state3 = dt.Rows[0][0].ToString();
            ViewBag.state2 = dt.Rows[1][0].ToString();
            ViewBag.state4 = dt.Rows[2][0].ToString();
            ViewBag.state0 = dt.Rows[3][0].ToString();
            return(View(entity));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 登录验证
        /// </summary>
        /// <param name="username">账号</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        public ActionResult CheckLogin(string username, string password)
        {
            UserEntity userEntity = new UserBLL().CheckLogin(username, password);

            if (userEntity != null)
            {
                //登录后会修改微信用户的userid,username字段,下次可直接进入主界面
                WeChat_UsersEntity entity = wechatUserBll.GetEntity(CurrentWxUser.OpenId);
                if (entity != null)
                {
                    entity.UserId   = userEntity.UserId;
                    entity.UserName = userEntity.RealName;
                    wechatUserBll.SaveForm(CurrentWxUser.OpenId, entity);
                }
                return(Content("true"));
            }
            else
            {
                return(Content("false"));
            }
        }
Ejemplo n.º 7
0
        public ActionResult Index()
        {
            //1.授权登录
            string returnUrl = Request.Url.ToString();
            string url       = WeixinAuth(returnUrl);

            if (!string.IsNullOrEmpty(url))
            {
                return(Redirect(url));
            }
            WeChat_UsersEntity entity = wechatUserBll.GetEntity(CurrentWxUser.OpenId);

            if (entity != null)
            {
                ViewBag.UserName = entity.UserName;
                ViewBag.UserId   = entity.UserId;
            }
            else
            {
                ViewBag.UserName = "";
                ViewBag.UserId   = "";
            }
            return(View());
        }
Ejemplo n.º 8
0
        public ActionResult Index(string urlstr)
        {
            //1.2根据注册的微信id去用户表中匹配是否有此员工
            WeChat_UsersEntity entity = wechatUserBll.GetEntity(CurrentWxUser.OpenId);

            //WeChat_UsersEntity entity = wechatUserBll.GetEntity("o7HEd1LjnupfP0BBBMz5f69MFYVE");
            if (!string.IsNullOrEmpty(entity.UserName) && !string.IsNullOrEmpty(entity.UserId))
            {
                UserEntity userEntity = new UserBLL().GetEntity(entity.UserId);

                LogEntity logEntity = new LogEntity();
                logEntity.CategoryId     = 1;
                logEntity.OperateTypeId  = ((int)OperationType.Login).ToString();
                logEntity.OperateType    = EnumAttribute.GetDescription(OperationType.AppLogin);
                logEntity.OperateAccount = userEntity.RealName;
                logEntity.OperateUserId  = userEntity.RealName;
                logEntity.Module         = Config.GetValue("SoftName");
                //写入日志
                logEntity.ExecuteResult     = 1;
                logEntity.ExecuteResultJson = "登录成功";
                logEntity.WriteLog();

                AuthorizeBLL authorizeBLL = new AuthorizeBLL();
                Operator     operators    = new Operator();
                operators.UserId        = userEntity.UserId;
                operators.Code          = userEntity.EnCode;
                operators.Account       = userEntity.Account;
                operators.UserName      = userEntity.RealName;
                operators.Password      = userEntity.Password;
                operators.Secretkey     = userEntity.Secretkey;
                operators.CompanyId     = userEntity.OrganizeId;
                operators.DepartmentId  = userEntity.DepartmentId;
                operators.IPAddress     = Net.Ip;
                operators.IPAddressName = IPLocation.GetLocation(Net.Ip);
                operators.ObjectId      = new PermissionBLL().GetObjectStr(userEntity.UserId);
                operators.LogTime       = DateTime.Now;
                operators.Token         = DESEncrypt.Encrypt(Guid.NewGuid().ToString());

                //写入当前用户数据权限
                AuthorizeDataModel dataAuthorize = new AuthorizeDataModel();
                dataAuthorize.ReadAutorize        = authorizeBLL.GetDataAuthor(operators);
                dataAuthorize.ReadAutorizeUserId  = authorizeBLL.GetDataAuthorUserId(operators);
                dataAuthorize.WriteAutorize       = authorizeBLL.GetDataAuthor(operators, true);
                dataAuthorize.WriteAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators, true);
                operators.DataAuthorize           = dataAuthorize;
                //判断是否系统管理员
                if (userEntity.Account == "System")
                {
                    operators.IsSystem = true;
                }
                else
                {
                    operators.IsSystem = false;
                }
                OperatorProvider.Provider.AddCurrent(operators);
                //return RedirectToAction("Index", "WeiXinHome");
                return(RedirectToAction("Index", "WeiXinHome", new { urlstr = urlstr }));
            }
            else
            {
                return(View());
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 微信认证
        /// https://open.weixin.qq.com/connect/oauth2/authorize
        /// ?appid=wx24e47efa56c2e554
        /// &redirect_uri=http%3a%2f%2fmap.lywenkai.cn%2fWeChatManage%2fWeiXinHome%2fRedirect
        /// &response_type=code&scope=snsapi_userinfo
        /// &state=http%3a%2f%2fmap.lywenkai.cn%2fWeChatManage%2fLogin%2fIndex
        /// #wechat_redirect
        /// </summary>
        /// <param name="code">snsapi_userinfo</param>
        /// <param name="state">回调url</param>
        /// <returns></returns>
        public ActionResult Redirect(string code, string state)
        {
            //若用户禁止授权,则重定向后不会带上code参数
            if (string.IsNullOrEmpty(code))
            {
                return(Redirect(state));
            }
            else
            {
                WeixinToken token = new WeixinToken();
                //判断是否保存微信token,用户网页授权access_token,不限制,,拿到授权access_token和openid
                if (Session[WebSiteConfig.WXTOKEN_SESSION_NAME] != null)
                {
                    token = Session[WebSiteConfig.WXTOKEN_SESSION_NAME] as WeixinToken;
                }
                else
                {
                    string tokenUrl = string.Format(WeixinConfig.GetTokenUrl, code);
                    token = AnalyzeHelper.Get <WeixinToken>(tokenUrl);
                    if (token.errcode != null)
                    {
                        return(Content(token.errcode + ":" + token.errmsg));
                    }
                    Session[WebSiteConfig.WXTOKEN_SESSION_NAME] = token;
                }

                //查询用户是否存在
                var userEntity = wechatUserBll.GetEntity(token.openid);
                if (userEntity == null)
                {
                    #region CacheFactory方式获取token
                    ////全局token--基础access_token,每日限额2000
                    //var cacheToken = CacheFactory.Cache().GetCache<string>("access_token");
                    //if (cacheToken == null)
                    //{
                    //    var userInfoBase = AnalyzeHelper.Get<WeixinTokenBase>(WeixinConfig.GetTokenBaseUrl);
                    //    cacheToken = userInfoBase.access_token;
                    //    CacheFactory.Cache().WriteCache(cacheToken, "access_token", DateTime.Now.AddSeconds(7000));
                    //}
                    #endregion

                    //改成盛派容器获取基础token
                    string base_token = TemplateWxApp.getToken(); //获取AccessToken结果

                    string userInfoUrl = string.Format(WeixinConfig.GetUserInfoUrl, base_token, token.openid);
                    var    userInfo    = AnalyzeHelper.Get <WeixinUserInfo>(userInfoUrl);
                    if (userInfo.errcode != null)
                    {
                        Response.Write(userInfo.errcode + ":" + userInfo.errmsg);
                        Response.End();
                    }
                    else
                    {
                        LogHelper.AddLog("用户关注状态:" + userInfo.subscribe.ToString());
                        if (userInfo.subscribe != 1)
                        {
                            //未关注
                            //未关注先跳转关注https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzU3MzczNTY4Mw==#wechat_redirect
                            //微信7.0之后限制,加载完成之后按钮一闪而逝,WeixinConfig.BizUrl,生成二维码,从微信打开该链接即可
                            return(RedirectToAction("Guanzhu", "Brand"));
                        }
                        userEntity = new WeChat_UsersEntity()
                        {
                            City       = userInfo.city,
                            Country    = userInfo.country,
                            HeadimgUrl = userInfo.headimgurl,
                            NickName   = userInfo.nickname,
                            OpenId     = userInfo.openid,
                            Province   = userInfo.province,
                            Sex        = userInfo.sex,
                            AppName    = Config.GetValue("AppName")
                        };
                        wechatUserBll.SaveForm("", userEntity);
                    }
                }
                Session[WebSiteConfig.WXUSER_SESSION_NAME] = userEntity;
                return(Redirect(state));
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 个人中心
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            WeChat_UsersEntity entity = wechatUserBll.GetEntity("o7HEd1LjnupfP0BBBMz5f69MFYVE");//CurrentWxUser.OpenId

            return(View(entity));
        }
Ejemplo n.º 11
0
 public ActionResult SaveForm(string keyValue, WeChat_UsersEntity entity)
 {
     wechat_usersbll.SaveForm(keyValue, entity);
     return(Success("操作成功。"));
 }