C # Micro-letter development of micro-letter public number label management function _c# Tutorial

Source: Internet
Author: User
Tags openid tag name

Micro-credit public number, modeled on the enterprise number of ideas, increased the function of label management, the attention of fans can be set tag management, to achieve more convenient grouping management functions. Developers can use the user tag management interface, to achieve the public number of tags to create, query, modify, delete and other operations, but also to the user to tag, cancel tags and other operations. This essay mainly introduces how to use C # to encapsulate the new feature of public number, and realize the function of label management.

1. Introduction of label function

1 label function to replace the grouping function, support multidimensional definition of user properties

Operators can login to the public platform background, click on the left menu "user Management" after the management has been concerned about users, click on one of the users to the right of the "label" small angle can be pop-up check box for the user to quickly add a label, and add a label check box has supported the direct new label

In addition, the label function interface has been updated, the developer can call the interface to implement the label and user operations. At the same time, the advanced mass interface and personalized menu interface have been supported to implement the operation according to the label.

2 optimize the user card, support multiple scenes to view the large image and interactive data, enhance the operator's familiarity with the user and management efficiency

This issue of new messages, messages and appreciation of the interactive data, and show the user attention time and support to view the large image of the user, in favor of narrowing the distance between the operator and the user. In addition, support the "appreciation function" and "message management" scene directly manage users, improve management efficiency.

2, the Label Interface encapsulation

The interface of the label is divided into two parts: tag management and user management, a public number that can create up to 100 labels. The label feature currently supports the public number with a maximum of three tabs for the user.

Where tag management includes:

1) Create label 2 get public number created label 3 edit label 4 Delete label 5) Get the list of fans under the label

User management for the label includes:

1 batch for the user to play the label 2) batch for the user to cancel the label 3 to get the user's tag list

The following is an introduction to several interface packages.

First of all, we define the relevant interfaces and implementation relationships in the usual way, as shown in the following figure.

According to the relevant interface description, we can implement the definition of the label interface, the C # code is shown below.

<summary>///Micro-credit Label Management API Interface///developers can use the user tag management interface, to achieve the public number of tags to create, query, modify, delete and other operations, but also to the user to tag, cancel the label and so on.
</summary> public interface Itagapi {///<summary>///create label///A common number, you can create up to 100 labels. </summary>///<param name= "Accesstoken" > Calling interface Voucher </param>///<param name= "Name" >
Label name (within 30 characters) </param>///<returns></returns> tagjson createtag (String accesstoken, string name); <summary>///get public number created labels///</summary>///<param name= "Accesstoken" > Call interface voucher </param>///&
Lt;returns></returns> list<tagcountjson> gettaglist (string accesstoken); <summary>///Edit Tags///</summary>///<param name= "Accesstoken" > Calling interface voucher </param>///<param
Name= "id" > Label id</param>///<param name= "name" > tag name </param>///<returns></returns>
Commonresult Updatetag (string accesstoken, int ID, string name); <summary>///Delete tags///</summary>///<pAram Name= "Accesstoken" > Calling interface Credentials </param>///<param name= "IDs" > tags id</param>///<returns>
</returns> commonresult Deletetag (string accesstoken, int id); <summary>///get the label under the fan list///</summary>///<param name= "Accesstoken" > Calling interface Voucher </param>///< param name= "id" > Label id</param>///<param name= "name" > tag name </param>///<returns></
Returns> gettagresult Gettag (string accesstoken, int id, string next_openid = null);
<summary>///Batch label for users///label feature currently supports the public number for users to play up to three tabs. </summary>///<param name= "Accesstoken" > Calling interface Voucher </param>///<param name= "TagID" > tags id</ param>///<param name= "openid_list" > Fan list </param>///<returns></returns> Commonresult
Batchtagging (string accesstoken, int tagid, list<string> openid_list);
<summary>///batch for users to cancel the label///label feature currently supports the public number for users to play up to three tabs. </summary>///<param name= "Accesstoken" > Calling interface Voucher </param>///<param name= "TagID" > tags id</param>///<param name= "openid_list" > Fan list </param>/// <returns></returns> commonresult batchuntagging (string accesstoken, int tagid, list<string> openid_
list); <summary>///Get the label list of the user///</summary>///<param name= "Accesstoken" > Call interface voucher </param>///& Lt;param name= "OpenID" > User openid</param>///<returns></returns> list<int> getidlist (
String Accesstoken, String OpenID); }

Specifically, let's look at the official definition data for several interfaces.

1 Create the interface of the label

Interface Call Request Description

HTTP request mode: POST (please use HTTPS protocol)

Https://api.weixin.qq.com/cgi-bin/tags/create?access_token=ACCESS_TOKEN

Post data format: JSON

Post Data example:

{"
tag": {
"name": "Guangdong"//label name
}

Returns a description (example of a JSON packet returned in normal time)

{"
tag": {
"id": 134,//label ID
"name": "Guangdong"
}
}

This allows us to define an entity class to host the returned data.

<summary>
///tag Information
///</summary> public
class Tagjson
{
///<summary >
///Tag ID, by the Micro-trust assignment
///</summary> public
int ID {get; set;}
<summary>
///label name, UTF8 encoding
///</summary> public
string name {get; set;}
}

In this way, the complete implementation code to create the label is as follows

<summary>
///Create
a label///a public number, you can create up to 100 labels.
///</summary>
///<param name= "Accesstoken" > Calling interface Voucher </param>
///<param name= "name "> Label name (within 30 characters) </param>
///<returns></returns> public
Tagjson Createtag (string Accesstoken, string name)
{
var url = string. Format ("https://api.weixin.qq.com/cgi-bin/tags/create?access_token={0}", Accesstoken);
var data = new
{
tag = new
{
name = name
}
};
var postdata = data. Tojson ();
var result = Jsonhelper<tagcreateresult>. Convertjson (URL, postdata);
Return result!= null? Result.tag:null;
}

2 Get public number already created label

Interface Call Request Description

HTTP request mode: Get (Please use HTTPS protocol)

Https://api.weixin.qq.com/cgi-bin/tags/get?access_token=ACCESS_TOKEN

Return Data Format: Example of data returned by JSON:

{"
tags": [{
"id": 1,
"name": "Blacklist",
"Count": 0//The number of fans under this label
},{
"id": 2,
"name": "STAR Group",
' count ': 0
},{
' id ': 127,
' name ': ' Guangdong ',
' count ': 5
}
]
}

This allows us to define the return value of list<tagcountjson>, where Tagcountjson is the property of the corresponding class.

<summary>
///label information and statistics
///</summary> public
class Tagcountjson:tagjson
{
///<summary>
///The number of fans under this label
///</summary> public
int count {get; set;}
}

This allows us to return the corresponding data through JSON parsing, which is similar to the above interface and is not to be discussed.

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.