/// <summary> /// 直接更新本地数据库中账号 /// </summary> public static WX_User GetUserInfoByOpenidWithUpdateLocal(string openid, OAuthAccessTokenResult _accresstoken, string _code) { UserInfoJson u = GetUserInfoByOpenid(openid); WX_User wxuser = new WX_User(); if (u != null && u.errmsg == null)//有用户信息返回 { wxuser = new WX_UserB().GetEntity(d => d.Openid == u.openid); return(UpdateLocalUserInfo(u, _accresstoken, _code)); } return(wxuser); }
public void GETUSERINFOBYOPENID(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo) { string _openid = CommonHelp.GetCookieString("openid"); WX_User u = new WX_UserB().GetEntity(d => d.Openid == _openid); if (u != null) { JH_Auth_User localuser = new JH_Auth_UserB().GetEntity(d => d.WXopenid == _openid && d.IsWX == 1); if (localuser != null) { msg.Result = localuser; } } }
/// <summary> /// 粉丝列表分页 /// </summary> public void GETFSLIST_PAGE(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo) { string strWhere = " 1=1 "; if (P1 != "") { strWhere += string.Format(" and wu.Nickname like '%{0}%'", P1); } string colNme = @"wu.*, u.UserRealName, u.IsWX, u.mobphone, u.IDCard, u.ToMonoLicense "; string tableName = string.Format(@" WX_User wu left join JH_Auth_User u on wu.Openid=u.WXOpenid "); int page = 0; int pagecount = 10; int.TryParse(context.Request["p"] ?? "1", out page); int.TryParse(context.Request["pagecount"] ?? "10", out pagecount);//页数 page = page == 0 ? 1 : page; int total = 0; DataTable dt = new WX_UserB().GetDataPager(tableName, colNme, pagecount, page, " wu.CRDate desc", strWhere, ref total); msg.Result = dt; msg.Result1 = total; }
/// <summary> /// 更新本地数据库中微信用户信息 /// </summary> public static WX_User UpdateLocalUserInfo(UserInfoJson u, OAuthAccessTokenResult _accresstoken, string _code) { string _accesstokenstr = ""; int _expires_in = 0; string _refreshtokenstr = ""; string _scopestr = ""; if (_accresstoken != null && _accresstoken.errmsg == null) { _accesstokenstr = _accresstoken.access_token; _expires_in = _accresstoken.expires_in; _refreshtokenstr = _accresstoken.refresh_token; _scopestr = _accresstoken.scope; } WX_User wxuser = new WX_UserB().GetEntity(d => d.Openid == u.openid); if (wxuser == null) { wxuser = new WX_User(); wxuser.Openid = u.openid; wxuser.Nickname = u.nickname; wxuser.Sex = u.sex == 1 ? "男" : (u.sex == 2 ? "女" : "未知"); wxuser.Province = u.province; wxuser.City = u.city; wxuser.Country = u.country; wxuser.HeadImgUrl = u.headimgurl; wxuser.Code = _code; wxuser.Access_token = _accesstokenstr; wxuser.Expires_in = _expires_in; wxuser.Refresh_token = _refreshtokenstr; wxuser.Scope = _scopestr; wxuser.CRDate = DateTime.Now; wxuser.LastLoginDate = DateTime.Now; wxuser.AuthUserID = 0; new WX_UserB().Insert(wxuser); } else { wxuser.Nickname = u.nickname; wxuser.Sex = u.sex == 1 ? "男" : (u.sex == 2 ? "女" : "未知"); wxuser.Province = u.province; wxuser.City = u.city; wxuser.Country = u.country; wxuser.HeadImgUrl = u.headimgurl; wxuser.Code = _code; wxuser.Access_token = _accesstokenstr; wxuser.Expires_in = _expires_in; wxuser.Refresh_token = _refreshtokenstr; wxuser.Scope = _scopestr; wxuser.LastLoginDate = DateTime.Now; new WX_UserB().Update(wxuser); } return(wxuser); //JH_Auth_User localuser = new JH_Auth_UserB().GetEntity(d => d.WXopenid == u.openid && d.IsWX == 1); //if (localuser == null) //{ // localuser = new JH_Auth_User(); // localuser.UserName = "******" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 16); // //新用户名随机生成 // localuser.UserRealName = u.nickname; // localuser.UserPass = CommonHelp.GetMD5("a123456"); // localuser.pccode= EncrpytHelper.Encrypt(localuser.UserName + "@" + localuser.UserPass + "@" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")); // localuser.ComId = 10334; // localuser.Sex = u.sex == 1 ? "男" : (u.sex == 2 ? "女" : "未知"); // localuser.BranchCode = 0; // localuser.CRDate = DateTime.Now; // localuser.CRUser = "******"; // localuser.logindate = DateTime.Now; // localuser.IsUse = "Y"; // localuser.IsWX = 1; // localuser.WXopenid = u.openid; // new JH_Auth_UserB().Insert(localuser); //} //else //{ // //localuser.pccode = EncrpytHelper.Encrypt(localuser.UserName + "@" + localuser.UserPass + "@" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")); // localuser.logindate = DateTime.Now; // new JH_Auth_UserB().Update(localuser);//更新logindate pccode不能更新 //} }
/// <summary> /// 绑定手机、姓名、身份证、专卖许可证 /// </summary> public void BINDTOMONOLICENSE(HttpContext context, Msg_Result msg, string P1, string P2, JH_Auth_UserB.UserInfo UserInfo) { JH_Auth_User j = JsonConvert.DeserializeObject <JH_Auth_User>(P1); if (j == null) { msg.ErrorMsg = "绑定失败"; return; } if (string.IsNullOrWhiteSpace(j.UserRealName.Trim())) { msg.ErrorMsg = "姓名不能为空"; return; } if (string.IsNullOrWhiteSpace(j.mobphone.Trim())) { msg.ErrorMsg = "手机号不能为空"; return; } if (string.IsNullOrWhiteSpace(j.IDCard.Trim())) { msg.ErrorMsg = "身份证号不能为空"; return; } if (string.IsNullOrWhiteSpace(j.ToMonoLicense.Trim())) { msg.ErrorMsg = "专卖许可证号不能为空"; return; } string _openid = CommonHelp.GetCookieString("openid"); WX_User u = new WX_UserB().GetEntity(d => d.Openid == _openid); msg.Result = u; if (u != null) { JH_Auth_User localuser = new JH_Auth_UserB().GetEntity(d => d.mobphone == j.mobphone.Trim()); if (localuser == null) { new JH_Auth_UserB().ExsSql("update JH_Auth_User set WXopenid='', IsWX=0, IDCard='',ToMonoLicense='' where WXopenid='" + _openid + "'");//清除以前绑定的用户 //新用户,随机生成 localuser = new JH_Auth_User(); localuser.UserName = "******" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 16); localuser.UserRealName = j.UserRealName.Trim(); localuser.UserPass = CommonHelp.GetMD5("a123456"); localuser.pccode = EncrpytHelper.Encrypt(localuser.UserName + "@" + localuser.UserPass + "@" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")); localuser.ComId = 10334; localuser.Sex = u.Sex; localuser.mobphone = j.mobphone.Trim(); localuser.BranchCode = 0; localuser.CRDate = localuser.logindate = DateTime.Now; localuser.CRUser = "******"; localuser.IsUse = "Y"; localuser.IsWX = 1; localuser.WXopenid = _openid; localuser.weixinCard = j.weixinCard.Trim(); localuser.IDCard = j.IDCard.Trim(); localuser.ToMonoLicense = j.ToMonoLicense.Trim(); new JH_Auth_UserB().Insert(localuser); WXFWHelp.UpdateCookieAfterSignIn(localuser); msg.Result = localuser; //msg.ErrorMsg = "手机号不存在,请联系管理员"; return; } else { //老用户 if (localuser.UserRealName == j.UserRealName.Trim()) { new JH_Auth_UserB().ExsSql("update JH_Auth_User set WXopenid='', IsWX=0, IDCard='',ToMonoLicense='' where WXopenid='" + _openid + "'");//清除以前绑定的用户 localuser.WXopenid = _openid; localuser.IsWX = 1; localuser.weixinCard = j.weixinCard.Trim(); //localuser.pccode = EncrpytHelper.Encrypt(localuser.UserName + "@" + localuser.UserPass + "@" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")); localuser.logindate = DateTime.Now; localuser.IDCard = j.IDCard.Trim(); localuser.ToMonoLicense = j.ToMonoLicense.Trim(); new JH_Auth_UserB().Update(localuser);//更新logindate,pccode不能更新 WXFWHelp.UpdateCookieAfterSignIn(localuser); msg.Result = localuser; } else { msg.ErrorMsg = "姓名与手机号不匹配"; return; } } } else { msg.ErrorMsg = "微信登录异常"; return; } }