資源簡介
入口頁面: wxProcess.aspx
【自己調(diào)通了非常喜悅。好東東,大家分享。 免積分,給個好評哦;)】
微信公眾平臺 網(wǎng)頁授權(quán)獲取用戶基本信息
//獲取從wxProcess.aspx傳遞過來的跳轉(zhuǎn)地址reurl
if (Request.QueryString["reurl"] != null && Request.QueryString["reurl"] != "")
{
reurl = Request.QueryString["reurl"].ToString();
}
string code = "";
if (Request.QueryString["code"] != null && Request.QueryString["code"] != "")
{
//獲取微信回傳的code
code = Request.QueryString["code"].ToString();
OAuth_Token Model = Get_token(code); //獲取token
OAuthUser OAuthUser_Model = Get_UserInfo(Model.access_token, Model.openid );
if(OAuthUser_Model.openid!=null && OAuthUser_Model.openid !="") //已獲取得openid及其他信息
{
//在頁面上輸出用戶信息
Response.Write("用戶OPENID:" + OAuthUser_Model.openid + "用戶昵稱:" + OAuthUser_Model.nickname + "性別:" + OAuthUser_Model.sex + "所在省:" + OAuthUser_Model.province + "所在市:" + OAuthUser_Model.city + "所在國家:" + OAuthUser_Model.country + "頭像地址:" + OAuthUser_Model.headimgurl + "用戶特權(quán)信息:" + OAuthUser_Model.privilege);
//或跳轉(zhuǎn)到自己的頁面,想怎么處理就怎么處理
Response.Redirect(reurl);
}
}

代碼片段和文件信息
using?System;
using?System.Data;
using?System.Configuration;
using?System.Collections;
using?System.Web;
using?System.Web.Security;
using?System.Web.UI;
using?System.Web.UI.WebControls;
using?System.Web.UI.WebControls.WebParts;
using?System.Web.UI.HtmlControls;
using?System.Net;
using?System.Text;
using?System.Runtime.Serialization.Json;
using?System.IO;
namespace?GustBook.WEB.front.html.CommonControl
{
????public?partial?class?wxProcess1?:?System.Web.UI.Page
????{
????????protected?void?Page_Load(object?sender?EventArgs?e)
????????{
????????????if?(!IsPostBack)
????????????{
//????????????????測試號信息
//appID
//wx81b71d9e6fcb9dd8
//appsecret
//1b7fb028c223d1d7283946ee8b52ee4b
????????????????//????????????TTK
????????????????//????????????????wxfef3c2c5833330ea
????????????????//AppSecret(應(yīng)用密鑰)a808ad45e740c0fa04fc1ca2579b83b5?隱藏?重置
????????????????string?reurl?=?““;
????????????????//傳遞參數(shù),獲取用戶信息后,可跳轉(zhuǎn)到自己定義的頁面,想怎么處理就怎么處理
????????????????if?(Request.QueryString[“reurl“]?!=?null?&&?Request.QueryString[“reurl“]?!=?““)
????????????????{
????????????????????reurl?=?Request.QueryString[“reurl“].ToString();
????????????????}
????????????????else
????????????????{
????????????????????reurl?=?“http://www.dreamlinker.cn“;
????????????????}
????????????????string?code?=?““;
????????????????//彈出授權(quán)頁面(如在不彈出授權(quán)頁面基礎(chǔ)下未獲得openid,彈出授權(quán)頁面,提示用戶授權(quán))
????????????????if?(Request.QueryString[“auth“]?!=?null?&&?Request.QueryString[“auth“]?!=?““?&&?Request.QueryString[“auth“]?==?“1“)
????????????????{
????????????????????Response.Redirect(“https://open.weixin.qq.com/connect/oauth2/authorize?appid=“?+?“wxfef3c2c5833330ea“?+?“&redirect_uri=http://www.dreamlinker.cn/wxProcess2.aspx?reurl=“?+?reurl?+?“&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect“);
????????????????}
????????????????else
????????????????{
????????????????????//不彈出授權(quán)頁面
????????????????????Response.Redirect(“https://open.weixin.qq.com/connect/oauth2/authorize?appid=“?+?“wxfef3c2c5833330ea“?+?“&redirect_uri=http://www.dreamlinker.cn/wxProcess2.aspx?reurl=“?+?reurl?+?“&response_type=code&scope=snsapi_base&state=1#wechat_redirect“);
???????????????????//?https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf0e81c3bee622d60&redirect_uri=http%3A%2F%2Fnba.bluewebgame.com%2Foauth_response.php&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect
????????????????}
????????????}
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????.......???????369??2016-02-27?00:17??wxProcess.aspx
?????文件???????2646??2016-03-01?23:21??wxProcess.aspx.cs
????.......???????795??2016-02-27?00:17??wxProcess.aspx.designer.cs
????.......???????371??2016-02-27?00:17??wxProcess2.aspx
?????文件??????11281??2016-03-02?09:25??wxProcess2.aspx.cs
????.......???????796??2016-02-27?00:17??wxProcess2.aspx.designer.cs
-----------?---------??----------?-----??----
????????????????16258????????????????????6
評論
共有 條評論