private void GetOpenId()
        {
            string accsess_token = string.Empty;
            string refresh_token = string.Empty;
            string openId        = string.Empty;
            string code          = Request["code"] ?? "";

            TokenMana.GetTokenForScanQR(code, out accsess_token, out refresh_token, out openId);
            Response.Write(openId);
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string errMsg = string.Empty;
                string md5    = Request["state"] ?? "";
                string url    = Request.Url.GetLeftPart(UriPartial.Path);
                string code   = Request["code"] ?? "";
                LogHelper.SaveLog("code:" + code);

                string accsess_token = string.Empty;
                string refresh_token = string.Empty;
                string openId        = string.Empty;
                string token         = string.Empty;
                if (TokenMana.GetTokenForScanQR(code, out accsess_token, out refresh_token, out openId, out errMsg))
                {
                    UserInfoModel userInfo = new UserInfoModel();
                    if (getWxUser <UserInfoModel>(openId, out userInfo, out errMsg))
                    {
                        //验证用户
                        LogHelper.SaveLog("openId:" + openId);
                        LogHelper.SaveLog("userInfo:" + userInfo.NickName);
                        Response.Redirect(WeiXinConfig.RedirectAccountPage + "?openId=" + openId + "&nickName=" + userInfo.NickName, false);
                    }
                    else
                    {
                        LogHelper.SaveLog("错误: 获取用户基本信息失败" + errMsg);
                        Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("绑定失败") + "&message=" + HttpUtility.UrlEncode(errMsg), false);
                    }
                }
                else
                {
                    LogHelper.SaveLog("错误: 获取openid失败" + errMsg);
                    Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("绑定失败") + "&message=" + HttpUtility.UrlEncode(errMsg), false);
                }
            }
            catch (Exception ex)
            {
                LogHelper.SaveLog("错误:" + ex.Message);
                Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("绑定失败") + "&message=" + HttpUtility.UrlEncode(ex.Message), false);
            }
        }
Exemple #3
0
        /// <summary>
        /// H5页面微信授权
        /// </summary>
        private void H5AuthCommon(string code)
        {
            string accsess_token = string.Empty;
            string refresh_token = string.Empty;
            string openId        = string.Empty;
            string errMsg        = string.Empty;

            try
            {
                if (TokenMana.GetTokenForScanQR(code, out accsess_token, out refresh_token, out openId, out errMsg))
                {
                    bool isReg = false;
                    IMobileTokenService mobileTokenService = BLLContainer.Resolve <IMobileTokenService>();
                    var mobileTokenModel = mobileTokenService.GetModels(p => p.OpenId.Equals(openId)).FirstOrDefault <t_MobileToken>();
                    if (mobileTokenModel != null)
                    {
                        IMemberTokenService memberTokenService = BLLContainer.Resolve <IMemberTokenService>();
                        var memberTokenModel = mobileTokenService.GetModels(p => p.OpenId.Equals(openId)).FirstOrDefault <t_MobileToken>();
                        if (memberTokenModel != null)
                        {
                            isReg = true;
                        }
                    }
                    string redirectUrl = string.Format("{0}?openId={1}&isReg={2}", CommonConfig.H5WeiXinAuthRedirectUrl, openId, Convert.ToInt32(isReg));
                    Response.Redirect(redirectUrl);
                }
                else
                {
                    LogHelper.SaveLog(TxtLogType.WeiXin, TxtLogContentType.Common, TxtLogFileType.Day, "errMsg:" + errMsg);
                    //重定向的错误页面
                    Response.Redirect(WeiXinConfig.RedirectErrorPage);
                }
            }
            catch (Exception e)
            {
                LogHelper.SaveLog(TxtLogType.WeiXin, TxtLogContentType.Exception, TxtLogFileType.Day, "Exception:" + e.Message);
            }
        }