/// <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"); } }
/// <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); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/json"; string _action = MyCommFun.QueryString("myact"); Dictionary <string, string> jsondict = new Dictionary <string, string>(); #region 注册观众信息 if (_action == "addGz") { BLL.wx_zh_gz gzBll = new BLL.wx_zh_gz(); string tel = MyCommFun.QueryString("tel"); string fax = MyCommFun.QueryString("fax"); string mobile = MyCommFun.QueryString("mobile"); string qq = MyCommFun.QueryString("qq"); string linkman = MyCommFun.QueryString("linkman"); string email = MyCommFun.QueryString("email"); string company = MyCommFun.QueryString("company"); try { Model.wx_zh_gz gzModel = new Model.wx_zh_gz { company_name = company, tel = tel, createdate = DateTime.Now, fax = fax, linkman = linkman, mobile = mobile, qq = qq, email = email }; string gzid = gzBll.Add(gzModel).ToString(); MyCommFun.setCookie("gz_id", gzid, 30); jsondict.Add("res", "1"); jsondict.Add("content", gzid); context.Response.Write(MyCommFun.getJsonStr(jsondict)); return; } catch (Exception) { jsondict.Add("res", "0"); context.Response.Write(MyCommFun.getJsonStr(jsondict)); return; } } #endregion #region 注册展商信息 if (_action == "addZs") { BLL.wx_zh_zs zsBll = new BLL.wx_zh_zs(); string tel = MyCommFun.QueryString("tel"); string fax = MyCommFun.QueryString("fax"); string mobile = MyCommFun.QueryString("mobile"); string qq = MyCommFun.QueryString("qq"); string linkman = MyCommFun.QueryString("linkman"); string email = MyCommFun.QueryString("email"); string company = MyCommFun.QueryString("company"); string type = MyCommFun.QueryString("type"); string area = MyCommFun.QueryString("area"); try { Model.wx_zh_zs zsModel = new Model.wx_zh_zs { company_name = company, tel = tel, createdate = DateTime.Now, fax = fax, linkman = linkman, mobile = mobile, qq = qq, email = email, sq_area = area, type = type }; string zsid = zsBll.Add(zsModel).ToString(); MyCommFun.setCookie("zs_id", zsid, 30); jsondict.Add("res", "1"); jsondict.Add("content", zsid); context.Response.Write(MyCommFun.getJsonStr(jsondict)); return; } catch (Exception) { jsondict.Add("res", "0"); context.Response.Write(MyCommFun.getJsonStr(jsondict)); return; } } #endregion if (_action == "getqrcode") { #region 生成二维码 //if (Request["chl"] == null) { return; } //string url = "http://" + HttpContext.Current.Request.Url.Authority + "/weixin/ucard/checkFX.aspx?" + Request["chl"].ToString().Replace("_", "&"); string url = MyCommFun.getWebSite() + "/weixin/zhanhui/gzReg_ret.aspx"; //创建二维码生成类 QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); try { qrCodeEncoder.QRCodeScale = 4; } catch { } String data = url; System.IO.MemoryStream ms = new System.IO.MemoryStream(); qrCodeEncoder.QRCodeBackgroundColor = System.Drawing.Color.White; //背景颜色 // qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC; qrCodeEncoder.QRCodeForegroundColor = System.Drawing.Color.Black; //图像颜色 //设置编码版本 qrCodeEncoder.QRCodeVersion = 0; System.Drawing.Image myimg = qrCodeEncoder.Encode(data, System.Text.Encoding.UTF8); //kedee 增加utf-8编码,可支持中文汉字 myimg.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); context.Response.ClearContent(); context.Response.ContentType = "image/Gif"; context.Response.BinaryWrite(ms.ToArray()); context.Response.End(); #endregion } }