Asp.net development WeChat public platform (8) WeChat 9 high-level interface, custom menu

Source: Internet
Author: User
Tags openid
In the first seven articles, we have completed the most basic message receiving and reply operations, and completed the entry and split processing of the advanced interfaces with an empty method. This article describes the nine advanced interfaces, the user-defined menu is highlighted. In the first seven articles, we have completed the most basic message receiving and reply operations, and completed the entry and split processing of the advanced interfaces with an empty method. This article describes the nine advanced interfaces, the user-defined menu is highlighted.

The nine major interfaces are:

1. speech recognition interface

2. customer service interface

3. OAuth2.0 webpage authorization interface

4. generate a two-dimensional code interface with parameters

5. interface for obtaining users' geographic locations

6. interface for obtaining basic user information

7. interfaces for obtaining the list of consumers

8. user group interface

9. interfaces for uploading and downloading multimedia files

Details:

1. speech recognition

Function description: through the speech recognition interface, the speech sent by the user will also provide the text content recognized by the speech.

Practical significance: Third parties can call self-developed speech recognition technology. This means that the speech recognition technology is open to a third party, and the speech recognition interface is called directly to interact with the speech recognition results or automatically reply according to the recognition content.

2. customer service interface

Function description: through the customer service interface, the public number can reply to the user within 12 hours after the user has sent the message.

Practical significance: In the past, public accounts and subscribers had to respond passively. for example, if a user triggers a request, such as sending a keyword to a public account, the latter can talk to the user. Now, if a user has talked to a public account once, the public account can send messages to the user continuously within 12 hours. This improves the ability of the public account to send messages.

3. OAuth 2.0 webpage authorization

Function description: Through the webpage authorization interface, the public account can request user authorization.

Practical: this is like the account authorization function of Weibo and QQ. This means that the account is officially an account system.

4. generate a QR code with parameters

Function description: Through this interface, the public number can obtain a series of QR codes with different parameters. after the user scans the public number, the public number can analyze the effect of each QR code based on parameters.

Practical: for example, a billboard with a QR code on a website or offline has the same effect: Getting users interested. You can now analyze the sources of subscribers. Developers can set special information in the link for more data analysis. This function can also be used for account binding,

5. obtain the geographical location of a user

Function description: This interface allows a public account to obtain the geographical location of a user when accessing a public account session.

Practical: you can obtain the geographical location of a user in two cases: "session time" with a public account, and "every five seconds" on the session interface ". With the user's consent, this can be used for navigation or geo-fencing services.

6. get basic user information

Function description: This interface allows the public account to obtain basic user information, including profile picture, name, gender, and region, based on the encrypted user OpenID.

Practical: In the past, this was a very high permission. After obtaining basic user information, you can use the CRM management background to facilitate merchant management of users.

7. obtain the list of referers

Function description: This interface allows you to obtain the OpenID of all administrators.

Practical: I used to know how many people followed you and who followed you. Now you can know who is following you.

8. user group interface

Function description: Through the grouping interface, the public number can move groups for users in the background, or create or modify groups.

Practical significance: users can be grouped. for example, lesixiang organizes a "listener Exchange Meeting", where 1000 people are present and can be grouped into a group, the photos of subsequent activities are only sent to these 1000 people. This is a VIP member management platform for sellers.

9. upload and download multimedia files

Function description: This interface allows you to upload and download multimedia files on the server as needed.

Practical significance: Images and videos can be delivered. For example, a funny video that is uploaded to the background of a public account can be pushed to the audience, which is equivalent to a video website service.

The above is the introduction of the nine advanced interfaces. In fact, there should be 10 now, and there is also a payment function.

The custom menu is rewritten below.

The custom menu only needs to be created once and will exist later. each change takes several minutes to see it. create:

After I add all the items here, click "Create". the code is as follows:

