1.首先根据appid 获取到预授权码的code

  string Appid = "******";//appid。由于网页授权与js-jdk使用不同微信,所以暂时独立于此处。
string redirect_uri = "http://*********";//这里是回调地址的url
string state = filterContext.HttpContext.Request.Url.ToString();//这里的state是
state = state.Replace("?", "|").Replace("&", "!!");
string url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Appid + "&redirect_uri=" + redirect_uri + "&response_type=code&scope=snsapi_userinfo&state=" + state + "#wechat_redirect";
filterContext.HttpContext.Response.Redirect(url);

2.根据预授权码获取个人的用户信息

//根据code获取预授权码asstoken 和 openid 和Unionid
     string url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + df.getAppid() + "&secret=" + df.getAppSecret() + "&code=" + code + "&grant_type=authorization_code";
WebClient wc = new WebClient();
wc.Credentials = CredentialCache.DefaultCredentials;
Byte[] pageData = wc.DownloadData(url);
  string htmlstr = System.Text.Encoding.GetEncoding("utf-8").GetString(pageData);
    
//根据预授权码获取用户个人信息
df.get_json方法是获取当前json字符串的当前节点的值
    url = "https://api.weixin.qq.com/sns/userinfo?access_token=" + df.get_json(htmlstr, "access_token") + "&openid=" + df.get_json(htmlstr, "openid") + "&lang=zh_CN";
    wc = new WebClient();
    wc.Credentials = CredentialCache.DefaultCredentials;
    pageData = wc.DownloadData(url);
    htmlstr = System.Text.Encoding.GetEncoding("utf-8").GetString(pageData);
    return htmlstr;

3.如果想要根据openid 获取Unionid 则需要以下步奏

3.1根据appid 和appscreat 获取当前公众号的asstoken

3.2根据openid和UnionId获取用户信息(这里的用户基本信息只能是关注的才能获取完全基本信息,未关注只能获取openid和unionid)

关于微信授权和unionid 的获取思路。的更多相关文章

  1. 微信公众号&小程序 -- 获取并解密用户数据(获取openId、unionId)

    本文转自https://my.oschina.net/u/3235888/blog/832895 前言 微信小程序API文档:https://mp.weixin.qq.com/debug/wxadoc ...

  2. 微信小程序unionid获取问题

    微信小程序使用login获取unionid时可能获取不到,原因可能是该微信账号没有关注小程序所在公众号等.但在微信小程序中使用微信注册,必须要用unionid注册时,大部分用户就会因此无法注册成功. ...

  3. C#开发微信门户及应用(14)-在微信菜单中采用重定向获取用户数据

    我曾经在系列文章中的<C#开发微信门户及应用(11)--微信菜单的多种表现方式介绍>中介绍了微信菜单里面的重定向操作,通过这个重定向操作,我们可以获取一个code值,然后获取用户的open ...

  4. OAuth2.0授权和SSO授权

    一. OAuth2.0授权和SSO授 1. OAuth2.0 --> 网页 --> 当前程序内授权 --> 输入账号密码 --> (自己需要获取到令牌, 自己处理逻辑) 授权成 ...

  5. 解决微信公众号授权登录和开放平台微信第三方应用授权登录获取到的用户Openid关联问题

    开发背景: 最近一段时间一直在做关于微信方面的网站应用开发,这段时间也收获的不少关于微信开发方面的开发技能,接触的比较多的主要有微信公众号和微信网站app第三方登录授权,以及微信会员卡,优惠券和扫描二 ...

  6. ASP.NET MVC - 安全、身份认证、角色授权和ASP.NET Identity

    ASP.NET MVC - 安全.身份认证.角色授权和ASP.NET Identity ASP.NET MVC内置的认证特性 AuthorizeAttribute特性(System.Web.Mvc)( ...

  7. 微信openid和UnionID (多公众号如何判断是否是同一人)

    以下内容源于网络,因为非博客园信息,有想收藏,只能直接复制粘贴了,还希望原稿人员理解. 微信公众平台更新,为开发者提供UnionID机制 经开发者反馈,由于同一公司下多个公众号之间需要用户帐号互通,微 ...

  8. 转:微信开发之使用java获取签名signature(贴源码,附工程)

    微信开发之使用java获取签名signature(贴源码,附工程) 标签: 微信signature获取签名 2015-12-29 22:15 6954人阅读 评论(3) 收藏 举报  分类: 微信开发 ...

  9. 微信公众平台开发-access_token获取及应用(含源码)

    微信公众平台开发-access_token获取及应用(含源码)作者: 孟祥磊-<微信公众平台开发实例教程> 很多系统中都有access_token参数,对于微信公众平台的access_to ...

随机推荐

  1. CF 937

    A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...

  2. pandas数据排序(series排序 & DataFrame排序)

    # pandas数据排序 # series的排序: # Series.sort_values(ascending = True,inplace = False) # 参数说明: # ascending ...

  3. Kettle整理

    下载kettle版本 (1)hadoop version 查看hadoop的版本    hadoop2.6 (2)则在data-integration\plugins\pentaho-big-data ...

  4. Selenium Java tutorial

     https://eyes.applitools.com/app/test-results 1.

  5. Zookeeper学习笔记(下)

    这是ZK学习笔记的下篇, 主要希望可以分享一些 ZK 的应用以及其应用原理 我本人的学习告一段落, 不过还遗留了一些ZK相关的任务开发和性能测试的任务, 留待以后完成之后再通过其他文章来进行分享了 Z ...

  6. java(jdk8)死锁案例

    package testSynchorized; public class SynchronizedDeadLockTest { static Object src1 = new Object(); ...

  7. linux运维、架构之路-rpm定制、本地yum仓库搭建

    一.定制rpm包 1.环境 [root@m01 ~]# cat /etc/redhat-release CentOS release 6.9 (Final) [root@m01 ~]# uname - ...

  8. WEB超大文件上传与下载

    1.介绍enctype enctype 属性规定发送到服务器之前应该如何对表单数据进行编码. enctype作用是告知服务器请求正文的MIME类型(请求消息头content-type的作用一样) 1. ...

  9. 常用的JAVA第三方工具类

    转自:https://www.jianshu.com/u/9c5cb1ee4c46 一. org.apache.commons.io.IOUtils 注解 说明 closeQuietly 关闭一个IO ...

  10. DC.p4: programming the forwarding plane of a data-center switch

    Name of article:Dc. p4: Programming the forwarding plane of a data-center switch Origin of the artic ...