C#网页授权获取微信Openid
string openid = "";
string appid = "微信公众号appid";
string appsecret = "秘钥";
if (Session["openid"] == null)
{
string code = Request.QueryString["code"];
string state = Request.QueryString["state"];
if (code != null && code.Length > 0)
{
#region 获取到CODE
string posturl = "https://api.weixin.qq.com/sns/oauth2/access_token?app);
JsonData jd = JsonMapper.ToObject(getstr);
openid = jd["openid"].ToString();
Session["openid"] = openid;
#endregion
}
else
{
string callbackurl = Request.Url.ToString();
openid = (string)Session["openid"];
if (openid == null || openid.Length <= 0)
{
string ecode = MD5Encode(callbackurl).ToLower().Substring(0, 15);
Session["wx_encode"] = ecode;
string url = "https://open.weixin.qq.com/connect/oauth2/authorize?app];
}