In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail the ways in which the Wechat menu of Wechat developed by C# is expressed. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
1. Classification of Wechat custom menus
Wechat's requirements for custom menus: at present, the custom menu includes up to three first-level menus, and each first-level menu contains up to five second-level menus. The first-level menu has a maximum of 4 Chinese characters, and the second-level menu has up to 7 Chinese characters. Instead.
According to the classification of the menu, we can display it graphically:
I learned about various Wechat official accounts and found that most accounts use ordinary View type menu links, through which they are linked to their own micro-websites, but some have done well, such as the Provincial Sun Yat-sen Library, which can provide an entrance to bind library users and Wechat OpenID through redirection. after binding, users can view borrowed books. Then the quick renewal function of the book can be realized through the one-click renewal function.
For this type of redirect Url menu event, Wechat describes as follows:
If a user visits a third-party web page of the official account in Wechat (except Web Wechat), the official account developer can obtain the basic information of the current user (including nickname, gender, city and country) through this interface. Using user information, we can achieve the functions of experience optimization, user source statistics, account binding, user identity authentication and so on. Please note that "the interface for obtaining user basic information is that the user's basic information can be obtained according to the user's OpenID when the user and the official account interact with each other, while when the user is authorized to obtain the user's basic information, there is no need for message interaction, just when the user enters the official account's web page, the interface requesting user authorization will pop up. After the user is authorized, the interface will pop up." You can get its basic information (this process does not even require the user to follow the official account. ) "
2. URL of the redirect type menu
As mentioned above, there are two types of redirect menus. In fact, they are only different in the parameter Scope type, and the rest of the menu is the same.
To show, let's assume that when the user clicks the menu, we switch to the http://www.iqidi.com/testwx.ashx page and bring in the parameter information such as the current user's OpenID
The link for scope=snsapi_base mode is as follows:
Http://www.php.cn/scope=snsapi_base&state=123#wechat_redirect https://open.weixin.qq.com/connect/oauth3/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 scope=snsapi_userinfo
The links to the methods are as follows:
Https://open.weixin.qq.com/connect/oauth3/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 can switch smoothly, but the second will pop up a dialog box for the user to confirm before continuing.
In order to demonstrate the difference between the above two kinds of data acquisition, I send the value of the code they passed, and the user parses the user information after exchanging OpenID, and the results of both are the same. The specific test interface is shown below.
The backend code of the TestWX.ashx page is as follows:
/ public class TestWX: IHttpHandler {string appId = ""; / / replace your message string appSecret = ""; / / replace your message 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"); / / obtain Wechat program ID appSecret = config.AppConfigGet ("AppSecret") from configuration; / / obtain Wechat program key AccessTokenResult result = api.GetAccessToken (appId, appSecret, code) from configuration 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)? Subscribed: unsubscribed, userDetail.subscribe_time.GetDateTime ();} catch {}} context.Response.Write (content);}
In the above code, I am mainly divided 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, you can obtain the AccessTokenResult data through the API API, which contains the user's OpenID.
AccessTokenResult result = api.GetAccessToken (appId, appSecret, code)
After the normal call, we further parse the OpenID identified by the user and call API to get the details of the user. The specific code is shown below.
UserJson userDetail = userApi.GetUserDetail (token, result.openid)
When we get the relevant information about the user, we can display all kinds of user information, as shown in the following code.
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)? "subscribed": "unsubscribed", userDetail.subscribe_time.GetDateTime ();} 3. Redirect the purpose of the link menu
This kind of menu needs to specify a domain name and set it in the Wechat background. The redirected link must belong to this domain name, otherwise it will not go to the link you want.
In this way, our Wechat application backend can obtain the user's identity, user details, and so on, so that we can use it to bind user-related business information, such as the above-mentioned library loan information, water delivery customer information, customer points information, or can be associated with the background account to achieve more complex applications. User identity information is so important that if it is combined with our CRM system and business management system, it can play the role of user information application.
On the "C# development of Wechat Wechat menu what is the performance of this article," this article shares here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.