if (!IsPostBack)
{
string reurl = "http://www.xxxxxx/webchart/WebApp/MyCertification.aspx";
//传递参数,获取用户信息后,可跳转到自己定义的页面,想怎么处理就怎么处理
if (Request.QueryString["state"] != null && Request.QueryString["state"] != "")
{
if( Request.QueryString["state"].ToString()=="Un"&& Request.QueryString["code"]!=null&& Request.QueryString["code"].ToString()!="")
{
Log.Info("Authorize is success");
code = Request.QueryString["code"].ToString();
if (!string.IsNullOrEmpty(code))
{
WeiXin weixin = new WeiXin();
QmsFrameWork.WebChart.WXCodeUser User = weixin.GetUserByCode(code);
openid = User.openid;
txtopenid.Value = openid;
hidopenid.Value = openid;
if (User != null && User.openid != null && User.openid != "")
{
if (QmsFrameWork.Entities.WXUser.ISAuthorization(openid))
{
Response.Redirect("./MyStaffInfo.aspx?openid="+openid);
}
else
{
DataTable dt = QmsFrameWork.Entities.WXUser.QueryDataByOpenID(openid);
if (dt == null || dt.Rows.Count == 0)
{
weixin.InsertWeiXinUserByOpenID(openid);
}
else
{
string staffid, staffname;
staffid= txtstaffid.Value = dt.Rows[0]["staff_id"].ToString();
staffname= txtstaffname.Value = dt.Rows[0]["staff_name"].ToString();
if(!string.IsNullOrEmpty(staffid)&&!string.IsNullOrEmpty(staffname))
{
Response.Redirect("./WaitAuthorization.aspx");
}
}
}
}
}
}
else
{
Log.Info("Authorize is faile");
}
}
else
{
if (Request.QueryString["auth"] != null && Request.QueryString["auth"] != "" && Request.QueryString["auth"] == "1")
{
Response.Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=" + reurl + "&response_type=code&scope=snsapi_userinfo&state=Un&connect_redirect=1#wechat_redirect");
}
else
{
//不弹出授权页面
// Response.Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=" + reurl + "&response_type=code&scope=snsapi_base&state=Un&connect_redirect=1#wechat_redirect");
Response.Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=" + reurl + "&response_type=code&scope=snsapi_userinfo&state=Un&connect_redirect=1#wechat_redirect");
}
}
//弹出授权页面(如在不弹出授权页面基础下未获得openid,则弹出授权页面,提示用户授权)
}