Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CookieHelper.WriteCookie("WXLoginType", "3");

                #region 获取返回路径
                string returnurl = GlobalUtils.WebURL + "/Member/my_account.aspx";

                if (!string.IsNullOrEmpty(WEBRequest.GetString("ReturnUrl")))
                {
                    returnurl = WEBRequest.GetString("ReturnUrl");//团贷网返回路径
                    if (string.IsNullOrEmpty(returnurl))
                    {
                        returnurl = GlobalUtils.WebURL + "/Member/my_account.aspx";
                    }
                }
                #endregion

                string        CallbackUrl = GlobalUtils.WebURL + ConfigHelper.getConfigString("CallbackUrl") + "?ReturnUrl=" + returnurl;
                ThirdLoginSDK shareSdk    = new ThirdLoginSDK();
                shareSdk.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
                //获取微信授权时URL
                string requestUrl = shareSdk.GetCodeUrl(CallbackUrl);

                Response.Redirect(requestUrl);
            }
        }
Exemplo n.º 2
0
        private void GetRequestToken()
        {
            CookieHelper.WriteCookie("WXLoginType", "1");

            #region 获取返回路径
            string returnurl = GlobalUtils.WebURL + "/Member/my_account.aspx";

            if (!string.IsNullOrEmpty(WEBRequest.GetString("ReturnUrl")))
            {
                returnurl = WEBRequest.GetString("ReturnUrl");
                if (string.IsNullOrEmpty(returnurl))
                {
                    returnurl = GlobalUtils.WebURL + "/Member/my_account.aspx";
                }
            }
            #endregion

            string        CallbackUrl = "ReturnUrl=" + returnurl;
            ThirdLoginSDK shareSdk    = new ThirdLoginSDK();
            shareSdk.InitSDK(ThirdLoginSDK.ThirdLoginType.QQ);
            //获取微信授权时URL
            string requestUrl = shareSdk.GetCodeUrl(CallbackUrl);

            Response.Redirect(requestUrl);
        }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            this.returnUrl = WEBRequest.GetQueryString("ReturnUrl");
            LoginType      = CookieHelper.GetCookie("WXLoginType");
            code           = WEBRequest.GetQueryString("code");
            //微信登录时从cookie中没法取到
            if (LoginType.ToText().IsEmpty())
            {
                LoginType = WEBRequest.GetQueryString("state");
                CookieHelper.WriteCookie("WXLoginType", LoginType);
            }

            if (returnUrl.ToText().IsEmpty())
            {
                returnUrl = "/Member/my_account.aspx";
            }
            if (code.ToText() == "")
            {
                //授权失败时返回到登录框
                Response.Redirect("/user/Login.aspx?ReturnUrl=" + returnUrl);
                return;
            }

            //判断当前第三方帐号是否有绑定过,若有绑定过直接登录。
            ThirdLoginSDK shareSdk = new ThirdLoginSDK();

            shareSdk.InitSDK(ThirdLoginSDK.GetLoginType(LoginType.ToString()));
            //根据code获取第三方用户信息
            ThirdLoginSDK.ThirdUserInfo mUserInfo = shareSdk.GetUserSampleInfo(code);

            if (LoginType.ToInt(0) == (int)ThirdLoginSDK.ThirdLoginType.QQ)
            {
                CookieHelper.WriteCookie("OpenId", Tool.Cryptography.TripleDESEncrypt(mUserInfo.UId));
            }
            else if (LoginType.ToInt(0) == (int)ThirdLoginSDK.ThirdLoginType.Sina)
            {
                CookieHelper.WriteCookie("weiboUserId", mUserInfo.UId);
            }
            else if (LoginType.ToInt(0) == (int)ThirdLoginSDK.ThirdLoginType.WeiXin)
            {
                CookieHelper.WriteCookie("weixinUserId", mUserInfo.UId);
            }
            CookieHelper.WriteCookie("ThirdLoginUserInfo", JsonHelper.ToJson(mUserInfo));

            UserBLL userbll = new UserBLL();

            SqlParameter[]    paramData = new SqlParameter[] { new SqlParameter("@ThirdPartyId", mUserInfo.UId) };
            UserBasicInfoInfo model     = userbll.WXGetUserBasicInfo("ThirdPartyId=@ThirdPartyId", paramData);

            if (model != null)
            {
                //先前已绑定过,就直接登录
                WXRegister.UserLogin(model);
                Response.Redirect(this.returnUrl);
                return;
            }
        }
Exemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string code = WEBRequest.GetQueryString("code");

            if (!IsPostBack)
            {
                ThirdLoginSDK sdkApi = new ThirdLoginSDK();
                sdkApi.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
                string SelfOpenId = sdkApi.GetCookieOpenId(code);
            }
        }
Exemplo n.º 5
0
        protected void btnCreateQR_Click(object sender, EventArgs e)
        {
            this.txtQRUrl.Text = string.Empty;
            this.ImageQR.ImageUrl = "";
            if (this.txtPassword.Text.Equals("createQRAdministrator"))
            {
                if (string.IsNullOrEmpty(this.txtSourceFrom.Text.Trim()) || this.txtSourceFrom.Text.Trim().Length > 59)
                {
                    JavaScript.Alert("推广渠道填写错误,最多60个字,不能空白");
                }
                #region 先判断以前有没有,有就直接返回
                const string querySql = "select * from [dbo].[WXQRInfos] where sourceFrom =@sourceFrom order by AddDate desc ";
                var param = new DynamicParameters();
                param.Add("@SourceFrom", this.txtSourceFrom.Text.Trim());

                var wxQrInfos =PublicConn.QueryActivityBySql<WXQRInfo>(querySql,ref param);
                if (wxQrInfos.Count >=1)
                {
                    this.txtQRUrl.Text = wxQrInfos.FirstOrDefault().QrUrl;
                    this.ImageQR.ImageUrl = "http://s.jiathis.com/qrcode.php?url=" + wxQrInfos.FirstOrDefault().QrUrl;
                    JavaScript.Alert("已经生成过这样的推广二维码了哦!");
                    return;
                }

                #endregion
                #region  调用接口获取
                ThirdLoginSDK sdk = new ThirdLoginSDK();
                sdk.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
                var wxQr = sdk.GetWXQrInfoBy(this.txtSourceFrom.Text);
                if (wxQr != null)
                {
                    this.txtQRUrl.Text = wxQr.url;
                    const string insertSql = @"insert into [dbo].[WXQRInfos]([Id],[SourceFrom],[AddDate],[QrUrl],[Ticket])
                                                values (@Id,@SourceFrom,@AddDate,@QrUrl,@Ticket)";

                    var param2 = new DynamicParameters();
                    param2.Add("@Id", Guid.NewGuid());
                    param2.Add("@SourceFrom", this.txtSourceFrom.Text);
                    param2.Add("@AddDate", DateTime.Now);
                    param2.Add("@QrUrl", wxQr.url);
                    param2.Add("@Ticket", wxQr.ticket);

                    PublicConn.ExecuteActivity(insertSql,ref param2); 
                    this.ImageQR.ImageUrl = "http://s.jiathis.com/qrcode.php?url=" + wxQr.url;
                }
                #endregion
            }
            else
            {
                Jscript.Alert("请输入正确的管理员密码");
            }
        }
