private static JsTicket _GetTicket(string access_token) { string url = string.Format(@"https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={0}&type=jsapi", access_token); string response_content = WebClientHelper.CallGet(url); if (response_content.IndexOf("ticket") > 0) { // LogBase.LogHzCrm.LogInfo("ticket:" + response_content, ELogType.Info); //JavaScriptSerializer serializer = new JavaScriptSerializer(); return(GYLib.Base.Utils.JsonUtils.ParseFromJson <JsTicket>(response_content)); //return serializer.Deserialize<JsTicket>(response_content); } return(null); }
private void GetWeiXinInfo() { #region 获取微信信息 Response.Cookies.Append("WxOpenId", "error", cookie); string resultParam = ""; if (Request.Query["code"].ToString() != null) { string code = Request.Query["code"]; if (!string.IsNullOrEmpty(code)) { WebClientHelper wc = new WebClientHelper(); string strUrl = string.Format( @"https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code" , ConfigurationManager.GetSection("WxAppId") , ConfigurationManager.GetSection("WxSecret") , code); wc.SetUrl(strUrl); string strResult = wc.CallGet(""); if (!string.IsNullOrEmpty(strResult)) { if (strResult.IndexOf("errcode") > 0) { var json = JsonConvert.SerializeObject(strResult); Response.Cookies.Append("WxOpenId", "error", cookie); // WebSession.WxOpenId = "error"; } else { _oauthbase = JsonConvert.DeserializeObject <OauthBase>(strResult); if (_oauthbase != null && !string.IsNullOrEmpty(_oauthbase.openid)) { // WebSession.WxOpenId = _oauthbase.openid; Response.Cookies.Append("WxOpenId", _oauthbase.openid, cookie); resultParam = "openid=" + _oauthbase.openid; //额外获取用户信息 WxUserInfo _wxUserInfo = GetWxUserInfo(_oauthbase.openid); if (_wxUserInfo != null && !string.IsNullOrEmpty(_wxUserInfo.openid)) { //ResponseLogin reLogin = new ResponseLogin(); //reLogin.Name = _wxUserInfo.nickname; //reLogin.WxOpenId = _wxUserInfo.openid; //reLogin.WxImgUrl = _wxUserInfo.headimgurl; //reLogin.Subscribe = ConvertUtils.ConvertToInt(_wxUserInfo.subscribe); //reLogin.Sex = ConvertUtils.ConvertToInt(_wxUserInfo.sex); ////额外获取支付的OpenId //RequestLogin login = new RequestLogin(); //login.WxOpenId = _wxUserInfo.openid; //login.Flag = (int)EnumLoginFlag.WXOpenID; //ResponseLogin responseLogin = MemberDataAccess.MemberLogin(login, _accesstoken); //if (responseLogin.IsSucessed == 1) //{ // reLogin.PayWxOpenId = responseLogin.PayWxOpenId; //} //WebCommon.CreateSession(this.Page.Session, reLogin); Response.Cookies.Append("UserCookieModel", JsonConvert.SerializeObject(_wxUserInfo), cookie); resultParam = string.Format("openid={0}&subscribe={3}&nickname={1}&headimgurl={2}", _wxUserInfo.openid, _wxUserInfo.nickname, _wxUserInfo.headimgurl, _wxUserInfo.subscribe ?? "0"); } else { WxAccToken.SetOverDueTime(DateTime.Now.AddHours(-1)); } } } } } } #endregion // GetNextUrl(); }