?? ????? WeChat ??? ?? ??? ???? ? ? ?????. WeChat ?? ????? ??? ???? ?????? ? ? ????. ? ???. ?? ??? ??? ???, ?? ??? ?? ? ??? ???? ???, ??? ?? Url ??(View ??? ??)??, ?? ??? ??? ??(Click ??? ??)???. ???? ????? WeChat? URL ??? ??? ??? ?? ? ??? WeChat ??? ??? ?? ????? ??? ??? ? ?? ?? ??(????? ??)? ?????. ? ????? ?? ??? ??? ???? ??? ?????. ???? ??? ?? ??? ? ?? ?????.
1. WeChat ?? ?? ??
WeChat ?? ?? ????: ?? ?? ???? ?? 3?? 1? ??? ??? ? ???, ? 1? ???? ?? 5?? ?? ??. 1?? ???? ?? 4?? ??? ??? ? ???, 2?? ???? ?? 7?? ??? ??? ? ????. ?? ??? "..."?? ?????.
?? ??? ?? ????? ???? ??? ? ????.
??? ?? ?? ??? ?? ???? ???? ???? ??? ?? ???????? ???? ?? ???? ?? ?? ?? ??? ?????, ??? ???? ??? WeChat OpenID? ???? ? ?? ?? ???? ?? ? ???? ??? ????. ?? ? ???? ?? ??? ??? ? ???, ??? ?? ??? ?? ??? ?? ?? ??? ??? ? ????.
??? ???? Url ?? ???? ?? WeChat? ??? ??? ????.
???? WeChat ?? ??? ?3? ????? ???? ??(Web WeChat ??), ?? ??? ? ?????? ?? ?? ???? ?? ??(???, ??, ??, ?? ??)? ?? ? ????. ??? ??? ???? ?? ???, ??? ?? ??, ?? ???, ??? ?? ?? ?? ??? ??? ? ????. "??? ?? ?? ??? ?? ?????? ???? ?? ?? ? ??? ????? ?? ? ???? OpenID? ????? ???? ?? ??? ??? ? ????. ??? ???? ?? ??? ??? ?? ??? ? ????. ???? ??? ???? ????. ???? ????? ?? ???. ?? ??? ????? ???? ??? ??? ???? ?????? ?????. ???? ???? ?? ??? ?? ? ????. ?? ??? ???? ??????.)"
2. ???? ?? ??? URL
??? ??? ??? ???? ?? ???? ? ?? ??? ????. ???? ???? ?? ??? ?? ? ?? ??? ??? ???????.
??? ?? ???? ??? ???? http://www.iqidi.com/testwx.ashx ???? ???? ?? ???? OpenID ? ?? ???? ??? ???? ??? ?????.
scope=snsapi_base ??? ??? ??? ????.
https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3d81fc2886d86526&redirect_uri=http%3A%2F% 2Fwww.iqidi.com%2Ftestwx.ashx&response_type=code&scope=snsapi_base&state=123#wechat_redirect
scope=snsapi_userinfo ??? ??? ????:
https://open.weixin.qq.com /connect/oauth2 /authorize?appid=wx3d81fc2886d86526&redirect_uri=http%3A%2F%2Fwww.iqidi.com%2Ftestwx.ashx&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect
??? ??? ??? ?????? ???? ??? ????. ? ??? ???? ??? ? ??? ? ??? ???? ?? ???? ??? ? ?? ?? ??? ?????.
? ? ?? ??? ?? ??? ???? ????? ?? ???? ??? ?? ???? OpenID? ???? ???????. ??? ??. ? ?? ??? ?? ?????. ???? ??? ?????? ??? ????.
TestWX.ashx? ??? ??? ??? ??? ????.
????///?<summary> ????///?TestWX?的摘要說明????///?</summary> ????public?class?TestWX?:?IHttpHandler ????{????????string?appId?=?"";?//換成你的信息 ????????string?appSecret?=?"";?//換成你的信息 ????????public?void?ProcessRequest(HttpContext?context) ????????{ ????????????context.Response.ContentType?=?"text/plain";????????????string?content?=?"";????????????if?(context.Request?!=?null?&&?context.Request.Url?!=?null) ????????????{ ????????????????NameValueCollection?list?=?HttpUtility.ParseQueryString(context.Request.Url.Query);????????????????foreach?(string?key?in?list.AllKeys) ????????????????{ ????????????????????content?+=?string.Format("{0}:{1}?\r\n",?key,?list[key]); ????????????????} ????????????}????????????string?code?=?context.Request.QueryString["code"]????"";????????????if?(!string.IsNullOrEmpty(code)) ????????????{ ????????????????IBasicApi?api?=?new?BasicApi();????????????????try ????????????????{ ????????????????????AppConfig?config?=?new?AppConfig(); ????????????????????appId?=?config.AppConfigGet("AppId");//從配置中獲取微信程序ID ????????????????????appSecret?=?config.AppConfigGet("AppSecret");//從配置中獲取微信程序秘鑰 ????????????????????AccessTokenResult?result?=?api.GetAccessToken(appId,?appSecret,?code);????????????????????if?(result?!=?null) ????????????????????{ ????????????????????????content?+=?string.Format("openid:{0}\r\n",?result.openid);????????????????????????string?token?=?api.GetAccessToken(appId,?appSecret); ????????????????????????IUserApi?userApi?=?new?UserApi(); ????????????????????????UserJson?userDetail?=?userApi.GetUserDetail(token,?result.openid);????????????????????????if?(userDetail?!=?null) ????????????????????????{ ????????????????????????????content?+=?string.Format("nickname:{0}??sex:{1}\r\n",?userDetail.nickname,?userDetail.sex); ????????????????????????????content?+=?string.Format("Location:{0}?{1}?{2}?{3}\r\n",?userDetail.country,?userDetail.province,?userDetail.city,?userDetail.language); ????????????????????????????content?+=?string.Format("HeadUrl:{0}?\r\n",?userDetail.headimgurl); ????????????????????????????content?+=?string.Format("subscribe:{0},{1}\r\n",?(userDetail.subscribe?==?1)???"已訂閱"?:?"未訂閱",?userDetail.subscribe_time.GetDateTime()); ????????????????????????} ????????????????????} ????????????????}????????????????catch?{?} ????????????} ????????????context.Response.Write(content); ????????}
在上面的代碼中,我主要分為幾步,一個是打印當前用戶重定向過來的鏈接的參數(shù)信息,代碼如下。
????????????????NameValueCollection?list?=?HttpUtility.ParseQueryString(context.Request.Url.Query);????????????????foreach?(string?key?in?list.AllKeys) ????????????????{ ????????????????????content?+=?string.Format("{0}:{1}?\r\n",?key,?list[key]); ????????????????}
然后獲取到Code參數(shù)后,通過API接口,獲取AccessTokenResult的數(shù)據(jù),這里面有用戶的OpenID
AccessTokenResult?result?=?api.GetAccessToken(appId,?appSecret,?code);
當正常調(diào)用后,我們把用戶標識的OpenID進一步進行解析,調(diào)用API獲取用戶的詳細信息,具體代碼如下所示。
UserJson?userDetail?=?userApi.GetUserDetail(token,?result.openid);
當我們把用戶的相關信息獲取到了,就可以做各種用戶信息的展示了,如下代碼所示。
????????????????????????if?(userDetail?!=?null) ????????????????????????{ ????????????????????????????content?+=?string.Format("nickname:{0}??sex:{1}\r\n",?userDetail.nickname,?userDetail.sex); ????????????????????????????content?+=?string.Format("Location:{0}?{1}?{2}?{3}\r\n",?userDetail.country,?userDetail.province,?userDetail.city,?userDetail.language); ????????????????????????????content?+=?string.Format("HeadUrl:{0}?\r\n",?userDetail.headimgurl); ????????????????????????????content?+=?string.Format("subscribe:{0},{1}\r\n",?(userDetail.subscribe?==?1)???"已訂閱"?:?"未訂閱",?userDetail.subscribe_time.GetDateTime()); ????????????????????????}
3、重定向鏈接菜單的用途
這種菜單就是需要指定域名,在微信后臺中進行設置,重定向的鏈接必須屬于這個域名之中,否則不會轉(zhuǎn)到你希望的鏈接。
這個方式,讓我們的微信應用程序后臺可以獲得用戶的標識、用戶詳細信息等,我們就可以用來綁定和用戶相關的業(yè)務信息了,如上面提到的圖書館借閱信息,送水客戶的信息,客戶的積分信息,或者可以和后臺賬號進行關聯(lián)實現(xiàn)更加復雜的應用等。用戶的身份信息如此重要,如果結(jié)合到我們的CRM系統(tǒng)、業(yè)務管理系統(tǒng),就可以發(fā)揮用戶信息應用的作用了。
以上就是我對這個類型菜單鏈接的應用了解,具體還需要進一步深化其應用,希望和大家共同探討這方面的應用場景。
更多C# WeChat ?? ? ?????? ?? - WeChat ??? ??? ?? ??相關文章請關注PHP中文網(wǎng)!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)