/// <summary> /// 1 授权判断,页面跳转; /// 2 获取openid /// </summary> /// <param name="model"></param> /// <param name="state"></param> /// <param name="targetUrl">目标地址</param> public void OAuth2BaseProc(Model.wx_userweixin model, string state, string targetUrl) { string isTest = MyCommFun.getAppSettingValue("isOAuthTest"); if (isTest == "1") { openid = MyCommFun.RequestOpenid(); return; } string code = MyCommFun.QueryString("code"); if (code == null || code.Trim() == "") { if (targetUrl == null || targetUrl.Trim() == "") { targetUrl = MyCommFun.getTotalUrl(); } //thisUrl = MyCommFun.getWebSite() + "/weixin/huodong/index.aspx"; string newUrl = OAuthApi.GetAuthorizeUrl(model.AppId, targetUrl, state, OAuthScope.snsapi_base); Response.Redirect(newUrl); } else { if (MyCommFun.getCookie("cookie_openid") == "") { var result = OAuthApi.GetAccessToken(model.AppId, model.AppSecret, code); openid = result.openid; MyCommFun.setCookie("cookie_openid", openid, 100); } openid = MyCommFun.getCookie("cookie_openid"); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string gzid_pd = MyCommFun.getCookie("zs_id"); BLL.wx_zh_gz gzBll = new BLL.wx_zh_gz(); if (gzid_pd != "") { if (gzBll.GetRecordCount("id='" + gzid_pd + "'") > 0) { Response.Redirect("zsReg_ret.aspx?zsid=" + gzid_pd); } } } }
/// <summary> /// 授权判断获取openid,如果code为空页面跳转 /// </summary> /// <param name="model"></param> /// <param name="state"></param> /// <param name="code">默认读取请求中的code属性</param> /// <param name="targetUrl">目标地址</param> protected string OAuth2BaseProc(Model.wx_userweixin model, string state, string code, string targetUrl) { string openid = String.Empty; #if DEBUG string isTest = MyCommFun.getAppSettingValue("isOAuthTest"); if (isTest == "1") { openid = MyCommFun.RequestOpenid(); return(openid); } #endif //如果不传 if (string.IsNullOrEmpty(code)) { code = MyCommFun.QueryString("code"); } if (code == null || code.Trim() == "") { if (targetUrl == null || targetUrl.Trim() == "") { targetUrl = MyCommFun.getTotalUrl(); } //thisUrl = MyCommFun.getWebSite() + "/weixin/huodong/index.aspx"; string newUrl = OAuthApi.GetAuthorizeUrl(model.AppId, targetUrl, state, OAuthScope.snsapi_base); //41008 缺少oauth code throw new UnAuthException(newUrl, "41008"); } else { if (MyCommFun.getCookie("cookie_openid") == "") { OAuthAccessTokenResult result = OAuthApi.GetAccessToken(model.AppId, model.AppSecret, code); openid = result.openid; MyCommFun.setCookie("cookie_openid", openid, 100); } openid = MyCommFun.getCookie("cookie_openid"); } return(openid); }