Exemplo n.º 6
0
        protected void InitFormData()
        {
            ThirdLoginSDK sdkApi = new ThirdLoginSDK();

            sdkApi.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
            SelfOpenId = sdkApi.GetCookieOpenId("");

            WealthPage.GodWealthRecordInfo wealthInfo = WealthPage.GetUserGodWealthInfo(SelfOpenId);
            if (wealthInfo != null)
            {
                GodShowName = wealthInfo.ShowName;
            }
            RedPackedStatus = WealthPage.CheckRedPacketStatus().ToString();
        }
Exemplo n.º 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            this.returnUrl = WEBRequest.GetQueryString("ReturnUrl");
            LoginType      = ThirdLoginSDK.GetLoginType(CookieHelper.GetCookie("WXLoginType"));
            code           = WEBRequest.GetQueryString("code");

            if (this.returnUrl.IsEmpty())
            {
                this.returnUrl = "/Member/my_account.aspx";
            }
            ThirdLoginSDK shareSdk = new ThirdLoginSDK();
            UserBLL       userbll  = new UserBLL();

            //初始化SDK
            shareSdk.InitSDK(LoginType);

            //根据code获取第三方用户信息
            ThirdLoginSDK.ThirdUserInfo mUserInfo = shareSdk.GetCacheUserInfo();
            string strUId = shareSdk.GetCacheUId();

            SqlParameter[]    paramData = new SqlParameter[] { new SqlParameter("@ThirdPartyId", strUId) };
            UserBasicInfoInfo model     = userbll.WXGetUserBasicInfo("ThirdPartyId=@ThirdPartyId", paramData);

            if (model != null)
            {
                //当已存在时直接登录,并跳转
                WXRegister.UserLogin(model);
                Response.Redirect(this.returnUrl);
                return;
            }
            else
            {
                //用第三登录信息注册一新帐号
                Guid userid          = Guid.NewGuid();
                var  userbasicEntity = WXRegister.AddUserInfo(userid, "tuandai_weixin", "", "", "", mUserInfo.NickName, mUserInfo.HeadImg, mUserInfo.UId, (int)LoginType);
                if (userbasicEntity != null)
                {
                    model = userbll.GetUserBasicInfoModelById(userid);
                    WXRegister.UserLogin(model);
                    Response.Redirect(this.returnUrl);
                    return;
                }
            }

            Response.Redirect("/user/Login.aspx?ReturnUrl=" + this.returnUrl);
        }
Exemplo n.º 8
0
        //获取当前用户的OpenId
        private string GetCurrentOpenId(string code)
        {
            ThirdLoginSDK sdkApi = new ThirdLoginSDK();

            sdkApi.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
            string HostOpenId = sdkApi.GetCookieOpenId(code);

            //if (GlobalUtils.OpenId.ToText().IsNotEmpty())
            //{
            //    HostOpenId = GlobalUtils.OpenId;
            //}
            //else
            //{
            //    HostOpenId = WeiXin.GetOpenid(code);
            //    GlobalUtils.WriteOpenIdToCookie(HostOpenId);
            //}
            return(HostOpenId);
        }
Exemplo n.º 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            code = WEBRequest.GetQueryString("code");
            if (!IsPostBack)
            {
                if (code.IsEmpty())
                {
                    HttpContext.Current.Response.Redirect(GlobalUtils.WebURL + "/Activity/20150901Vote/AuthIndex.aspx", true);

                    return;
                }
                ThirdLoginSDK sdkApi = new ThirdLoginSDK();
                sdkApi.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
                HostOpenId = sdkApi.GetCookieOpenId(code);

                GetHadVoterCount();
            }
        }
Exemplo n.º 10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string        code = Tool.WEBRequest.GetQueryString("code");
            ThirdLoginSDK sdk  = new ThirdLoginSDK();

            sdk.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
            //获取微信上用户信息
            TuanDai.WXApiWeb.Common.ThirdLoginSDK.WXOAuthUser wxUserInfo = sdk.GetWXUserSubscribeInfor(code);
            if (wxUserInfo != null)
            {
                HeadImg  = wxUserInfo.headimgurl;
                NickName = wxUserInfo.nickname;
            }
            else
            {
                HeadImg  = "images/tx1.png";
                NickName = "我是团粉";
            }
        }
