Example #1
0
        public ActionResult Authorize(string CurrentUser, string ConnectionId)
        {
            string url = OAuthApi.GetAuthorizeUrl(MPConfig.AppId,
                                                  "http://www.webpsj.com/home/backurl?CurrentUser="******"&ConnectionId=" + ConnectionId
                                                  , "STATE", Senparc.Weixin.MP.OAuthScope.snsapi_userinfo);

            FileLog.AddLog(url);
            return(Redirect(url));
        }
        /// <summary>
        /// IP认证
        /// </summary>
        /// <returns></returns>
        private BaseDtoResp AuthorizeIP()
        {
            if (DataConfig.QyConfig.AllowIP != "*")
            {
                string ip  = IPHelper.GetClientIP();
                string ip2 = IPHelper.GetExternalIP();
                string ip3 = IPHelper.GetLocalIP();
                FileLog.AddLog(string.Format("ip={0},ip2={1},ip3={2}", ip, ip2, ip3));

                if (!DataConfig.QyConfig.AllowIP.Split('|').Contains(ip))
                {
                    return new BaseDtoResp()
                           {
                               Msg = "IP认证不通过"
                           }
                }
                ;
            }
            return(new BaseDtoResp()
            {
                IsSuccess = true
            });
        }
Example #3
0
        public ActionResult BackUrl(string code, string CurrentUser, string ConnectionId)
        {
            FileLog.AddLog("code=" + code + "CurrentUser="******"ConnectionId=" + ConnectionId);
            string url = OAuthApi.GetAuthorizeUrl(MPConfig.AppId,
                                                  "http://www.webpsj.com/home/backurl?CurrentUser="******"&ConnectionId=" + ConnectionId,
                                                  "STATE", Senparc.Weixin.MP.OAuthScope.snsapi_userinfo);

            FileLog.AddLog("url=" + url);
            var tokenResult = OAuthApi.GetAccessToken(MPConfig.AppId, MPConfig.AppSecret, code);

            FileLog.AddLog("tokenResult=" + JsonConvert.SerializeObject(tokenResult));
            var userInfo = OAuthApi.GetUserInfo(tokenResult.access_token, tokenResult.openid);

            FileLog.AddLog("userInfo=" + JsonConvert.SerializeObject(userInfo));
            dynamic expando = new System.Dynamic.ExpandoObject();

            expando.url         = url;
            expando.code        = code;
            expando.tokenResult = tokenResult;
            expando.userInfo    = userInfo;

            FileLog.AddLog("expando=" + JsonConvert.SerializeObject(expando));

            var item = BaseHub.list.Where(p => p.ConnectionId == ConnectionId).FirstOrDefault();

            if (item != null)
            {
                item.Name      = userInfo.nickname;
                item.OtherData = userInfo;
            }

            ViewBag.CurrentUser  = CurrentUser;
            ViewBag.ConnectionId = ConnectionId;
            //return Json(expando, JsonRequestBehavior.AllowGet);
            return(View(userInfo));
        }