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 = "我是团粉"; } }
/// <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); }
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(); } }
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 = "无"; } } }
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; } }