Exemplo n.º 11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            code      = WEBRequest.GetQueryString("code");
            ExtendKey = WEBRequest.GetQueryString("ExtendKey");
            IsLogin   = WebUserAuth.IsAuthenticated ? 1 : 0;


            if (!IsPostBack)
            {
                WeiXinApi jssdk = new WeiXinApi();
                jssdk.InitApi();
                System.Collections.Hashtable hs = jssdk.getSignPackage();
                AppId     = hs["appId"].ToString();
                NonceStr  = hs["nonceStr"].ToString();
                TimeStamp = hs["timestamp"].ToInt(0);
                Signature = hs["signature"].ToString();
            }
            ThirdLoginSDK sdkApi = new ThirdLoginSDK();

            sdkApi.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
            HostOpenId = sdkApi.GetCookieOpenId(code);

            if (!IsPostBack)
            {
                //判断有没帮好友做过,假如有为好友过时,则显示出自已领蛋糕的界面。 Allen 2015-07-13
                if (ExtendKey.IsNotEmpty())
                {
                    //帮好友做蛋糕
                    bool isDoCake = AjaxHandler.CheckUserHasDoCake(ExtendKey, HostOpenId);
                    if (isDoCake)
                    {
                        ExtendKey = "";//清空推广人
                    }
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 开始做蛋糕
        /// </summary>
        public void StartDoCake()
        {
            PrintJson("-2", "您帐号在微信上未授权!");
            return;

            //改为从DB中读取活动起止日期
            GamePrizeInfo gprizeInfo = CelebHelper.GetPrizeInfor("FirstPrize");

            if (gprizeInfo != null)
            {
                CelebHelper.ActivityStartDate = gprizeInfo.ActivityStartDate;
                CelebHelper.ActivityEndDate   = gprizeInfo.ActivityEndDate;
            }

            bool   isLogin = WebUserAuth.IsAuthenticated;
            string code    = WEBRequest.GetFormString("code");

            if (code.IsEmpty())
            {
                PrintJson("-2", "您帐号在微信上未授权!");
                return;
            }
            if (DateTime.Now < CelebHelper.ActivityStartDate)
            {
                PrintJson("-3", "您来得太早了,<br/>活动还未开始!");
                return;
            }
            if (DateTime.Now > CelebHelper.ActivityEndDate)
            {
                PrintJson("-3", "您来得太晚了,<br/>活动已结束了!");
                return;
            }
            string ExtendOpenId = WEBRequest.GetFormString("ExtendKey"); //推广人OpenId
            Guid?  userId       = WebUserAuth.UserId;
            bool   isSelfUser   = true;                                  //是否自已在做蛋糕

            if (ExtendOpenId.IsNotEmpty())
            {
                isSelfUser = false;
                if (!CheckUserIsExists(ExtendOpenId))
                {
                    PrintJson("-2", "对不起,该邀请码无效!");
                    return;
                }
            }

            string HostOpenId = GetCurrentOpenId(code);

            //判断OpenId为空
            if (HostOpenId.IsEmpty())
            {
                PrintJson("-2", "您帐号在微信上未授权!");
                return;
            }
            bool isDoCake = false;

            if (ExtendOpenId.IsNotEmpty())
            {
                //帮好友做蛋糕
                isDoCake = CheckUserHasDoCake(ExtendOpenId, HostOpenId);
            }
            else
            {
                isDoCake = CheckUserHasDoCake(HostOpenId, HostOpenId);
            }
            if (isDoCake)
            {
                string errMsg = "您已经做过蛋糕了!";
                if (isSelfUser == false)
                {
                    errMsg = "您已帮好友做过一次蛋糕!";
                }
                PrintJson("-1", errMsg);
                return;
            }

            ThirdLoginSDK sdk = new ThirdLoginSDK();

            sdk.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
            //获取微信上用户信息
            TuanDai.WXApiWeb.Common.ThirdLoginSDK.WXOAuthUser wxUserInfo = sdk.GetWXUserSubscribeInfor(code);
            if (wxUserInfo == null || wxUserInfo.nickname.IsEmpty())
            {
                PrintJson("-2", "您帐号获取微信授权失败!");
                return;
            }

            string strSQL       = "";
            bool   IsAddSuccess = false;

            //给自已做蛋糕
            if (isSelfUser)
            {
                GamePrizeInfo prizeInfo = CelebHelper.GetPrizeInfor("RedPacket");
                if (prizeInfo == null)
                {
                    PrintJson("-4", "对不起,该活动参与人数已满,<br/>下次再参与吧!");
                    return;
                }

                #region 写入做蛋糕记录
//                using (SqlConnection connection = CelebHelper.OpenConnection(2))
//                {
//                    UserBLL userbll = new UserBLL();
//                    UserBasicInfoInfo userInfo = null;
//                    if (isLogin)
//                    {
//                        userInfo = userbll.GetUserBasicInfoModelById(userId.Value);
//                    }
//                    strSQL = @"insert into Activity_ThreeYearGame_Record(Id,UserId,UserName,NickName,WXOpenId,AddDate,CakeNum,ExpirationDate,GetPrizeDate)
//                               values(@Id,@UserId,@UserName,@NickName,@WXOpenId,@AddDate,@CakeNum,@ExpirationDate,@GetPrizeDate)";

//                    DynamicParameters dyParams = new DynamicParameters();
//                    dyParams.Add("@Id", Guid.NewGuid());
//                    if (userInfo != null)
//                    {
//                        dyParams.Add("@UserId", userInfo.Id);
//                        dyParams.Add("@UserName", userInfo.UserName);
//                        dyParams.Add("@NickName", userInfo.NickName);
//                        dyParams.Add("@ExpirationDate", null);//已登录时,奖品就已发送至团宝箱,这里没过期时间
//                    }
//                    else
//                    {
//                        dyParams.Add("@UserId", null);
//                        dyParams.Add("@UserName", "");
//                        dyParams.Add("@NickName", "");
//                        dyParams.Add("@ExpirationDate", CelebHelper.GetPrizeEndDate);
//                    }
//                    dyParams.Add("@WXOpenId", HostOpenId);
//                    dyParams.Add("@AddDate", DateTime.Now);
//                    dyParams.Add("@CakeNum", 0);
//                    if (userInfo != null)
//                        dyParams.Add("@GetPrizeDate", DateTime.Now);
//                    else
//                        dyParams.Add("@GetPrizeDate", null);

//                    IsAddSuccess = connection.Execute(strSQL, dyParams) > 0;

//                    //登录后将奖品自动插入我的团宝箱
//                    if (IsAddSuccess && userInfo != null)
//                    {
//                        CelebHelper.AddToMyPrize(prizeInfo, WebUserAuth.UserId.Value, false);
//                    }
//                }
                #endregion
            }

            //往做蛋糕好友表中添加一笔
            AddOneFriendDataDelegate addFriend = new AddOneFriendDataDelegate(AddOneFriendData);
            if (isSelfUser)
            {
                //自已做蛋糕
                addFriend.Invoke(HostOpenId, HostOpenId, isLogin, wxUserInfo);
            }
            else
            {
                //好友做蛋糕
                addFriend.Invoke(ExtendOpenId, HostOpenId, isLogin, wxUserInfo);
            }
            string showMsg = "";
            if (isSelfUser)
            {
                showMsg = "<p>恭喜您,参与成功!</p><p>获得<span class=\"c-ffde00\">10元</span>投资红包!</p><p style=\"text-align:center\">(详见\"我的奖品\")</p>";
            }
            else
            {
                string friendNickName = GetFriendNickName(ExtendOpenId);
                showMsg = string.Format("<p>恭喜您!成功帮好友“{0}”做蛋糕!</p>", friendNickName.IsEmpty() ? "他" : friendNickName);
            }

            PrintJson("1", showMsg);
        }
Exemplo n.º 13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            CurrTel = new UserBLL().GetUserBasicInfoModelById(WebUserAuth.UserId.Value).TelNo;
            if (string.IsNullOrEmpty(CurrTel))
            {
                CurrTel = "1********";
            }
            CookieHelper.WriteCookie("shellben4tel", Tool.Common.Utils.StringHandler.MaskTelNo(CurrTel));
            string cmd = Request.QueryString["cmd"];

            if (cmd == "notbind")
            {
                NotBind();
                return;
            }
            if (GlobalUtils.IsWeiXinBrowser)
            {
                try
                {
                    string code   = WEBRequest.GetQueryString("code");
                    string openId = WEBRequest.GetQueryString("openid");
                    if (openId.IsNotEmpty())
                    {
                        GlobalUtils.WriteOpenIdToCookie(openId);
                    }

                    ThirdLoginSDK sdk = new ThirdLoginSDK();
                    sdk.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
                    //获取微信上用户信息
                    wxUserInfo = sdk.GetWXUserSubscribeInfor(code, openId.ToText());
                    if (wxUserInfo != null && !string.IsNullOrEmpty(wxUserInfo.nickname))
                    {
                        CookieHelper.WriteCookie("shellben4wxname", wxUserInfo.nickname);
                        openId = wxUserInfo.openid;
                    }
                    TuanDai.LogSystem.LogClient.LogClients.TraceLog(TdConfig.ApplicationName, "GetWeiXinUserInfo", "", JsonConvert.SerializeObject(wxUserInfo));

                    var    posturl = GlobalUtils.MsgApiUrl;
                    string err     = "";
                    var    descStr =
                        TuanDai.WXSystem.Core.Common.MsgDesc.GetDescStr("{\"Data\":{\"WeiXinOpenId\":\"" + openId + "\"}}");
                    TuanDai.LogSystem.LogClient.LogClients.TraceLog(TdConfig.ApplicationName, "GetWeiXinUserInfo123", "", descStr);
                    string resp = HttpClient.HttpUtil.HttpPostJson(TdConfig.ApplicationName,
                                                                   posturl + "/4/GetUserIdsByWeixinOpenId", descStr,
                                                                   out err, null, 3);
                    if (!string.IsNullOrEmpty(resp))
                    {
                        var returnmsg =
                            JsonConvert
                            .DeserializeObject <TuanDai.WXSystem.Core.Common.MsgApiResponseMessage <List <string> > >(
                                resp);
                        if (returnmsg != null)
                        {
                            if (returnmsg.Data.Count > 0)
                            {
                                foreach (var item in returnmsg.Data)
                                {
                                    if (!uList.Exists(o => o.UserId == Guid.Parse(item)))
                                    {
                                        WeiXinUser user = new WeiXinUser();
                                        user.UserId     = Guid.Parse(item);
                                        user.DescUserId = Tool.DESC.EncryptTripleDES(user.UserId.ToString());
                                        var tduser = new UserBLL().GetUserBasicInfoModelById(user.UserId);
                                        if (tduser != null && !string.IsNullOrEmpty(tduser.TelNo))
                                        {
                                            user.Tel = tduser.TelNo;
                                        }
                                        uList.Add(user);
                                    }
                                }
                                uList = uList.Where(o => o.Tel.IsNotEmpty()).ToList();
                                if (uList != null && uList.Count > 0)
                                {
                                    if (uList.Exists(o => o.UserId == WebUserAuth.UserId.Value))
                                    {
                                        firstUser =
                                            uList.Where(o => o.UserId == WebUserAuth.UserId.Value).FirstOrDefault();
                                    }
                                    else
                                    {
                                        firstUser = uList[0];
                                    }
                                }

                                string redisErr = "";
                                RedisServerStack.StringSet(TdConfig.ApplicationName, "/redis/web", openId, uList, ref redisErr);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    TuanDai.LogSystem.LogClient.LogClients.ErrorLog(TdConfig.ApplicationName, "GetWeiXinUserInfo",
                                                                    WebUserAuth.UserId.Value.ToString(), "获取用户微信信息失败");
                    Response.Redirect("my_account.aspx", true);
                    //Response.End();
                }
            }
            else
            {
                Response.Redirect("my_account.aspx", true);
                //Response.End();
            }

            if (wxUserInfo == null)
            {
                wxUserInfo = new ThirdLoginSDK.WXOAuthUser();
            }
        }
Exemplo n.º 14
0
        public void DoMakeWealthGod()
        {
            try
            {
                Response.ContentType = "application/json";
                string nickName  = this.Request.Form["nickName"];
                string base64Img = this.Request.Form["base64Img"];

                string godImagePath = "";
                //上传头像
                bool saveImg = SaveHeadImage(base64Img, ref godImagePath);
                if (!saveImg)
                {
                    PrintJson("-1", "上传头像失败!");
                    return;
                }

                if (DateTime.Now < WealthPage.ActivityStartDate)
                {
                    PrintJson("-3", "您来得太早了,活动还未开始!");
                    return;
                }
                if (DateTime.Now > WealthPage.ActivityEndDate)
                {
                    PrintJson("-3", "您来得太晚了,活动已结束了!");
                    return;
                }


                ThirdLoginSDK sdkApi = new ThirdLoginSDK();
                sdkApi.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
                string OpenId = sdkApi.GetCookieOpenId("");
                if (OpenId.IsEmpty())
                {
                    PrintJson("-2", "微信授权失败,请重试!");
                    return;
                }
                bool isLogin = WebUserAuth.IsAuthenticated;
                Guid?userId  = WebUserAuth.UserId;
//                using (SqlConnection connection = WealthPage.OpenConnection(2))
//                {
//                    string strSQL = " select count(1) as cnt from Activity_GodWealth_Record where WXOpenId=@WXOpenId";
//                    DynamicParameters dyParams = new DynamicParameters();
//                    dyParams.Add("@WXOpenId", OpenId);
//                    int iCount = connection.Query<Int32>(strSQL, dyParams).FirstOrDefault();
//                    if (iCount > 0)
//                    {
//                        PrintJson("-1", "您已做过一回财神!");
//                        return;
//                    }

//                    strSQL = @" insert into Activity_GodWealth_Record(Id,UserId,UserName,WXOpenId,ShowName,GodImage,FriendNum,AddDate,ExpirationDate,GetPrizeDate,IsGetPrize)
//                                values(@Id,@UserId,@UserName,@WXOpenId,@ShowName,@GodImage,@FriendNum,@AddDate,@ExpirationDate,@GetPrizeDate,@IsGetPrize)";
//                    dyParams = new DynamicParameters();
//                    dyParams.Add("@Id", Guid.NewGuid());
//                    dyParams.Add("@UserId", null);
//                    dyParams.Add("@UserName", "");
//                    dyParams.Add("@WXOpenId", OpenId);
//                    dyParams.Add("@ShowName", nickName);
//                    dyParams.Add("@GodImage", godImagePath);
//                    dyParams.Add("@FriendNum", 0);
//                    dyParams.Add("@AddDate", DateTime.Now);
//                    dyParams.Add("@ExpirationDate", DateTime.Today.AddMonths(1));
//                    dyParams.Add("@GetPrizeDate", null);
//                    dyParams.Add("@IsGetPrize", 0);
//                    bool isSuccess = connection.Execute(strSQL, dyParams) > 0;
//                    if (isSuccess)
//                    {
//                        var responseObj = new { result = "1", NickName = nickName, GodImage = godImagePath };
//                        PrintJson(responseObj);
//                        return;
//                    }
//                    else
//                    {
//                        PrintJson("-1", "做财神失败,请重试!");
//                        return;
//                    }
//                }
            }
            catch (Exception ex)
            {
                PrintJson("-1", "做财神失败,请重试!");
                BusinessDll.NetLog.WriteLoginHandler("财神爷活动上传图片出错", Tool.ExceptionHelper.GetExceptionMessage(ex), "触屏版");
            }
            finally {
                Response.End();
            }
        }
Exemplo n.º 15
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack)
            {
                return;
            }

            var code = Tool.WEBRequest.GetQueryString("code");
            var sdk  = new ThirdLoginSDK();

            sdk.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);

            //获取微信上用户信息.
            var wxUserInfo = sdk.GetWXUserSubscribeInfor(code);

            this.awards = this.GetAwardRecords(this.activityCode).ToList();

            this.awards.Add(new PrizeRecord {
                NickName = "Dave", PrizeName = "10元电影折扣券"
            });
            this.awards.Add(new PrizeRecord {
                NickName = "Stuart", PrizeName = "20元电影折扣券"
            });
            this.awards.Add(new PrizeRecord {
                NickName = "Tim", PrizeName = "10元电影折扣券"
            });
            this.awards.Add(new PrizeRecord {
                NickName = "Mark", PrizeName = "3D通兑券"
            });
            this.awards.Add(new PrizeRecord {
                NickName = "Phil", PrizeName = "10元电影折扣券"
            });
            this.awards.Add(new PrizeRecord {
                NickName = "Jerry", PrizeName = "10元电影折扣券"
            });
            this.awards.Add(new PrizeRecord {
                NickName = "Jorge", PrizeName = "20元电影折扣券"
            });
            this.awards.Add(new PrizeRecord {
                NickName = "Kevin", PrizeName = "10元电影折扣券"
            });
            this.awards.Add(new PrizeRecord {
                NickName = "Jon", PrizeName = "10元电影折扣券"
            });
            this.awards.Add(new PrizeRecord {
                NickName = "Bob", PrizeName = "10元电影折扣券"
            });

            this.isSubscribed = wxUserInfo.subscribe;
            this.isLogin      = WebUserAuth.IsAuthenticated ? 1 : 0;
            this.myPrizes     = "无";
            if (this.isLogin == 1)
            {
                var userId = WebUserAuth.UserId.Value;

                var action = this.Request.QueryString["Action"];
                if (action.IsNotEmpty())
                {
                    if (action == "GetPrize")
                    {
                        var result = this.GetPrize(userId);
                        if (result.Success)
                        {
                            var codes     = result.GetParameter <string[]>("Codes");
                            var chances   = result.GetParameter <int>("Chnaces");
                            var type      = result.GetParameter <int>("Type");
                            var prizeName = result.GetParameter <string>("PrizeName");

                            this.PrintJson(new
                            {
                                result.Success,
                                result.Message,
                                Type      = type,
                                PrizeName = prizeName,
                                Codes     = codes,
                                Chances   = chances
                            });
                        }
                        else
                        {
                            this.PrintJson(new { result.Success, result.Message });
                        }
                    }
                }

                var totalChances = this.GetPrizeChances(userId);
                var usedChances  = this.GetUsedChances(userId, this.activityCode);

                this.totalChances = totalChances;
                this.chances      = Math.Max(0, totalChances - usedChances);

                var prizes = this.GetUserPrizes(userId, this.activityCode).ToList();
                if (prizes.Count > 0)
                {
                    if (prizes.Count == 1)
                    {
                        this.myPrizes = prizes[0].PrizeName;
                    }
                    if (prizes.Count == 2)
                    {
                        this.myPrizes = prizes[0].PrizeName + "," + prizes[1].PrizeName;
                    }
                }
                else
                {
                    this.myPrizes = "无";
                }
            }
        }
Exemplo n.º 16
0
        public void GetGodSendRedPacket()
        {
            try
            {
                Response.ContentType = "application/json";
                string ExtendOpenId = WEBRequest.GetFormString("extendkey"); //财神爷OpenId

                if (DateTime.Now < WealthPage.ActivityStartDate)
                {
                    PrintJson("-3", "您来得太早了,活动还未开始!");
                    return;
                }
                if (DateTime.Now > WealthPage.ActivityEndDate)
                {
                    PrintJson("-3", "您来得太晚了,活动已结束了!");
                    return;
                }

                if (ExtendOpenId.IsNotEmpty())
                {
                    if (!WealthPage.CheckGodIsExists(ExtendOpenId))
                    {
                        PrintJson("-3", "对不起,该财神爷不存在!");
                        return;
                    }
                }
                ThirdLoginSDK sdkApi = new ThirdLoginSDK();
                sdkApi.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
                string OpenId = sdkApi.GetCookieOpenId("");

                bool isGetHisPrize = WealthPage.CheckUserHasGetRedPacket(ExtendOpenId, OpenId);
                if (isGetHisPrize)
                {
                    //这里必须要判断自已是否有做过财神,不然没法得到红包
                    WealthPage.GodWealthRecordInfo wealthInfo = WealthPage.GetUserGodWealthInfo(SelfOpenId);
                    if (wealthInfo != null)
                    {
                        PrintJson("-2", "对不起,您已经领过他派的红包!");
                    }
                    else
                    {
                        PrintJson("1", "");
                    }
                    return;
                }
//                using (SqlConnection connection = WealthPage.OpenConnection(2))
//                {
//                    string strSQL = @"insert into Activity_GodWealth_Friend(Id,WXOpenId,FriendOpenId,UserAgent,AddDate)
//                                  values(@Id,@WXOpenId,@FriendOpenId,@UserAgent,@AddDate)";

//                    DynamicParameters dyParams = new DynamicParameters();
//                    dyParams.Add("@Id", Guid.NewGuid());
//                    dyParams.Add("@WXOpenId", ExtendOpenId);
//                    dyParams.Add("@FriendOpenId", OpenId);
//                    //获取用户浏览器信息
//                    string strAgent = "";
//                    strAgent += string.Format("用户IP: {0}\r\n", Tool.WebFormHandler.GetIP());
//                    strAgent += string.Format("用户浏览器: {0}\r\n", HttpContext.Current.Request.UserAgent);
//                    dyParams.Add("@UserAgent", strAgent);
//                    dyParams.Add("@AddDate", DateTime.Now);
//                    int iCount = connection.Execute(strSQL, dyParams);
//                    //领取成功时,更新财神爷派发个数
//                    if (iCount > 0)
//                    {
//                        strSQL = " update Activity_GodWealth_Record set FriendNum=isnull(FriendNum,0)+1 where WXOpenId=@WXOpenId";
//                        dyParams = new DynamicParameters();
//                        dyParams.Add("@WXOpenId", ExtendOpenId);
//                        connection.Execute(strSQL, dyParams);
//                    }
//                }
                PrintJson("1", "");
            }
            catch (Exception ex)
            {
                BusinessDll.NetLog.WriteLoginHandler("财神爷活动上传图片出错", Tool.ExceptionHelper.GetExceptionMessage(ex), "触屏版");
                PrintJson("0", "获取红包失败!");
            }
            finally
            {
                Response.End();
            }
        }
Exemplo n.º 17
0
        //登录后自动领取奖品
        private bool AwardMyPrize(string code)
        {
            ThirdLoginSDK sdkApi = new ThirdLoginSDK();

            sdkApi.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
            string OpenId = sdkApi.GetCookieOpenId(code);

//            using (SqlConnection connection = CelebHelper.OpenConnection(2))
//            {
//                string strSQL = "select * from Activity_ThreeYearGame_Record where WXOpenId=@WXOpenId";
//                DynamicParameters dyParams = new DynamicParameters();
//                dyParams.Add("@WXOpenId", OpenId);
//                GameRecordInfo recordInfo = connection.Query<GameRecordInfo>(strSQL, dyParams).FirstOrDefault();
//                if (recordInfo == null)
//                    return false;
//                //此处先屏蔽掉。因为考滤到之前没有领取红包失败的数据
//                //if (recordInfo.UserId.ToText().IsNotEmpty())
//                //    return true;


//                //非过期时才改为当前用户Id
//                //if (recordInfo.ExpirationDate.HasValue && recordInfo.ExpirationDate > DateTime.Now)
//                //{
//                UserBLL userbll = new UserBLL();
//                UserBasicInfoInfo userInfo = userbll.GetUserBasicInfoModelById(WebUserAuth.UserId.Value);

//                //判断同一个用户ID是否有领取奖品 Allen 2015-07-14
//                strSQL = " SELECT count(1) as cnt FROM Activity_ThreeYearGame_Record  WHERE UserId=@UserId";
//                dyParams = new DynamicParameters();
//                dyParams.Add("@UserId", userInfo.Id);
//                int iCount = connection.Query<Int32>(strSQL, dyParams).Sum();
//                if (iCount > 2)
//                {
//                    return false;
//                }

//                strSQL = @"update Activity_ThreeYearGame_Record set
//                                UserId=@UserId, UserName=@UserName, NickName=@NickName,
//                                ExpirationDate=@ExpirationDate, GetPrizeDate=@GetPrizeDate
//                                where WXOpenId=@WXOpenId";
//                dyParams = new DynamicParameters();
//                dyParams.Add("@WXOpenId", OpenId);
//                dyParams.Add("@UserId", userInfo.Id);
//                dyParams.Add("@UserName", userInfo.UserName);
//                dyParams.Add("@NickName", userInfo.NickName);
//                dyParams.Add("@ExpirationDate", null); //已获取奖品后这里清空
//                dyParams.Add("@GetPrizeDate", DateTime.Now); //领取时间

//                int iSuc = connection.Execute(strSQL, dyParams);

//                if (iSuc > 0)
//                {
//                    //判断团宝箱中有没发放过10元投资红包
//                    bool isSendRedPacket = CelebHelper.CheckInvestRedPrizeIsExists(WebUserAuth.UserId.Value);
//                    if (isSendRedPacket == false)
//                    {
//                        GamePrizeInfo prizeInfo = CelebHelper.GetPrizeInfor("RedPacket");
//                        if (prizeInfo != null)
//                        {
//                            //发送团宝箱
//                            CelebHelper.AddToMyPrize(prizeInfo, WebUserAuth.UserId.Value, false);
//                        }
//                    }
//                }

//                //修改已登录标识
//                strSQL = "update Activity_ThreeYearGame_Friend set IsLogin=1 where  FriendOpenId=@FriendOpenId";
//                dyParams = new DynamicParameters();
//                dyParams.Add("@FriendOpenId", OpenId);
//                connection.Execute(strSQL, dyParams);
//                // }
//            }
            return(true);
        }
Exemplo n.º 18
0
        //领取红包
        private void AwardToGetPrize()
        {
            try
            {
                ThirdLoginSDK sdkApi = new ThirdLoginSDK();
                sdkApi.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
                string OpenId = sdkApi.GetCookieOpenId("");
                Guid   userId = WebUserAuth.UserId.Value;
                //判断为空时不可领取
                if (userId == Guid.Empty || OpenId.ToText().IsEmpty())
                {
                    return;
                }

//                using (SqlConnection connection = WealthPage.OpenConnection(2))
//                {
//                    //判断是否有领取过
//                    string strSQL = "SELECT COUNT(1) AS cnt  FROM Activity_GodWealth_Record   WHERE  IsGetPrize=1 AND (WXOpenId=@WXOpenId OR UserId=@UserId)";
//                    DynamicParameters dyParams = new DynamicParameters();
//                    dyParams.Add("@WXOpenId", OpenId);
//                    dyParams.Add("@UserId", userId);
//                    int iCount = connection.Query<Int32>(strSQL, dyParams).FirstOrDefault();
//                    if (iCount > 0)
//                        return;
//                    //判断奖品是否已发送完毕
//                    WealthPage.ActivityConfigInfo configInfo = WealthPage.GetActivityConfig();
//                    if (configInfo == null || configInfo.UsePrizeNum >= configInfo.TotalPrizeNum)
//                        return;

//                    WealthPage.GodWealthRecordInfo recordInfo = WealthPage.GetUserGodWealthInfo(OpenId);
//                    //非过期时才可领取红包
//                    if (recordInfo.ExpirationDate.HasValue && recordInfo.ExpirationDate > DateTime.Now)
//                    {
//                        UserBLL userbll = new UserBLL();
//                        UserBasicInfoInfo userInfo = userbll.GetUserBasicInfoModelById(userId);
//                        strSQL = @" update Activity_GodWealth_Record set
//                                UserId=@UserId, UserName=@UserName,
//                                ExpirationDate=@ExpirationDate,
//                                GetPrizeDate=@GetPrizeDate, IsGetPrize=@IsGetPrize
//                                where WXOpenId=@WXOpenId";
//                        dyParams = new DynamicParameters();
//                        dyParams.Add("@WXOpenId", OpenId);
//                        dyParams.Add("@UserId", userInfo.Id);
//                        dyParams.Add("@UserName", userInfo.UserName);
//                        dyParams.Add("@ExpirationDate", null); //已获取奖品后这里清空
//                        dyParams.Add("@GetPrizeDate", DateTime.Now); //领取时间
//                        dyParams.Add("@IsGetPrize", 1); //标记已领取

//                        int iSuc = connection.Execute(strSQL, dyParams);
//                        if (iSuc > 0)
//                        {
//                            int outStatus = 0;
//                            SendUserPrizeInfo prizeInfo = new SendUserPrizeInfo();
//                            prizeInfo.UserId = userId;
//                            prizeInfo.PrizeName = "10元投资红包";
//                            prizeInfo.PrizeValue = 10;
//                            //规则: 新用户要投资500元才能使用10元,老用户投资1000元才能使用
//                            if (userInfo.AddDate >= configInfo.ActivityStartDate)
//                            {
//                                prizeInfo.RuleId = Guid.Parse("9dd159c3-712a-4bee-8857-640de08b9a9e");
//                                prizeInfo.Description = "团贷网&财神爷派红包活动-单笔投资满500元即可使用10元,过期时间为:" + DateTime.Today.AddMonths(1).AddDays(-1).ToString("yyyy/MM/dd");
//                            }
//                            else
//                            {
//                                prizeInfo.RuleId = Guid.Parse("918f88a9-f3f7-4687-b239-8db70c4e483b");//规则Id
//                                prizeInfo.Description = "团贷网&财神爷派红包活动-单笔投资满1000元即可使用10元,过期时间为:" + DateTime.Today.AddMonths(1).AddDays(-1).ToString("yyyy/MM/dd");
//                            }
//                            userbll.SendUserPrizeNew(prizeInfo, out  outStatus);
//                            //更新奖品数量
//                            if (outStatus == 1)
//                                WealthPage.UpdateUsedPrizeNum();
//                        }
//                    }
//                }
            }
            catch (Exception ex) {
                BusinessDll.NetLog.WriteLoginHandler("财神爷派红包活动领取奖品失败", ExceptionHelper.GetExceptionMessage(ex), "触屏版");
            }
        }
Exemplo n.º 19
0
        /*
         * 进来时逻辑判断:
         * 1.第一次直接扫码进来时,就显示上传图片界面。
         * 2.第二次扫码进来时,显示自已头像,显示好友个数。
         * 2.从第一位好友分享进来时。显示好友头像,再做相片
         * 3.从第二次好友分享进来时,显示自已头像,再加提示“红包已领取过”
         * 4. 活动已结束时,任何动作进来直接 显示自已头像,显示“活动已结束,感谢参与”
         * 5. 领取奖品结束时,自已进来时,显示“红包已过期”
         */

        private void InitPageData()
        {
            //读取活动的配置信息
            ActivityConfigInfo configInfo = GetActivityConfig();

            if (configInfo != null)
            {
                WealthPage.ActivityStartDate = configInfo.ActivityStartDate;
                WealthPage.ActivityEndDate   = configInfo.ActivityEndDate;
            }

            ThirdLoginSDK sdkApi = new ThirdLoginSDK();

            sdkApi.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
            SelfOpenId = sdkApi.GetCookieOpenId(code);

            WealthPage.GodWealthRecordInfo wealthInfo = WealthPage.GetUserGodWealthInfo(SelfOpenId);
            #region 活动已结束情况
            if (WealthPage.ActivityEndDate <= DateTime.Now)
            {
                this.UserStatus = "1";
                //活动已结束时,这里显示自已的头像,姓名
                this.GetCaiShengInfo(wealthInfo);
                return;
            }
            #endregion

            //判断奖品是否已发送完毕 (前提自已没有当过财神进来时才提示)
            if (configInfo == null || (wealthInfo == null && configInfo.UsePrizeNum >= configInfo.TotalPrizeNum))
            {
                //活动已结束时,这里显示自已的头像,姓名
                wealthInfo = WealthPage.GetUserGodWealthInfo(ExtendKey != "" ? ExtendKey : SelfOpenId);
                this.GetCaiShengInfo(wealthInfo);
                this.UserStatus = "6";
                return;
            }

            //自已直接进来或点自已分享链接时
            if (ExtendKey.IsEmpty() || ExtendKey == SelfOpenId)
            {
                #region 自已做财神
                wealthInfo = WealthPage.GetUserGodWealthInfo(SelfOpenId);
                if (wealthInfo == null)
                {
                    this.UserStatus = "2";
                    return;
                }
                else
                {
                    this.UserStatus = "3";
                    this.GetCaiShengInfo(wealthInfo);
                    RedPackedStatus = CheckRedPacketStatus().ToString();
                }
                #endregion
            }
            else
            {
                #region 好友派发红包时
                WealthPage.GodWealthRecordInfo selfWealthInfo = WealthPage.GetUserGodWealthInfo(SelfOpenId);
                if (selfWealthInfo != null)
                {
                    //第二个好友分享后,点进来判断有领过红包
                    this.GetCaiShengInfo(selfWealthInfo);
                    this.UserStatus = "5";
                }
                else
                {
                    wealthInfo = WealthPage.GetUserGodWealthInfo(ExtendKey);
                    //如果财神爷数据找不到,就跳转
                    if (wealthInfo == null)
                    {
                        Response.Redirect(GlobalUtils.WebURL + "/Activity/GodWealth/AuthorIndex.aspx");
                        return;
                    }
                    this.UserStatus = "4";
                    this.GetCaiShengInfo(wealthInfo);
                }
                #endregion
            }
        }
Exemplo n.º 20
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string type = WEBRequest.GetQueryString("type");
            string code = "";

            switch (type.Trim().ToLower())
            {
            case "":
                string ReturnUrl = WEBRequest.GetQueryString("ReturnUrl");
                code = WEBRequest.GetQueryString("code");
                string goBackUrl = ReturnUrl;
                if (ReturnUrl.IndexOf("?") != -1)
                {
                    goBackUrl += "&code=" + code;
                }
                else
                {
                    goBackUrl += "?code=" + code;
                }

                Response.Redirect(goBackUrl);
                break;

            //获取微细OpenId
            case "getopenid":
                #region
                Response.ContentType = "application/json";
                try
                {
                    code = WEBRequest.GetQueryString("code");
                    ThirdLoginSDK sdkApi = new ThirdLoginSDK();
                    sdkApi.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
                    string wxOpenId = sdkApi.GetCookieOpenId(code);
                    TuanDai.LogSystem.LogClient.LogClients.TraceLog(TdConfig.ApplicationName, "getopenid", "", wxOpenId);
                    this.PrintJson("1", wxOpenId);
                }
                catch (Exception ex)
                {
                    this.PrintJson("-100", "程序异常:" + ex.Message);
                }
                finally
                {
                    Response.End();
                }
                break;

                #endregion
            //获取微信用户信息
            case "getuserinfor":
                #region
                Response.ContentType = "application/json";
                try
                {
                    DateTime beginTime = DateTime.Now;
                    code = WEBRequest.GetQueryString("code");
                    //写入openid 因为code被使用过一次后,就会失效,缓存的openid就取不到。
                    string openId = WEBRequest.GetQueryString("openid");
                    if (openId.IsNotEmpty())
                    {
                        GlobalUtils.WriteOpenIdToCookie(openId);
                    }

                    ThirdLoginSDK sdk = new ThirdLoginSDK();
                    sdk.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
                    //获取微信上用户信息
                    TuanDai.WXApiWeb.Common.ThirdLoginSDK.WXOAuthUser wxUserInfo = sdk.GetWXUserSubscribeInfor(code, openId.ToText());

                    var jsonStr = JsonHelper.ToJson(wxUserInfo);
                    this.PrintJson("1", jsonStr);
                    DateTime endTime = DateTime.Now;

                    LogClients.TraceLog("WXTouch", "微信授权时间差", openId, (endTime - beginTime).TotalMilliseconds.ToString());
                }
                catch (Exception ex)
                {
                    this.PrintJson("-100", "程序异常:" + ex.Message);
                    LogClients.ErrorLog("WXTouch", "微信授权错误", "", ex.Message + ex.StackTrace);
                }
                finally
                {
                    Response.End();
                }
                break;

                #endregion
            //获取Token
            case "getaccesstoken":
                #region
                string token       = WEBRequest.GetQueryString("Token");
                string configToken = ConfigHelper.getConfigString("APIKey");
                Response.ContentType = "application/json";
                try
                {
                    if (configToken != token)
                    {
                        this.PrintJson("99", "验证不通过!");
                        return;
                    }
                    //从同一个缓存中读取全局的Token
                    ThirdLoginSDK sdkApi = new ThirdLoginSDK();
                    sdkApi.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
                    TuanDai.WXApiWeb.Common.ThirdLoginSDK.WXOAuth_Token accessToken = sdkApi.GetWXUserOpenIdByCgi(code);
                    var jsonStr = JsonHelper.ToJson(accessToken);
                    this.PrintJson("1", jsonStr);
                }
                catch (Exception ex)
                {
                    this.PrintJson("-100", "程序异常:" + ex.Message);
                }
                finally
                {
                    Response.End();
                }
                break;

                #endregion
            //App中活动登录
            case "appajaxlogin":
                #region
                Response.ContentType = "application/json";
                try
                {
                    string appActivityToken = WEBRequest.GetFormString("appActivityToken");
                    if (!string.IsNullOrEmpty(appActivityToken))
                    {
                        TuanDai.PortalSystem.Model.UserBasicInfoInfo model = new TuanDai.PortalSystem.BLL.AppUserTokenRecBLL().GetAppActivityUser(appActivityToken);
                        if (model != null)
                        {
                            string DOMAINNAME = ConfigurationManager.AppSettings["CookieDomain"];
                            Tool.CookieHelper.WriteCookie("TDW_WapUserName", model.UserName);
                            string strLastLoginDate = DateTime.Now.ToString("yyyy-MM-dd") + model.UserName;
                            if (string.IsNullOrEmpty(CookieHelper.GetCookie("TDLastLoginDate")) || CookieHelper.GetCookie("TDLastLoginDate") != strLastLoginDate)
                            {
                                TuanDai.PortalSystem.BLL.VipGetWorthBLL.AddGetWorth(model.Id, (int)ConstString.UserGrowthType.EveryDayFirstLogin, null, 0);
                            }

                            Tool.CookieHelper.WriteCookie(DOMAINNAME, "TDLastLoginDate", strLastLoginDate);
                            WebUserAuth.SignIn(model.Id.ToString());
                        }
                        else
                        {
                            WebUserAuth.SignOut();
                        }
                    }
                    this.PrintJson("1", "登录成功!");
                }
                catch (Exception ex)
                {
                    this.PrintJson("-1", ex.Message);
                }
                finally
                {
                    Response.End();
                }
                #endregion
                break;

            //获取用户推送开关设置
            case "getwxpushswitch":
                #region
                token       = WEBRequest.GetQueryString("Token");
                configToken = ConfigHelper.getConfigString("APIKey");
                string pushtype = WEBRequest.GetQueryString("PushType");
                Response.ContentType = "application/json";
                try
                {
                    if (configToken != token)
                    {
                        this.PrintJson("99", "验证不通过!");
                        return;
                    }
                    string strSQL = "SELECT DISTINCT OpenId FROM dbo.UserWXNotice WHERE ISNULL(OpenId,'')!=''";
                    if (pushtype.ToLower() == "wexnotice")
                    {
                        strSQL += " and  IsWeXNotice=1";
                    }
                    else if (pushtype.ToLower() == "actnotice")
                    {
                        strSQL += " and  IsActivityNotice=1";
                    }
                    else
                    {
                        strSQL += " and 1=0";
                    }
                    Dapper.DynamicParameters dyParams   = new Dapper.DynamicParameters();
                    List <string>            OpenIDList = PublicConn.QueryBySql <string>(strSQL, ref dyParams);
                    var jsonStr = JsonHelper.ToJson(OpenIDList);
                    this.PrintJson("1", jsonStr);
                }
                catch (Exception ex)
                {
                    this.PrintJson("-100", "程序异常:" + ex.Message);
                }
                finally
                {
                    Response.End();
                }
                #endregion
                break;
            }
        }
