public static string getwxCode(string code, string httpUrl) { string result = "123"; string xtopenid = ""; Cms.BLL.wx_info info = new Cms.BLL.wx_info(); string appid = info.GetModel(1).AppId; string appsecret = info.GetModel(1).AppSecret; if (code != null && code != "") { string Code = code; string Str = GetJson("https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + appsecret + "&code=" + Code + "&grant_type=authorization_code"); //微信回传的数据为Json格式,将Json格式转化成对象 OAuth_Token Model = wxuser.JSONToObject <OAuth_Token>(Str); xtopenid = Model._openid; result = Model._openid + code; Cms.BLL.wx_info wxinfo = new Cms.BLL.wx_info(); Cms.Model.wx_info Model_info = new Cms.Model.wx_info(); Cms.BLL.wx_userinfo userinfo = new Cms.BLL.wx_userinfo(); Cms.Model.wx_userinfo muserinfo = new Cms.Model.wx_userinfo(); Model_info = wxinfo.GetModel(1); string str = ""; string openid = Model._openid; str = setinfo("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + Model.access_token + "&openid=" + openid, "", openid); muserinfo = JSONToObject <Cms.Model.wx_userinfo>(str); Cms.Model.wx_userinfo wxs = new Cms.Model.wx_userinfo(); wxs.subscribe = muserinfo.subscribe; wxs.openid = muserinfo.openid; wxs.nickname = muserinfo.nickname; wxs.sex = muserinfo.sex; wxs.language = muserinfo.language; wxs.city = muserinfo.city; wxs.province = muserinfo.province; wxs.country = muserinfo.country; wxs.headimgurl = muserinfo.headimgurl; wxs.subscribe_time = muserinfo.subscribe_time; wxs.remark = muserinfo.remark; wxs.updatetime = DateTime.Now; if (!Cms.DBUtility.DbHelperSQL.Exists("select count(1) from wx_userinfo where openid='" + muserinfo.openid + "'")) { if (wxs.openid != "") { userinfo.Add(wxs); } } else { Cms.DBUtility.DbHelperSQL.ExecuteSql("update wx_userinfo set updatetime='" + DateTime.Now + "' where openid='" + muserinfo.openid + "'"); } } return(result); }
public static Cms.Model.wx_userinfo getwxCode(string code, string httpUrl) { Cms.Model.wx_info wxInfo = new Cms.BLL.wx_info().GetModel(1); Cms.BLL.wx_userinfo userinfo = new Cms.BLL.wx_userinfo(); Cms.Model.wx_userinfo muserinfo = new Cms.Model.wx_userinfo(); if (code != null && code != "") { string strOpenId = GetJson("https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + wxInfo.AppId + "&secret=" + wxInfo.AppSecret + "&code=" + code + "&grant_type=authorization_code"); //微信回传的数据为Json格式,将Json格式转化成对象 OAuth_Token oAuth_Token = wxuser.JSONToObject <OAuth_Token>(strOpenId); string strInfo = GetJson("https://api.weixin.qq.com/sns/userinfo?access_token=" + oAuth_Token.access_token + "&openid=" + oAuth_Token.openid + "&lang=zh_CN"); wxuserinfo Wxuserinfo = wxuser.JSONToObject <wxuserinfo>(strInfo); muserinfo.subscribe = Wxuserinfo.subscribe; muserinfo.openid = Wxuserinfo.openid; muserinfo.nickname = Wxuserinfo.nickname; muserinfo.sex = Wxuserinfo.sex; muserinfo.language = Wxuserinfo.language; muserinfo.city = Wxuserinfo.city; muserinfo.province = Wxuserinfo.province; muserinfo.country = Wxuserinfo.country; muserinfo.headimgurl = Wxuserinfo.headimgurl; muserinfo.subscribe_time = Wxuserinfo.subscribe_time; muserinfo.remark = Wxuserinfo.remark; muserinfo.updatetime = DateTime.Now; //string str = setinfo("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + Model_info.access_token + "&openid=" + openid, "", openid); if (!Cms.DBUtility.DbHelperSQL.Exists("select count(1) from wx_userinfo where openid='" + muserinfo.openid + "'")) { if (muserinfo.openid != "") { setlog("添加访问信息", oAuth_Token.openid); userinfo.Add(muserinfo); } else { DataTable dtUserInfo = new Cms.BLL.wx_userinfo().GetList("openid='" + muserinfo.openid + "' order by updatetime desc").Tables[0]; if (dtUserInfo != null && dtUserInfo.Rows.Count > 0) { muserinfo.id = int.Parse(dtUserInfo.Rows[0]["id"].ToString()); userinfo.Update(muserinfo); } } } else { DataTable dtUserInfo = new Cms.BLL.wx_userinfo().GetList("openid='" + muserinfo.openid + "' order by updatetime desc").Tables[0]; if (dtUserInfo != null && dtUserInfo.Rows.Count > 0) { muserinfo.id = int.Parse(dtUserInfo.Rows[0]["id"].ToString()); userinfo.Update(muserinfo); } } } return(muserinfo); }
public static string getUser_info(string poststr) { string result = "123"; try { wxuser.setstatistics("", "微信消息", poststr, 1, 1); string res = ""; if (poststr != null) { wxmessage wx = new wxmessage(); XmlDocument xml = new XmlDocument(); xml.LoadXml(poststr); XmlElement root = xml.DocumentElement; wx.ToUserName = root.SelectSingleNode("ToUserName").InnerText; wx.FromUserName = root.SelectSingleNode("FromUserName").InnerText; wx.MsgType = root.SelectSingleNode("MsgType").InnerText; if (wx.MsgType.Trim() == "text") { wx.Content = root.SelectSingleNode("Content").InnerText; } if (wx.MsgType.Trim() == "event") { wx.EventName = root.SelectSingleNode("Event").InnerText; wx.EventKey = root.SelectSingleNode("EventKey").InnerText; } if (wx.MsgType.Trim() == "voice") { wx.Recognition = root.SelectSingleNode("Recognition").InnerText; } Cms.BLL.wx_info wxinfo = new Cms.BLL.wx_info(); Cms.Model.wx_info Model = new Cms.Model.wx_info(); Cms.BLL.wx_userinfo userinfo = new Cms.BLL.wx_userinfo(); Cms.Model.wx_userinfo muserinfo = new Cms.Model.wx_userinfo(); Model = wxinfo.GetModel(1); string str = ""; string openid = wx.FromUserName; str = setinfo("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + Model.access_token + "&openid=" + openid, "", openid); muserinfo = JSONToObject <Cms.Model.wx_userinfo>(str); Cms.Model.wx_userinfo wxs = new Cms.Model.wx_userinfo(); wxs.subscribe = muserinfo.subscribe; wxs.openid = muserinfo.openid; wxs.nickname = muserinfo.nickname; wxs.sex = muserinfo.sex; wxs.language = muserinfo.language; wxs.city = muserinfo.city; wxs.province = muserinfo.province; wxs.country = muserinfo.country; wxs.headimgurl = muserinfo.headimgurl; wxs.subscribe_time = muserinfo.subscribe_time; wxs.remark = muserinfo.remark; wxs.updatetime = DateTime.Now; if (!Cms.DBUtility.DbHelperSQL.Exists("select count(1) from wx_userinfo where openid='" + muserinfo.openid + "'")) { if (muserinfo.openid != "") { userinfo.Add(wxs); } } else { Cms.DBUtility.DbHelperSQL.ExecuteSql("update wx_userinfo set updatetime='" + DateTime.Now + "' where openid='" + muserinfo.openid + "'"); } wxuser.setstatistics("", "", "", 3, 1); result = muserinfo.openid; } HttpContext.Current.Response.ContentType = "text/xml"; HttpContext.Current.Response.Write(res); } catch (Exception ex) { setlog(ex.Message, "错误1"); } return(result = "21313"); }
/// <summary> /// 获取微信用户信息 /// </summary> /// <param name="openid"></param> /// <returns></returns> public static Cms.Model.wx_userinfo getwxuserinfo(string openid) { Cms.BLL.wx_info wxinfo = new Cms.BLL.wx_info(); Cms.Model.wx_info Model = new Cms.Model.wx_info(); Cms.BLL.wx_userinfo userinfo = new Cms.BLL.wx_userinfo(); Cms.Model.wx_userinfo muserinfo = new Cms.Model.wx_userinfo(); Model = wxinfo.GetModel(1); string str = ""; DataTable dt = userinfo.GetList("openid='" + openid + "' order by updatetime desc").Tables[0]; if (dt.Rows.Count > 0) { string uptime = Convert.ToDateTime(dt.Rows[0]["updatetime"]).ToString("yyyy-MM-dd"); string time = DateTime.Now.ToString("yyyy-MM-dd"); if (uptime == time) { muserinfo = userinfo.GetModel(int.Parse(dt.Rows[0]["id"].ToString())); } else { string Str = GetJson("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + Model.AppId + "&secret=" + Model.AppSecret + ""); //微信回传的数据为Json格式,将Json格式转化成对象 OAuth_Token ModelOAuth_Token = wxuser.JSONToObject <OAuth_Token>(Str); setlog("添加ModelOAuth_Token", ModelOAuth_Token.access_token); string StrTwo = GetJson("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + ModelOAuth_Token.access_token + "&openid=" + openid + ""); wxuserinfo ModelTwo = wxuser.JSONToObject <wxuserinfo>(StrTwo); muserinfo.subscribe = ModelTwo.subscribe; muserinfo.openid = ModelTwo.openid; muserinfo.nickname = ModelTwo.nickname; muserinfo.sex = ModelTwo.sex; muserinfo.language = ModelTwo.language; muserinfo.city = ModelTwo.city; muserinfo.province = ModelTwo.province; muserinfo.country = ModelTwo.country; muserinfo.headimgurl = ModelTwo.headimgurl; muserinfo.subscribe_time = ModelTwo.subscribe_time; muserinfo.remark = ModelTwo.remark; muserinfo.updatetime = DateTime.Now; //str = setinfo("https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + Model.access_token + "&openid=" + openid, "", openid); //muserinfo = JSONToObject<Cms.Model.wx_userinfo>(str); //Cms.Model.wx_userinfo wx = new Cms.Model.wx_userinfo(); ////wx.id = int.Parse(dt.Rows[0]["id"].ToString()); //wx.subscribe = muserinfo.subscribe; //wx.openid = muserinfo.openid; //wx.nickname = muserinfo.nickname; //wx.sex = muserinfo.sex; //wx.language = muserinfo.language; //wx.city = muserinfo.city; //wx.province = muserinfo.province; //wx.country = muserinfo.country; //wx.headimgurl = muserinfo.headimgurl; //wx.subscribe_time = muserinfo.subscribe_time; //wx.remark = muserinfo.remark; //wx.updatetime = DateTime.Now; userinfo.Add(muserinfo); } } return(muserinfo); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Cms.Model.wx_userinfo model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Cms.Model.wx_userinfo model) { return(dal.Add(model)); }