public ActionResult SeeMember(string code, string state) { try { if (state == "wanlixin") { var token = OAuth2API.GetAccessToken(code, WeixinConfig.AppID, WeixinConfig.AppSecret); var usermodel = WebUtils.Get2 <CustomerNewSelect>(WebConfig.ApiBaseUrl + "WlxApi/GetCustomerNewBySql", token.openid); if (!string.IsNullOrEmpty(usermodel.c_num))//c_openid已经更新过 { Customer customer = new Customer(); customer.Phone = usermodel.c_num; Session["Customer"] = customer; h_CustomerNew h_CustomerNew = new h_CustomerNew(); h_CustomerNew.c_num = usermodel.c_num; h_CustomerNew.c_Name = usermodel.c_Name; h_CustomerNew.c_Identity = usermodel.c_Identity; Session["h_CustomerNew"] = h_CustomerNew; return(RedirectToAction("Member", "Home")); } } return(Content("验证失败4")); } catch (Exception ex) { string st = string.Format("时间:{0},描述:{1}", DateTime.Now, ex.ToString()); Tools.MessBox(st, "//Log//Weixin//SeeMember"); return(Redirect("/error/index")); } }
public ActionResult DefaultAuthorize(string code, string state) { try { if (state == "wanlixin") { var scope = WeixinConfig.OauthScope; double expires_in = 0; var access_token = ""; var openId = ""; var token = OAuth2API.GetAccessToken(code, WeixinConfig.AppID, WeixinConfig.AppSecret); dynamic userinfo; //access_token = WeixinConfig.TokenHelper.GetToken();//基础支持中的access_token access_token = AccessTokenContainer.TryGetAccessToken(WeixinConfig.AppID, WeixinConfig.AppSecret, true); openId = token.openid; expires_in = token.expires_in; //TODO: 如果用户已经关注,可以用openid,获取用户信息。 userinfo = UserAdminAPI.GetInfo(access_token, openId);//如果本地已经存储了用户基本信息,建议在本地获取。 Tools.MessBox(string.Format("时间:{0},描述:{1}", DateTime.Now, userinfo), "//Log//Weixin//DefaultAuthorize//userinfo//"); //通过api接口,根据openid查找,如果openid已经保存,跳转到”会员积分查询“页面,否则跳转到”输入手机号码页面“ Tools.MessBox("openId:" + openId); var usermodel = WebUtils.Get2 <CustomerNewSelect>(WebConfig.ApiBaseUrl + "WlxApi/GetCustomerNewBySql", openId); //Tools.MessBox("usermodel:"+ usermodel.c_num); if (usermodel != null) { if (!string.IsNullOrEmpty(usermodel.c_num))//c_openid已经更新过 { Customer customer = new Customer(); customer.Phone = usermodel.c_num; Session["Customer"] = customer; h_CustomerNew h_CustomerNew = new h_CustomerNew(); h_CustomerNew.c_num = usermodel.c_num; h_CustomerNew.c_Name = usermodel.c_Name; h_CustomerNew.c_Identity = usermodel.c_Identity; Session["h_CustomerNew"] = h_CustomerNew; return(RedirectToAction("Member", "Home")); } } else { //插入微信信息 LoginService _loginservice = new LoginService(); Customer customer = _loginservice.CustomerLogin(userinfo.nickname, userinfo.openid, "", "", userinfo.headimgurl, Convert.ToInt32(userinfo.sex), userinfo.province, userinfo.city); if (customer != null) { Session["Customer"] = customer; } return(RedirectToAction("Index", "Home")); } } return(Content("验证失败4")); } catch (Exception ex) { string st = string.Format("时间:{0},描述:{1}", DateTime.Now, ex.ToString()); Tools.MessBox(st, "//Log//Weixin//"); return(Redirect("/error/index")); } }