微信网站登录doem
直接上代码
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的更多相关文章
- 微信一键登录(微信OAuth2.0)
1.注册微信开放平台https://open.weixin.qq.com,一定要清楚微信开放平台和微信公众平台是分别独立的,不能共用. 2.登录进入——管理中心,网站应用,创建网站应用.填写申请,企业 ...
- 微信授权登录-微信公众号和PC端网站
https://blog.csdn.net/qq_34664239/article/details/79107529 一.微信公众号授权登录——微信公众平台 微信授权登录,并调用后台接口,获取用户信息 ...
- 微信公众平台开发——微信授权登录(OAuth2.0)
1.OAuth2.0简介 OAuth(开放授权)是一个开放标准,允许用户让第三方应用访问该用户在某一网站上存储的私密的资源(如照片,视频,联系人列表),而无需将用户名和密码提供给第三方应用. 允许用户 ...
- [转] Android:微信授权登录与微信分享全解析
https://wohugb.gitbooks.io/wechat/content/qrconnent/refresh_token.html http://blog.csdn.net/xiong_it ...
- 微信第三方登录(原生)demo
在一家ecstore二开公司有一段时间了,公司希望往自己研发产品上面走,一直在培养新人. 最近要自己去微信登录,自己就在ectore的框架基础上,写的原生微信第三方登录以此来熟悉微信第三方登录,在 ...
- 微信授权登录(PHP)
微信授权登录(PHP) 微信授权 OAuth2.0授权 微信网页授权 主要是在项目中遇到网页授权登录这个需求,就对此做些总结记录. OAuth2.0授权 OAuth是一个开放协议,允许用户让第三方应用 ...
- wap2app(五)-- 微信授权登录以及踩过的坑
应用场景是:用Hbuilder打包app,在app中点击微信授权登录或者某一操作,调起微信授权登录,用户授权后拿到用户信息. 一.登录插件配置 先配置微信登录参数 appid和appsecret,在m ...
- VUE开发SPA之微信授权登录
SPA单页应用中微信授权登录的一点思路 单页应用应该如何解决微信授权登录的尴尬跳转?后退无法返回?主要遇到的问题就是 先进入单页应用,一边渲染页面一边判断用户有没有登录,当判断到没有登录时异步数据请求 ...
- 微信公众号与APP微信第三方登录账号打通
一个项目同时开发了APP和微信服务号,需要做到APP和微信服务号的账号互通同步,也就是说一个账号在2个地方都可以用,当然这个前提是保证你公司自己的服务器的数据库用的是同一套. 为保证用户数据的唯一性, ...
随机推荐
- github用户注册和仓库创建
访问github官网:https://github.com/,点击注册进入注册页面 输入用户名,电子邮箱和密码后点击下一步 邮箱验证,收到github的验证邮箱,打开后点击验证 选择个人计划 创建仓库 ...
- Java 后台请求第三方系统接口详解
//调用第三方系统接口 PrintWriter out = null; BufferedReader in = null; JSONObject jsonObject = null; Closeabl ...
- CSAPP lab1——位运算
本次为一次计算机系统实验,就是使用一些基本的运算符来实现函数功能. ps做这些题让我想起大一上学期刚学二进制时被鹏哥支配的痛苦. 知识准备: 1.负数等于正数取反加一. 2.左移一位相当于将这个数扩大 ...
- Windows下第一个驱动程序
Windows内核分析索引目录:https://www.cnblogs.com/onetrainee/p/11675224.html 参考下面博客: VS2017搭建驱动开发环境WDK :https: ...
- 移除 DevExpress 的 XtraForm 标题文字阴影
问题 在使用 DevExpress 开发 WinForm 程序时,我是使用的默认皮肤进行开发.但客户要求标题栏背景色改为蓝色,标题文字颜色改为白色. 改颜色比较简单,参考了 DevExpress Su ...
- llinux/重启/用户切换/注销
一.指令 shutdown命令 shutdown -h now //立即关机 shutdown -h 2 //分钟后关机 shutdown -r now //立即重启 shutdown -r 1 // ...
- Java生鲜电商平台-电商虚拟币的充值与消费思考
Java生鲜电商平台-电商虚拟币的充值与消费思考 项目背景 最近由于项目业务原因,需要为系统设计虚拟币的充值及消费功能.公司内已经有成熟的支付网关服务,所以重点变成了如何设计项目内虚拟币的充值流程,让 ...
- Java 国际化标准程序实现
国际化程序实现 所谓的国家化应用指的就是根据当前的语言环境读取指定的语言资源文件. 如果要想实现国际化的操作,那么首先要解决的问题就是如何读取资源文件的问题:所谓的资源文件 就是指文件后缀名称为:&q ...
- 【Gradle】Gradle插件
Gradle插件 插件的作用 把插件应用到项目中,插件会扩展项目的功能,帮助在项目构建过程中做很多事情. 1.可以添加任务到项目中,帮助完成测试.编译.打包等. 2.可以添加依赖配置到项目中,可以通过 ...
- tornado的IOLoop.instance()方法和IOLoop.current()方法区别
在使用tornado时,经常有人疑惑IOLoop.instance()方法和IOLoop.current()方法的区别是什么. IOLoop.instance() 返回一个全局 IOLoop实例. 大 ...