private void ShowInfo(int id) { hidid.Value = id.ToString(); Model.wx_ucard_users user = uBll.GetModel(id); txtrealName.Text = user.realName; lblcardNo.Text = user.cardNo; lblopenid.Text = user.openid; //等级 BLL.wx_ucard_udegree degreeBll = new wx_ucard_udegree(); IList <Model.wx_ucard_udegree> degreelist = degreeBll.GetModelList("sid=" + sid); int degreeNum = 0; string jibie = ""; jibie = BLL.wx_ucard_fun.userDegree(id, MyCommFun.Obj2Int(user.ttScore), jibie, out degreeNum); lblDegree.Text = jibie; rblSex.SelectedValue = user.sex == null ? "3" : user.sex.Value.ToString(); txtwxName.Text = user.wxName; txtage.Text = user.age == null?"0":user.age.ToString(); txtttScore.Text = MyCommFun.ObjToStr(user.ttScore); txtqdScore.Text = MyCommFun.ObjToStr(user.qdScore); txtconsumeScore.Text = MyCommFun.ObjToStr(user.consumeScore); txtconsumeMoney.Text = MyCommFun.ObjToStr(user.consumeMoney); txtregTime.Text = MyCommFun.Obj2DateTime(user.regTime).ToString("yyyy-MM-dd HH:mm:ss"); txtendDate.Text = MyCommFun.Obj2DateTime(user.endDate).ToString("yyyy-MM-dd HH:mm:ss"); txtmobile.Text = MyCommFun.ObjToStr(user.mobile); txtaddr.Text = MyCommFun.ObjToStr(user.addr); }
public string appsecret = ""; //公众微信平台下可以找到 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //获取从wxProcess.aspx传递过来的跳转地址reurl string reurl = HttpContext.Current.Session["session_reurl"].ToString(); int wid = int.Parse(HttpContext.Current.Session["session_wid"].ToString()); BLL.wx_userweixin wx = new BLL.wx_userweixin(); Model.wx_userweixin wxModel = wx.GetModel(wid); appid = wxModel.AppId; appsecret = wxModel.AppSecret; string code = ""; if (Request.QueryString["code"] != null && Request.QueryString["code"] != "") { //获取微信回传的code code = Request.QueryString["code"].ToString(); OAuth_Token Model = Get_token(code); //获取token OAuthUser OAuthUser_Model = Get_UserInfo(Model.access_token, Model.openid); if (OAuthUser_Model.openid != null && OAuthUser_Model.openid != "") //已获取得openid及其他信息 { //绑定数据 wx_ucard_users userBLL = new wx_ucard_users(); Model.wx_ucard_users userModel = new XCWeiXin.Model.wx_ucard_users(); bool Isuser = userBLL.getUserExists(OAuthUser_Model.openid); if (Isuser) { userModel = userBLL.GetModel(OAuthUser_Model.openid); } userModel.wid = wid; userModel.openid = OAuthUser_Model.openid; userModel.wxName = OAuthUser_Model.nickname; userModel.sex = OAuthUser_Model.sex; userModel.language = OAuthUser_Model.language; userModel.province = OAuthUser_Model.province; userModel.city = OAuthUser_Model.city; userModel.country = OAuthUser_Model.country; userModel.headimgul = OAuthUser_Model.headimgurl; userModel.subscribe = OAuthUser_Model.subscribe; // userModel.subscribe_time =DateTime.Parse(OAuthUser_Model.subscribe_time.Trim()); userModel.groupid = OAuthUser_Model.groupid; if (!Isuser)//没有记录,添加 { HttpCookie cookie = new HttpCookie("xcopenid"); cookie.Value = OAuthUser_Model.openid; cookie.Expires = DateTime.Now.AddDays(3650); HttpContext.Current.Response.Cookies.Add(cookie); userBLL.Add(userModel); } else//有记录更新 { HttpCookie cookie = new HttpCookie("xcopenid"); cookie.Value = OAuthUser_Model.openid; cookie.Expires = DateTime.Now.AddDays(3650); HttpContext.Current.Response.Cookies.Add(cookie); ; userBLL.Update(userModel); } Response.Redirect("" + reurl + "&openid=" + OAuthUser_Model.openid + ""); // Response.Redirect(reurl); } else //未获得openid,回到wxProcess.aspx,访问弹出微信授权页面,提示用户授权 { Response.Redirect("wxProcess.aspx?auth=1"); } } } }
public int init() { BLL.wx_userweixin wx = new BLL.wx_userweixin(); Model.wx_userweixin wxModel = wx.GetModel(wid); appid = wxModel.AppId; appsecret = wxModel.AppSecret; string code = ""; if (Request.QueryString["code"] != null && Request.QueryString["code"] != "") { //获取微信回传的code code = Request.QueryString["code"].ToString(); OAuth_Token Model = Get_token(code); //获取token OAuthUser OAuthUser_Model = Get_UserInfo(Model.access_token, Model.openid); if (OAuthUser_Model.openid != null && OAuthUser_Model.openid != "") //已获取得openid及其他信息 { //绑定数据 wx_ucard_users userBLL = new wx_ucard_users(); Model.wx_ucard_users userModel = new XCWeiXin.Model.wx_ucard_users(); bool Isuser = userBLL.getUserExists(OAuthUser_Model.openid); if (Isuser) { userModel = userBLL.GetModel(OAuthUser_Model.openid); } userModel.wid = wid; userModel.openid = OAuthUser_Model.openid; userModel.wxName = OAuthUser_Model.nickname; userModel.sex = OAuthUser_Model.sex; userModel.language = OAuthUser_Model.language; userModel.province = OAuthUser_Model.province; userModel.city = OAuthUser_Model.city; userModel.country = OAuthUser_Model.country; userModel.headimgul = OAuthUser_Model.headimgurl; userModel.subscribe = OAuthUser_Model.subscribe; // userModel.subscribe_time =DateTime.Parse(OAuthUser_Model.subscribe_time.Trim()); userModel.groupid = OAuthUser_Model.groupid; openid = OAuthUser_Model.openid; if (!Isuser)//没有记录,添加 { HttpCookie cookie = new HttpCookie("xcopenid" + wid + ""); cookie.Value = OAuthUser_Model.openid; cookie.Expires = DateTime.Now.AddDays(3650); HttpContext.Current.Response.Cookies.Add(cookie); userBLL.Add(userModel); return(0); } else//有记录更新 { HttpCookie cookie = new HttpCookie("xcopenid" + wid + ""); cookie.Value = OAuthUser_Model.openid; cookie.Expires = DateTime.Now.AddDays(3650); HttpContext.Current.Response.Cookies.Add(cookie); userBLL.Update(userModel); return(0); } // Response.Redirect("" + reurl + "&openid=" + OAuthUser_Model.openid + ""); // Response.Redirect(reurl); } else //未获得openid,回到wxProcess.aspx,访问弹出微信授权页面,提示用户授权 { return(1); } } else //取code失败 { return(2); } }