微信网页获取openId
<%@ WebHandler Language="C#" Class="UserAuth" %> public class UserAuth : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{ var appid = "wxf1c24c60e3ac13b7";
var secret = "5902b9817acb7a290d4b7c2e6e97d4d3"; var code = context.Request.QueryString["Code"];
if (string.IsNullOrEmpty(code))
{
var url = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri=http%3a%2f%2fwx.alinq.org%2fTest%2fUserAuth.ashx&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", appid);
context.Response.Redirect(url);
}
else
{
var client = new System.Net.WebClient();
client.Encoding = System.Text.Encoding.UTF8; var url = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", appid, secret, code);
var data = client.DownloadString(url); var serializer = new JavaScriptSerializer();
var obj = serializer.Deserialize<Dictionary<string, string>>(data);
string accessToken;
if (!obj.TryGetValue("access_token", out accessToken))
return; var opentid = obj["openid"];
url = string.Format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN", accessToken, opentid);
data = client.DownloadString(url);
var userInfo = serializer.Deserialize<Dictionary<string, object>>(data);
foreach (var key in userInfo.Keys)
{
context.Response.Write(string.Format("{0}: {1}", key, userInfo[key]) + "<br/>");
}
}
}
}
微信网页获取openId的更多相关文章
- 微信点餐系统(七)-微信授权获取openid:
章节小结: 1.学会了微信授权的步骤,学会了微信授权的文档 2.学会了使用natapp内网穿透工具 3.加深了虚拟机的网络配置以及基本使用 4.学会了抓包购票工具fiddler的使用 5.微信授权步骤 ...
- 绑定微信以及获取openId
由于公司最近在做一个微信公众号的项目,需要获取用户openId,我再一次踏入了微信的坑! 先在这里告诫后来的同志,如果一样要开始做有关微信的东西,最好是有前辈,或者直接看完文档,不懂或者纳闷的地方直接 ...
- node 微信授权 获取openid
node获取微信授权拿到openid 需要了解的网站 1.微信授权. 先说一下流程(一张图代替所有): 流程步骤: 1.用户同意,获取code. 2.通过code获取网页授权access_toke ...
- [转] Android进阶——安卓接入微信,获取OpenID
PS: sendAuthRequest拿到code,通过code拿到access_token和openId,access_token可以拿到用户的信息 http://blog.csdn.net/hao ...
- 微信企业号获取OpenID过程
define('CorpID', "wx82e2c31215d9a5a7"); define('CorpSecret', ""); //当前管理组 设置-> ...
- 微信小程序调用微信登陆获取openid及用户信息 java做为服务端
转载的文章,很不错 https://blog.csdn.net/weilai_zhilu/article/details/77932630
- 微信公众号&小程序 -- 获取并解密用户数据(获取openId、unionId)
本文转自https://my.oschina.net/u/3235888/blog/832895 前言 微信小程序API文档:https://mp.weixin.qq.com/debug/wxadoc ...
- 获取openid
请将文件MP_verify_IbWggk5i4gWgrast.txt上传至mp.weixin.qq.com指向的web服务器(或虚拟主机)的目录 怎么处理的?//将txt文件上传到你填的域名的根目录 ...
- 小程序获取openid和unionid java实现
官方api:https://developers.weixin.qq.com/miniprogram/dev/api/api-login.html#wxloginobject 参考文章:https:/ ...
随机推荐
- .NET: C#: StopWatch
StopWatch class is used for calculate the timespan for that procedure. In Debug Mode it will be very ...
- Linux: .vimrc
set nuset autoindentset cindent"set tabstop=2"set shiftwidth=2set cursorlineset hlsearch&q ...
- windows系统调用 进程快照
#include "windows.h" #include "tlhelp32.h" #include "iostream" using n ...
- jq 换图片路径
$("#index_01")[0].src="images/index_01_1.jpg"; //更改ID为index_01的图片的src值 $("# ...
- oracle的索引维护
索引重建 Alter index idx_name rebuild partition index_partition_name [online nologging] 需要对每个分区索引做rebuil ...
- EBS R12版 GL追溯到各个模块
应收.应付.收款.付款等单据都可以生成ERP的日记帐,那么这些模块的关系是如何关联的呢,我们将会解决这个问题. 各个模块与总帐模块的关系,主要是通过子分类帐来进行关联的. 下面的SQL就是总帐与子分类 ...
- springmvc+spring+mybatis分页查询实例版本1,ver1.0
无聊做做看看,几乎没有怎么仔细做过这方面的,总是以为很简单,想想就会,实际做起来结合工作经验感觉还是挺有收获的,可以用在自己的项目上 第一版本思路:框架使用ssm,这个无所谓,采用分页语句查询指定页面 ...
- ThinkPHP讲解(八)——显示、修改、添加、删除
一.显示数据 <h1>主页面</h1> <table width="100%" border="1" cellpadding=&q ...
- C#语言基础2016/3/6
一. 基础知识 输入输出 Console.Write();//输出语句,自动换行 Console.WriteLine();//输出语句 Console.WriteLine();输入语句 Consol ...
- android初体验——HelloWord
一.新建项目: 打开 eclipse ,选择File – New – Android Application Project 输入项目名称,程序名称,包名. 包名不能重复,它是项目的唯一标示,我理解为 ...