直接上代码

namespace CloudPrj.WeiXin
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Diyi();
            //string url ="https://open.weixin.qq.com/connect/qrconnect?appid=" + appid + "&redirect_uri=" + reredirect_url + "&response_type=code&scope=snsapi_login&state=" + secret + "#wechat_redirect";

}
        public void Diyi()
        {
            string appid = "wxc14f8e4042ba5463";      //公众号appid
            string secret = "322316fe831c7a2137fea0b4a62a2970";  //开发者密码
            string reredirect_url = "http://www.hai121.com/WeiXin/WebForm1.aspx";
            //回调链接,当请求完接口,会以get的方式传code参数给这个url
            string url = "https://open.weixin.qq.com/connect/qrconnect?appid=" + appid + "&redirect_uri=" + reredirect_url + "&response_type=code&scope=snsapi_login&state=" + secret + "#wechat_redirect";
            //普通授权,需要用户自己手动授权
            //$url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$reredirect_uri&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"; 
            //静默授权不需要用户手动授权,就是没有授权页面
            Response.Redirect(url);
        }
    }
}

public partial class index_HD : Page
    {
        string appid = "wxc14f8e4042ba5463";      //公众号appid
        string secret = "322316fe831c7a2137fea0b4a62a2970";  //开发者密码
        Result t;
        protected void Page_Load(object sender, EventArgs e)
        {
            string coem = Request["coem"];
            string token = getToken(coem);
            RefreshToken(token);
            getuser(token);
        }
        public static T JsonDeserialize<T>(string jsonString)
        {
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
            MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
            T obj = (T)ser.ReadObject(ms);
            return obj;
        }
        //通过code获取openid
        private string getToken(string code)
        {
        https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
            string _url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + secret + "&code=" + code + "&grant_type=authorization_code";
            WebClient wc = new WebClient();
            //取得微信返回的openid,access_token数据  
            String strReturn = wc.DownloadString(_url);
            Result b = new Result();
            //if (comHelper.InsertOp(b, "D_C_L", "D_id", this.Request, true, form1) > 0)
            //{

//}
            t = JsonDeserialize<Result>(strReturn);
            return t.access_token;
        }

//刷新
        private string RefreshToken(string token)
        {
        https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=APPID&grant_type=refresh_token&refresh_token=REFRESH_TOKEN
            string _url = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=" + appid + "&grant_type=refresh_token&refresh_token=" + token;
            WebClient wc = new WebClient();
            //取得微信返回的openid,access_token数据  
            String strReturn = wc.DownloadString(_url);
            Result b = new Result();
            //if (comHelper.InsertOp(b, "D_C_L", "D_id", this.Request, true, form1) > 0)
            //{

//}
            t = JsonDeserialize<Result>(strReturn);
            return strReturn;
        }

//获取用户
        private string getuser(string token)
        {
            string _url = "https://api.weixin.qq.com/sns/userinfo?access_token=" + t.access_token + "&openid=" + t.openid + "&lang=zh_CN";
            WebClient wc = new WebClient();
            //取得微信返回的openid,access_token数据  
            String strReturn = wc.DownloadString(_url);
            Result b = new Result();
            //if (comHelper.InsertOp(b, "D_C_L", "D_id", this.Request, true, form1) > 0)
            //{

//}
            return strReturn;
        }

源码下载 https://download.csdn.net/download/weixin_41472521/10656043

微信网站登录doem的更多相关文章

  1. 微信一键登录(微信OAuth2.0)

    1.注册微信开放平台https://open.weixin.qq.com,一定要清楚微信开放平台和微信公众平台是分别独立的,不能共用. 2.登录进入——管理中心,网站应用,创建网站应用.填写申请,企业 ...

  2. 微信授权登录-微信公众号和PC端网站

    https://blog.csdn.net/qq_34664239/article/details/79107529 一.微信公众号授权登录——微信公众平台 微信授权登录,并调用后台接口,获取用户信息 ...

  3. 微信公众平台开发——微信授权登录(OAuth2.0)

    1.OAuth2.0简介 OAuth(开放授权)是一个开放标准,允许用户让第三方应用访问该用户在某一网站上存储的私密的资源(如照片,视频,联系人列表),而无需将用户名和密码提供给第三方应用. 允许用户 ...

  4. [转] Android:微信授权登录与微信分享全解析

    https://wohugb.gitbooks.io/wechat/content/qrconnent/refresh_token.html http://blog.csdn.net/xiong_it ...

  5. 微信第三方登录(原生)demo

    在一家ecstore二开公司有一段时间了,公司希望往自己研发产品上面走,一直在培养新人.   最近要自己去微信登录,自己就在ectore的框架基础上,写的原生微信第三方登录以此来熟悉微信第三方登录,在 ...

  6. 微信授权登录(PHP)

    微信授权登录(PHP) 微信授权 OAuth2.0授权 微信网页授权 主要是在项目中遇到网页授权登录这个需求,就对此做些总结记录. OAuth2.0授权 OAuth是一个开放协议,允许用户让第三方应用 ...

  7. wap2app(五)-- 微信授权登录以及踩过的坑

    应用场景是:用Hbuilder打包app,在app中点击微信授权登录或者某一操作,调起微信授权登录,用户授权后拿到用户信息. 一.登录插件配置 先配置微信登录参数 appid和appsecret,在m ...

  8. VUE开发SPA之微信授权登录

    SPA单页应用中微信授权登录的一点思路 单页应用应该如何解决微信授权登录的尴尬跳转?后退无法返回?主要遇到的问题就是 先进入单页应用,一边渲染页面一边判断用户有没有登录,当判断到没有登录时异步数据请求 ...

  9. 微信公众号与APP微信第三方登录账号打通

    一个项目同时开发了APP和微信服务号,需要做到APP和微信服务号的账号互通同步,也就是说一个账号在2个地方都可以用,当然这个前提是保证你公司自己的服务器的数据库用的是同一套. 为保证用户数据的唯一性, ...

随机推荐

  1. VMware® Workstation 15 Pro 最新版软件安装教程

    VMware 15 Pro下载地址: https://pan.baidu.com/s/1ILY2PTqB-BaJMn2hbKO4CA 提取码:vebd 如有问题咨询QQ:2217084817 VMwa ...

  2. 分析Jackson的安全漏洞CVE-2019-12086

    CVE-2019-12086 Description A Polymorphic Typing issue was discovered in FasterXML jackson-databind 2 ...

  3. [WPF 自定义控件]使用WindowChrome自定义RibbonWindow

    1. 为什么要自定义RibbonWindow 自定义Window有可能是设计或功能上的要求,可以是非必要的,而自定义RibbonWindow则不一样: 如果程序使用了自定义样式的Window,为了统一 ...

  4. abp去掉AbpUser中的Name,Surname,去掉姓和名分离

    abp是国外的框架,默认的框架中的AbpUser表中的Name和Surname是分开的,这不符合国情:可以先去掉 1. 在User类中重写Name和Surname,并设置为私有 2. 在DbConte ...

  5. 使用docker简单搭建个人博客

    首先介绍需要的yml文件,docker-compose.yml: version: '3.3' services: db: image: mysql:5.7 volumes: - db_data:/v ...

  6. Linux-3.14.12内存管理笔记【伙伴管理算法(2)】

    前面已经分析了linux内存管理算法(伙伴管理算法)的准备工作. 具体的算法初始化则回到start_kernel()函数接着往下走,下一个函数是mm_init(): [file:/init/main. ...

  7. MATLAB聚类有效性评价指标(外部)

    MATLAB聚类有效性评价指标(外部) 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 更多内容,请看:MATLAB.聚类.MATLAB聚类有效性评价指 ...

  8. Linux 和 Windows 查看 CUDA 和 cuDNN 版本

    目录 Linux 查看 CUDA 版本 查看 cuDNN 版本 Windows 查看 CUDA 版本 查看 cuDNN 版本 References Linux 查看 CUDA 版本 方法一: nvcc ...

  9. go语言设计模式之memento

    memento.go package memento import ( "fmt" ) type State struct { Description string } type ...

  10. Java Web 学习(7) —— Spring MVC 之国际化

    Spring MVC 之国际化 i18n 与 l10n internationalization:国际化,以 i 开头,以 n 结尾,中间 18 个字母,简称 i18n. localization:本 ...