[C#] 纯文本查看 复制代码
protected void Page_Load(object sender, EventArgs e)
{
var code = this.Request.Params["code"];
var ret_url = this.Request.Params["ret_url"];
LogHelper.WriteLog(code);
if (!string.IsNullOrEmpty(code))
{
// 处理登录状态, 保存cookie, 并跳转到index
//获取访问用户身份
var url = $"https://qyapi.weixin.qq.com/cgi-bin/service/getuserinfo3rd?access_token={AccessTokenHelper.get_suite_access_token()}&code={code}";
HttpHelper http = new HttpHelper();
HttpResult result = http.GetHtml(new HttpItem()
{
URL = url,
ContentType = "application/x-www-form-urlencoded",
Method = "get",
Encoding = Encoding.UTF8
});
var html = JsonConvert.DeserializeObject<weixin_login_return_info>(result.Html);
if (html.errcode == 0)
{
// 查询用户数据,并添加cookie
var userbll = new sys_userBLL();
sys_user user_info = userbll.FindListOne($"wx_userid='{html.UserId}' and impower=1 and userflag=1 and comid=(select comid from sys_company where corpid='{html.CorpId}')");
if (user_info != null)
{
LoginHelper.Login(user_info.uid, "");
if (!string.IsNullOrEmpty(ret_url)) { Response.Redirect(ret_url); }
else { Response.Redirect("/PhoneCRM/Home/index.aspx"); }
}
}
}
}
}
}