Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example Analysis of the basic concept of Wechat Public platform Development

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is to share with you the content of an example analysis of the basic concepts of Wechat public platform development. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

One: how to start

1: if you do not have a public account, you can first apply for a test account: http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login

2: after logging in, the interface looks like this:

3: next, I need to prepare my own website, and then publish my own URL. So I wrote a WeixinTest.ashx in ASP.NET with the following code:

Public void ProcessRequest (HttpContext context) {string echoStr = HttpContext.Current.Request.QueryString ["echoStr"]; string signature = HttpContext.Current.Request.QueryString ["signature"]; string timestamp = HttpContext.Current.Request.QueryString ["timestamp"]; string nonce = HttpContext.Current.Request.QueryString ["nonce"]; if (! string.IsNullOrEmpty (echoStr)) {HttpContext.Current.Response.Write (echoStr) HttpContext.Current.Response.End ();}}

After publishing the site on our own server, we filled in the address and TOKEN (note that the TOKEN was not verified in my test code). Then click submit in the above figure to get this interface:

The appearance of the above interface means that the submission is successful.

4: what happened after scanning the QR code on Wechat on your mobile phone?

It talks about the performance of the official account of this test on the management side, so what happens to your own Wechat if you follow it? Yes, it appeared in your Subscription account. In other words, at first I thought that this test number was not a service number, so I couldn't enjoy some advanced functions. However, no, since it is a test number, it should make my test happy, so let's take a look at how to generate a menu. However, first of all, let's sort out our thoughts and see what the data flow of the official Wechat account is all about. If you don't figure this out, you'll be as confused as I am for a day.

Two: about data flow

1: register a test account

Signing up for a test account is done on Wechat's website. Typing url and token indicates that we have created this official account.

2: how others who follow your official account interact with you

When someone follows this official account, the first thing he visits is the url we used at the time of creation. Yes, the url is very important. When registering, Wechat's website will visit it to see if it is legal. After successful registration, the url becomes the only address where others use Wechat to interact with you on their mobile phone.

3: how do you push content to others

This is divided into two parts.

The first case: by configuring information on Wechat sites or calling Wechat interface, we bind our official account to some information, such as custom menus. In this way, when others follow the official account, they can see information such as custom menus.

The second situation: the first situation we understand as the configuration stage, then the second situation is the real development stage, in which we receive the user's message (text,click,view, etc.), and then the user's message is pushed to the user text,image, the website page (it can be a website with your url, or it can be a third-party website).

You can push this information to others: customize the menu

Three: example-how to generate a custom menu

This is the first situation mentioned above. Since it doesn't really have much to do with real Wechat development, or you can write a piece of code independently to complete the call interface to configure information, well, I'll use the program provided by Wechat itself:

Remember, the input must be in JSON format. To meet the format requirements, please refer to Wechat's developer profile.

Then we cancel the previous follow, re-follow the official account, we can see the newly created menu (note, there is a delay, if you do not want to wait, you can change to another WeChat account and come out). Since my phone can't take pictures of myself, there are no effect pictures here.

3.1 about access_token

Note that here, we also need to enter an access_token, which we can also use this interface debugging tool to obtain:

It is worth noting that this value has an expiration period.

Four: an example-a real url processor

Public void ProcessRequest (HttpContext param_context) {if (HttpContext.Current.Request.HttpMethod.ToUpper () = = "POST") {using (Stream stream = HttpContext.Current.Request.InputStream) {Byte [] postBytes = new Byte [stream.Length]; stream.Read (postBytes, 0, (Int32) stream.Length) Handle (Encoding.UTF8.GetString (postBytes));}} else {Auth ();}}

Why make a judgment that it is POST? Because when applying for the official account, Wechat website used GET to verify this url, so we can use the Auth method, while the interaction is carried out with POST.

Thank you for reading! This is the end of the article on "sample Analysis of the basic Concepts of Wechat Public platform Development". 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, you can share it 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.

Share To

Development