没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
















全文可编辑 word 文档 页眉与背景水印可删除
1
.NET 微信公众号获取 OpenID 和用户信息
本文实例为大家分享了微信公众平台实现获取用户
OpenID 的方法,供大家参考,具体内容如下
Index.aspx.cs 代码:
public partial class Index : System.Web.UI.Page
{
//用户 id
public string openid = "";
//公众号信息部分
public string appid =
ConfigurationManager.AppSettings["AppId"];
public string appsecret =
ConfigurationManager.AppSettings["AppSecret"];
public string redirect_uri
=HttpUtility.UrlEncode("https://www.jb51.net");
public string scope = "【删除这个并填入请求类型,
例如:snsapi_userinfo】";

全文可编辑 word 文档 页眉与背景水印可删除
2
#region 显示页面
public string accesstoken;
public string nickname;
public string sex;
public string headimgurl;
public string province;
public string country;
public string language;
public string city;
public string privilege = "";
#endregion
protected void Page_Load(object sender,
EventArgs e)
{
/*
*微信认证获取 openid 部分:
*临时认证 code
*/
//微信认证部分:第二步 获得 code

全文可编辑 word 文档 页眉与背景水印可删除
3
string code = Request["code"];
if (string.IsNullOrEmpty(code))
{
//如果 code 没获取成功,重新拉取一遍
OpenAccess();
}
//微信认证部分:第三步 获得 openid
string url =
string.Format("https://api.weixin.qq.com/sns/oauth2
/access_token?appid={0}&secret={1}&code={2}&grant_t
ype=authorization_code", appid, appsecret, code);
string result =
HttpClientHelper.GetResponse(url);
LogHelper.WriteFile(result);
JObject outputObj = JObject.Parse(result);
//微信认证部分:第四步 获得更多信息
accesstoken =
outputObj["access_token"].ToString();
openid = outputObj["openid"].ToString();
url =
string.Format("https://api.weixin.qq.com/sns/userin

全文可编辑 word 文档 页眉与背景水印可删除
4
fo?access_token={0}&openid={1}&lang=zh_CN",accessto
ken,openid);
string result1 =
HttpClientHelper.GetResponse(url);
LogHelper.WriteFile(result1);
JObject outputObj1 =
JObject.Parse(result1);//将 json 转为数组
//以下是第四步获得的信息:
nickname =
outputObj1["nickname"].ToString(); //昵称
sex = outputObj1["sex"].ToString(); //性别
什么的
headimgurl =
outputObj1["headimgurl"].ToString(); //头像 url
province =
outputObj1["province"].ToString(); ;
country =
outputObj1["country"].ToString(); ;
language =
outputObj1["language"].ToString(); ;
city = outputObj1["city"].ToString(); ;
//将获得的用户信息填入到 session 中
剩余19页未读,继续阅读
资源评论


mmoo_python
- 粉丝: 1w+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 基于PY32F403开发板学习(1-点亮LED灯)源码
- QT6 阅读与注释 QAction,给出源代码,其实现了菜单栏与工具栏中的按钮
- Ubuntu系统Python安装与使用教程 .pdf
- 西电计科网安密码学实验
- 使用 Spring Boot 调用 DeepSeek API的非流式实现
- elk镜像3(kibana)
- elk镜像4(logstah)
- 西电b测(2PSK,2DPSK)
- elk镜像2(elasticsearch)
- 用yolov8训练自己的模型
- 情感文本数据分类数据集,包含28个情感类别
- mysql908资源包
- 适用于Windows的Cobaltstrike CrossC2插件已改过代码
- 牙齿重建-基于五张口腔正畸图像的牙齿三维重建算法-附项目源码-优质项目实战.zip
- Centos7的安装与相关环境软件部署
- 三维重建-基于Matlab+轮廓形状实现的三维重建算法-附项目源码+重建效果-优质项目实战.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