Exemplo n.º 21
0
        public static string SeekMyLover(string base64Img)
        {
            try
            {
                string HeadImage = "";
                //上传头像
                bool saveImg = SaveHeadImage(base64Img, ref HeadImage);
                if (!saveImg)
                {
                    return(PrintJson("-1", "上传头像失败!"));
                }

                Dictionary <string, string> templateDict = GetLoverTemplate();
                int rIndex = rand.Next(templateDict.Count);
                if (rIndex < 1 || rIndex > templateDict.Count)
                {
                    rIndex = 0;
                }
                string seekLover    = templateDict.ElementAt(rIndex).Key;//匹配到的情人
                string seekLoverImg = templateDict.ElementAt(rIndex).Value;

                int    MatchMark  = GetRandomMark();
                int    BeautyMark = GetRandomMark();
                string SelfOpenId = "";
                try
                {
                    ThirdLoginSDK sdkApi = new ThirdLoginSDK();
                    sdkApi.InitSDK(ThirdLoginSDK.ThirdLoginType.WeiXin);
                    SelfOpenId = sdkApi.GetCookieOpenId("");
                }
                catch {
                    SelfOpenId = "";
                }

                //using (SqlConnection connection = new SqlConnection(TuanDai.Config.BaseConfig.ActivityConnectionString))
//                {
//                    string strSQL = @"insert into Activity_SeekLover_Record(Id,UserId,UserName,WXOpenId,HeadImage,MatchMark,BeautyMark,SeekLover,AddDate,UserAgent)
//                                     values(@Id,@UserId,@UserName,@WXOpenId,@HeadImage,@MatchMark,@BeautyMark,@SeekLover,@AddDate,@UserAgent)";

//                    DynamicParameters dyParams = new DynamicParameters();
//                    dyParams.Add("@Id", Guid.NewGuid());

//                    #region 用户数据
//                    if (WebUserAuth.IsAuthenticated)
//                    {
//                        UserBLL userbll = new UserBLL();
//                        UserBasicInfoInfo userInfo = userbll.GetUserBasicInfoModelById(WebUserAuth.UserId.Value);
//                        if (userInfo != null)
//                        {
//                            dyParams.Add("@UserId", userInfo.Id);
//                            dyParams.Add("@UserName", userInfo.UserName);
//                        }
//                        else
//                        {
//                            dyParams.Add("@UserId", null);
//                            dyParams.Add("@UserName", "");
//                        }
//                    }
//                    else
//                    {
//                        dyParams.Add("@UserId", null);
//                        dyParams.Add("@UserName", "");
//                    }
//                    #endregion
//                    dyParams.Add("@WXOpenId", SelfOpenId);
//                    dyParams.Add("@HeadImage", HeadImage);
//                    dyParams.Add("@MatchMark", MatchMark);
//                    dyParams.Add("@BeautyMark", BeautyMark);
//                    dyParams.Add("@SeekLover", seekLover);
//                    dyParams.Add("@AddDate", DateTime.Now);
//                    //获取用户浏览器信息
//                    string strAgent = "";
//                    strAgent += string.Format("用户IP: {0}\r\n", Tool.WebFormHandler.GetIP());
//                    strAgent += string.Format("用户浏览器: {0}\r\n", HttpContext.Current.Request.UserAgent);
//                    dyParams.Add("@UserAgent", strAgent);
//                    int iSuc = connection.Execute(strSQL, dyParams);

//                    if (iSuc > 0)
//                    {
//                        LoverInfo infor = new LoverInfo();
//                        infor.result = "1";
//                        infor.LoverName = seekLover;
//                        infor.LoverImage = seekLoverImg;
//                        infor.HeadImage = HeadImage;
//                        infor.MatchMark = MatchMark;
//                        infor.BeautyMark = BeautyMark;
//                        return PrintJson(infor);
//                    }
//                    else
//                    {
//                        return PrintJson("0", "保存头像失败!");
//                    }
//                }
                return("");
            }
            catch (Exception ex)
            {
                NetLog.WriteLoginHandler("速配情人活动出错", Tool.ExceptionHelper.GetExceptionMessage(ex), "触屏版");
                return(PrintJson("-100", "程序异常"));
            }
        }