Public void SetMenu () {dbHome = Factory. FContext. WeiXinDbContext (); var listP = DAL. ListWhere
 
  
(DbHome, a => a. ParentId = 0 & a. State = 1, a => a. ID, 3); List
  
   
> List = new List
   
    
> (); Foreach (var row in listP) {var listC = DAL. ListWhere
    
     
(DbHome, a => a. ParentId = row. ID & a. State = 1, a => a. ID, 5); List
     
      
> List2 = new List
      
        > (); Dictionary
       
         Dic2m = new Dictionary
        
          (); Dictionary
         
           Dic1 = new Dictionary
          
            (); If (listC. Count> 0) {foreach (var row2 in listC) {// level 2 menu content Dictionary
           
             Dic2c = new Dictionary
            
              (); Dic2c. add ("type", row2.Type. toString (). replace ("1", "click "). replace ("2", "view"); dic2c. add ("name", row2.Name); if (row2.Type = 1) dic2c. add ("key", row2.ID); if (row2.Type = 2) dic2c. add ("url", row2.LinkUrl); list2.Add (dic2c);} // -- // 2-level menu assembly dic2m. add ("name", row. name); dic2m. add ("sub_button", JsonHelper. listDicToJsonVals (list2); // ------ list. add (dic2m);} else {// level 1 menu dic1.Add ("type", row. type. toString (). replace ("1", "click "). replace ("2", "view"); dic1.Add ("name", row. name); if (row. type = 1) dic1.Add ("key", row. ID); if (row. type = 2) dic1.Add ("url", row. linkUrl); // ---------- list. add (dic1);} // Set level 1 and Level 2 to list // -----------} string m = JsonHelper. listDicToJsonVals (list); // Convert the list to a json value and assign it to the button. // assign the value to the button Dictionary.
             
               DicAll = new Dictionary
              
                (); DicAll. add ("button", m); // --------- string jsonResult = JsonHelper. getJsonStr (dicAll); // converting dic to json // The converted [{}, {}] will also be surrounded by "". remove "" jsonResult = jsonResult. replace ("\"[","["). replace ("] \" ","] "); string html = HttpHelper. httpPost ("https" + ": // api.weixin.qq.com/cgi-bin/menu/create? Access_token = "+ Common. config. systemConfig. access_token + "", jsonResult, Encoding. UTF8); dbHome. dispose (); Response. write (JsonHelper. jsonToVal (html, "errmsg"); Response. end ();}
              
             
            
           
          
         
        
       
      
     
    
   
  
 

Finally, the json data in the following format is post:

{"Button": [{"type": "click", "name": "Today's songs", "key": "V1001_TODAY_MUSIC" },{ "type ": "click", "name": "", "key": "V1001_TODAY_SINGER" },{ "name": "menu", "sub_button ": [{"type": "view", "name": "Search", "url": "http://www.soso.com/" },{ "type": "view ", "name": "video", "url": "http://v.qq.com/"}, {"type": "click", "name": "Like Us ", "key": "V1001_GOOD"}]}

In this way, you can see the result in:

{

}

Now we can complete the following:

// Click public void DoMenuClick (DbContext dbHome, RMenuClick mMenuClk) in the custom menu {SText mStxtA = new SText (); mStxtA. toUserName = mMenuClk. fromUserName; mStxtA. fromUserName = mMenuClk. toUserName; mStxtA. createTime = mMenuClk. createTime; int id = 0; mStxtA. content = "Welcome, enter any keyword to start experiencing"; if (int. tryParse (mMenuClk. eventKey, out id) {var me = DALWei. infoEntities
 
  
(DbHome, a => a. ID = id); if (me! = Null) mStxtA. content = "Welcome to [" + me. name + "], Introduction, description, link, and so on. It can also be a text message";} Often. responseToEnd (DALWei. sendText (mStxtA ));}
 

This is the menu processing of the Click type. it should be noted that the menu clicking of the view type will jump directly to the link you wrote, if the level 1 menu is set to the view type, the click event is still executed without redirection;

Effect:

I directly return a piece of text here. in actual application, any message can be returned.

For more information about the nine advanced interfaces of the public platform (8) developed by asp.net, refer to the PHP Chinese website for articles on custom menus!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.