


Introduction to various expression methods for developing WeChat portal and applying WeChat menu with C#
Mar 02, 2017 am 10:12 AM1. Classification of WeChat custom menus
WeChat’s requirements for custom menus: Currently, custom menus include up to 3 first-level menus, and each first-level menu contains up to 5 secondary menus. The first-level menu can contain up to 4 Chinese characters, and the second-level menu can contain up to 7 Chinese characters. The extra parts will be replaced by "...".
According to the classification of the menu, we can classify and display it through graphics:
I learned about various WeChat public accounts and found that Most accounts use ordinary View-type menu links to link to their own microsites, but there are some that do well, such as the Zhongshan Provincial Library, which can provide a link through redirection. Bind the entrance of library users and WeChat OpenID. After binding, users can view the borrowed books, and then realize the quick renewal function of books through the one-click renewal function.
For this type of redirection Url menu event, WeChat’s instructions are as follows:
If the user accesses the third-party webpage of the official account in WeChat (except Web WeChat), the official account developer Basic information of the current user (including nickname, gender, city, country) can be obtained through this interface. Using user information, you can realize functions such as experience optimization, user source statistics, account binding, and user identity authentication. Please note that the "obtain user basic information interface" can only obtain the user's basic information based on the user's OpenID when the user interacts with the public account through messages. However, the user's basic information can be obtained through web page authorization without message interaction. The user only needs to enter Go to the official account's webpage, and an interface requesting user authorization will pop up. After the user authorizes, you can obtain their basic information (this process does not even require the user to have followed the official account.)"
2. The URL of the redirection type menu
As mentioned above, there are two types of redirection type menus. In fact, they are only parameter Scope types. Different, other parts are still the same.
For demonstration purposes, we assume that when the user clicks the menu, we switch to the page http://www.iqidi.com/testwx.ashx and bring over the current user’s OpenID and other parameter information
The link for scope=snsapi_base method is as follows:
http://ipnx.cn/scope=snsapi_base&state=123#wechat_redirect 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 And for the scope=snsapi_userinfo
method The link is as follows:
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
However, the experience they give to the mobile client is different. The first one can switch smoothly, but the second one will pop up a dialog box for the user to confirm before continuing.
In order to demonstrate the difference between the above two methods of obtaining data, I took the value of the code they passed, and the user parsed the user information after exchanging it for OpenID. The results of both of them It's all the same. The specific test interface is as follows.
The page background code of TestWX.ashx is as follows:
/// <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); }
In the above code, I mainly divide it into several steps. One is to print the parameter information of the link redirected by the current user. The code is as follows.
NameValueCollection list = HttpUtility.ParseQueryString(context.Request.Url.Query); foreach (string key in list.AllKeys) { content += string.Format("{0}:{1} \r\n", key, list[key]); }
Then after obtaining the Code parameter, obtain the AccessTokenResult data through the API interface, which contains the user's OpenID
AccessTokenResult result = api.GetAccessToken(appId, appSecret, code);
After the normal call, we further parse the OpenID of the user identification and call the API to obtain the user's detailed information. The specific code is as follows .
UserJson userDetail = userApi.GetUserDetail(token, result.openid);
當(dāng)我們把用戶的相關(guān)信息獲取到了,就可以做各種用戶信息的展示了,如下代碼所示。
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、重定向鏈接菜單的用途
這種菜單就是需要指定域名,在微信后臺(tái)中進(jìn)行設(shè)置,重定向的鏈接必須屬于這個(gè)域名之中,否則不會(huì)轉(zhuǎn)到你希望的鏈接。
這個(gè)方式,讓我們的微信應(yīng)用程序后臺(tái)可以獲得用戶的標(biāo)識(shí)、用戶詳細(xì)信息等,我們就可以用來綁定和用戶相關(guān)的業(yè)務(wù)信息了,如上面提到的圖書館借閱信息,送水客戶的信息,客戶的積分信息,或者可以和后臺(tái)賬號(hào)進(jìn)行關(guān)聯(lián)實(shí)現(xiàn)更加復(fù)雜的應(yīng)用等。用戶的身份信息如此重要,如果結(jié)合到我們的CRM系統(tǒng)、業(yè)務(wù)管理系統(tǒng),就可以發(fā)揮用戶信息應(yīng)用的作用了。
以上就是我對(duì)這個(gè)類型菜單鏈接的應(yīng)用了解,具體還需要進(jìn)一步深化其應(yīng)用,希望和大家共同探討這方面的應(yīng)用場(chǎng)景。
?更多Introduction to various expression methods for developing WeChat portal and applying WeChat menu with C#相關(guān)文章請(qǐng)關(guān)注PHP中文網(wǎng)!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)