/// <summary> /// 向数据表wx_OpenInfo更新一条记录。带事务 /// </summary> /// <param name="sp">事务对象</param> /// <param name="_wx_OpenInfoModel">_wx_OpenInfoModel</param> /// <returns>影响的行数</returns> public int Update(SqlTransaction sp, wx_OpenInfoEntity _wx_OpenInfoModel) { string sqlStr = "update wx_OpenInfo set [access_token]=@access_token,[expires_in]=@expires_in,[refresh_token]=@refresh_token,[openid]=@openid,[scope]=@scope,[AddTime]=@AddTime,[UpdateTime]=@UpdateTime where Id=@Id"; SqlParameter[] _param = { new SqlParameter("@Id", SqlDbType.Int), new SqlParameter("@access_token", SqlDbType.VarChar), new SqlParameter("@expires_in", SqlDbType.Int), new SqlParameter("@refresh_token", SqlDbType.VarChar), new SqlParameter("@openid", SqlDbType.VarChar), new SqlParameter("@scope", SqlDbType.VarChar), new SqlParameter("@AddTime", SqlDbType.DateTime), new SqlParameter("@UpdateTime", SqlDbType.DateTime) }; _param[0].Value = _wx_OpenInfoModel.Id; _param[1].Value = _wx_OpenInfoModel.access_token; _param[2].Value = _wx_OpenInfoModel.expires_in; _param[3].Value = _wx_OpenInfoModel.refresh_token; _param[4].Value = _wx_OpenInfoModel.openid; _param[5].Value = _wx_OpenInfoModel.scope; _param[6].Value = _wx_OpenInfoModel.AddTime; _param[7].Value = _wx_OpenInfoModel.UpdateTime; return(SqlHelper.ExecuteNonQuery(sp, CommandType.Text, sqlStr, _param)); }
/// <summary> /// 向数据库中插入一条新记录。带事务 /// </summary> /// <param name="sp">事务对象</param> /// <param name="_wx_OpenInfoModel">wx_OpenInfo实体</param> /// <returns>新插入记录的编号</returns> public int Insert(SqlTransaction sp, wx_OpenInfoEntity _wx_OpenInfoModel) { string sqlStr = "insert into wx_OpenInfo([access_token],[expires_in],[refresh_token],[openid],[scope],[AddTime],[UpdateTime]) values(@access_token,@expires_in,@refresh_token,@openid,@scope,@AddTime,@UpdateTime) select @@identity"; int res; SqlParameter[] _param = { new SqlParameter("@access_token", SqlDbType.VarChar), new SqlParameter("@expires_in", SqlDbType.Int), new SqlParameter("@refresh_token", SqlDbType.VarChar), new SqlParameter("@openid", SqlDbType.VarChar), new SqlParameter("@scope", SqlDbType.VarChar), new SqlParameter("@AddTime", SqlDbType.DateTime), new SqlParameter("@UpdateTime", SqlDbType.DateTime) }; _param[0].Value = _wx_OpenInfoModel.access_token; _param[1].Value = _wx_OpenInfoModel.expires_in; _param[2].Value = _wx_OpenInfoModel.refresh_token; _param[3].Value = _wx_OpenInfoModel.openid; _param[4].Value = _wx_OpenInfoModel.scope; _param[5].Value = _wx_OpenInfoModel.AddTime; _param[6].Value = _wx_OpenInfoModel.UpdateTime; res = Convert.ToInt32(SqlHelper.ExecuteScalar(sp, CommandType.Text, sqlStr, _param)); return(res); }
/// <summary> /// 得到 wx_openinfo 数据实体 /// </summary> /// <param name="dr">dr</param> /// <returns>wx_openinfo 数据实体</returns> public wx_OpenInfoEntity Populate_wx_OpenInfoEntity_FromDr(IDataReader dr) { wx_OpenInfoEntity Obj = new wx_OpenInfoEntity(); Obj.Id = ((dr["Id"]) == DBNull.Value)?0:Convert.ToInt32(dr["Id"]); Obj.access_token = dr["access_token"].ToString(); Obj.expires_in = ((dr["expires_in"]) == DBNull.Value)?0:Convert.ToInt32(dr["expires_in"]); Obj.refresh_token = dr["refresh_token"].ToString(); Obj.openid = dr["openid"].ToString(); Obj.scope = dr["scope"].ToString(); Obj.AddTime = ((dr["AddTime"]) == DBNull.Value)?Convert.ToDateTime("1900-1-1"):Convert.ToDateTime(dr["AddTime"]); Obj.UpdateTime = ((dr["UpdateTime"]) == DBNull.Value)?Convert.ToDateTime("1900-1-1"):Convert.ToDateTime(dr["UpdateTime"]); return(Obj); }
/// <summary> /// 根据ID,返回一个wx_OpenInfo对象 /// </summary> /// <param name="id">id</param> /// <returns>wx_OpenInfo对象</returns> public wx_OpenInfoEntity Get_wx_OpenInfoEntity(int id) { wx_OpenInfoEntity _obj = null; SqlParameter[] _param = { new SqlParameter("@Id", SqlDbType.Int) }; _param[0].Value = id; string sqlStr = "select * from wx_OpenInfo with(nolock) where Id=@Id"; using (SqlDataReader dr = SqlHelper.ExecuteReader(WebConfig.WfxRW, CommandType.Text, sqlStr, _param)) { while (dr.Read()) { _obj = Populate_wx_OpenInfoEntity_FromDr(dr); } } return(_obj); }
/// <summary> /// 得到 wx_openinfo 数据实体 /// </summary> /// <param name="row">row</param> /// <returns>wx_openinfo 数据实体</returns> public wx_OpenInfoEntity Populate_wx_OpenInfoEntity_FromDr(DataRow row) { wx_OpenInfoEntity Obj = new wx_OpenInfoEntity(); if (row != null) { Obj.Id = ((row["Id"]) == DBNull.Value)?0:Convert.ToInt32(row["Id"]); Obj.access_token = row["access_token"].ToString(); Obj.expires_in = ((row["expires_in"]) == DBNull.Value)?0:Convert.ToInt32(row["expires_in"]); Obj.refresh_token = row["refresh_token"].ToString(); Obj.openid = row["openid"].ToString(); Obj.scope = row["scope"].ToString(); Obj.AddTime = ((row["AddTime"]) == DBNull.Value)?Convert.ToDateTime("1900-1-1"):Convert.ToDateTime(row["AddTime"]); Obj.UpdateTime = ((row["UpdateTime"]) == DBNull.Value)?Convert.ToDateTime("1900-1-1"):Convert.ToDateTime(row["UpdateTime"]); } else { return(null); } return(Obj); }
protected override void OnInit(EventArgs e) { shopid = int.Parse(Jnwf.Utils.Config.ConfigurationUtil.GetAppSettingValue("shopid")); appid = Jnwf.Utils.Config.ConfigurationUtil.GetAppSettingValue("appid"); secret = Jnwf.Utils.Config.ConfigurationUtil.GetAppSettingValue("secret"); weixincode = Jnwf.Utils.Config.ConfigurationUtil.GetAppSettingValue("weixincode"); //检查cookie string ticket = ""; string disney = CookieHelper.GetCookieValue("disney"); if (!string.IsNullOrEmpty(disney)) { jinru = "cookie"; ticket = Jnwf.Utils.Helper.DESEncrypt.Decrypt(disney); this.OnBasePage1OpenInfoLoad(ticket); } else if (!string.IsNullOrEmpty(Code)) { jinru = "code"; string url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + secret + "&code=" + Code + "&grant_type=authorization_code"; string json = Jnwf.Utils.Helper.HttpHelper.LoadPageContent(url); if (json.IndexOf("errcode") >= 0) { Jnwf.Utils.Log.Logger.Log4Net.Error("Results.aspx:" + json); } else { wx_OpenInfoEntity info = Jnwf.Utils.Json.JsonHelper.DeserializeJson <wx_OpenInfoEntity>(json); CookieHelper.SetCookie("disney", Jnwf.Utils.Helper.DESEncrypt.Encrypt(info.openid)); this.OnBasePage1OpenInfoLoad(info.openid); } } else { jinru = "url"; //string host = this.Request.Url.Host; //string path = this.Request.Path; //string redirect_uri = HttpUtility.UrlEncode("http://" + host + path); string redirect_uri = HttpUtility.UrlEncode(this.Request.Url.ToString()); Dictionary <string, string> data = new Dictionary <string, string>(); data.Add("appid", appid); data.Add("redirect_uri", redirect_uri); data.Add("response_type", "code"); data.Add("scope", "snsapi_base"); string temp_url = "https://open.weixin.qq.com/connect/oauth2/authorize?"; foreach (var dic in data) { temp_url += dic.Key + "=" + dic.Value + "&"; } //Jnwf.Utils.Log.Logger.Log4Net.Error("detail:" + temp_url); try { //触发微信返回code码 this.Response.Redirect(temp_url.TrimEnd('&'));//Redirect函数会抛出ThreadAbortException异常,不用处理这个异常 } catch (System.Threading.ThreadAbortException ex) { } } base.OnInit(e); }
protected override void OnInit(EventArgs e) { shopid = int.Parse(Jnwf.Utils.Config.ConfigurationUtil.GetAppSettingValue("shopid")); appid = Jnwf.Utils.Config.ConfigurationUtil.GetAppSettingValue("appid"); secret = Jnwf.Utils.Config.ConfigurationUtil.GetAppSettingValue("secret"); weixincode = Jnwf.Utils.Config.ConfigurationUtil.GetAppSettingValue("weixincode"); sitepath = Jnwf.Utils.Config.ConfigurationUtil.GetAppSettingValue("sitepath"); tb_UsersEntity user = null; Jnwf.Model.tb_App_UserEntity app_user = null; //检查cookie string ticket = ""; string disney = CookieHelper.GetCookieValue("disney"); if (!string.IsNullOrEmpty(disney)) { jinru = "cookie"; Jnwf.Utils.Log.Logger.Log4Net.Error("BasePage,jinru:" + jinru); ticket = Jnwf.Utils.Helper.DESEncrypt.Decrypt(disney); //Jnwf.Utils.Log.Logger.Log4Net.Error("basepage,cookie:" + ticket); user = AutoRepair.BLL.tb_UsersBLL.GetInstance().GetModelByOpenId(ticket); app_user = Jnwf.BLL.tb_App_UserBLL.GetInstance().GetModelByOpenId(ticket); if (app_user == null) { try { Response.Redirect("http://mp.weixin.qq.com/s?__biz=MzI4MzE0ODM1Nw==&mid=402172802&idx=1&sn=c66fe86ffd6b8c8cb73bd3033c1d2903#rd"); } catch (System.Threading.ThreadAbortException ex) { } } else if (user == null) { try { Response.Redirect(sitepath + "Registered.aspx"); } catch (System.Threading.ThreadAbortException ex) { } } else { this.OnBasePageLoad(user); } } else if (!string.IsNullOrEmpty(Code)) { jinru = "code"; Jnwf.Utils.Log.Logger.Log4Net.Error("BasePage,jinru:" + jinru); string url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + secret + "&code=" + Code + "&grant_type=authorization_code"; string json = Jnwf.Utils.Helper.HttpHelper.LoadPageContent(url); if (json.IndexOf("errcode") >= 0) { Jnwf.Utils.Log.Logger.Log4Net.Error("Results.aspx:" + json); } else { wx_OpenInfoEntity info = Jnwf.Utils.Json.JsonHelper.DeserializeJson <wx_OpenInfoEntity>(json); string str = info.openid; //Jnwf.Utils.Log.Logger.Log4Net.Error("basepage,code:" + str); CookieHelper.SetCookie("disney", Jnwf.Utils.Helper.DESEncrypt.Encrypt(str)); user = AutoRepair.BLL.tb_UsersBLL.GetInstance().GetModelByOpenId(info.openid); app_user = Jnwf.BLL.tb_App_UserBLL.GetInstance().GetModelByOpenId(info.openid); if (app_user == null) { try { Response.Redirect("http://mp.weixin.qq.com/s?__biz=MzI4MzE0ODM1Nw==&mid=402172802&idx=1&sn=c66fe86ffd6b8c8cb73bd3033c1d2903#rd"); } catch (System.Threading.ThreadAbortException ex) { } } else if (user == null) { try { Response.Redirect(sitepath + "Registered.aspx"); } catch (System.Threading.ThreadAbortException ex) { } } else { this.OnBasePageLoad(user); } } } else { jinru = "url"; Jnwf.Utils.Log.Logger.Log4Net.Error("BasePage,jinru:" + jinru); //string host = this.Request.Url.Host; //string path = this.Request.Path; //string redirect_uri = HttpUtility.UrlEncode("http://" + host + path); string redirect_uri = HttpUtility.UrlEncode(this.Request.Url.ToString()); Dictionary <string, string> data = new Dictionary <string, string>(); data.Add("appid", appid); data.Add("redirect_uri", redirect_uri); data.Add("response_type", "code"); data.Add("scope", "snsapi_base"); string temp_url = "https://open.weixin.qq.com/connect/oauth2/authorize?"; foreach (var dic in data) { temp_url += dic.Key + "=" + dic.Value + "&"; } //Jnwf.Utils.Log.Logger.Log4Net.Error("detail:" + temp_url); try { //触发微信返回code码 this.Response.Redirect(temp_url.TrimEnd('&'));//Redirect函数会抛出ThreadAbortException异常,不用处理这个异常 } catch (System.Threading.ThreadAbortException ex) { } } base.OnInit(e); }
public void Update(wx_OpenInfoEntity wx_OpenInfoEntity) { wx_OpenInfodal.Update(wx_OpenInfoEntity); }
public int Insert(wx_OpenInfoEntity wx_OpenInfoEntity) { return(wx_OpenInfodal.Insert(wx_OpenInfoEntity)); }